It crossed my mind, but I dismissed it as map lookups are expensive. Thinking about it, how many times do I really have to do a lookup? Probably affordable.
[editline]9th June 2013[/editline]
And yeah I understand your example, now. :v:
Expensive compared to what?
You mean because you need to store the name twice? That is something that bugged me about any std- or boost container, that there's no container where you can specify that the key can be derived from the value.
You could use const char* as key, this way the overhead per entry would be lower than storing the std::string.
I have very deep multidimensional arrays in javascript, each one being a different "level". How would I keep track on which level I am on compared to the first array? Along with this what would be the best way to go back up the array? Currently I have the arrays (well, an object holding the array) have a parent variable that is set to the array (again, an object holding the array) it is in.
I think I remember there being a list of OpenGL resources somewhere here on Facepunch. Anyone know about it? Because I haven't used OpenGL in a year now. I still remember most things, but I have forgotten small details like argument order and what things need enabling.
[QUOTE=hogofwar;40959955]I have very deep multidimensional arrays in javascript, each one being a different "level". How would I keep track on which level I am on compared to the first array? Along with this what would be the best way to go back up the array? Currently I have the arrays (well, an object holding the array) have a parent variable that is set to the array (again, an object holding the array) it is in.[/QUOTE]
I imagine you would have to store the depth along side the sub-arrays, like you did with storing a reference to the parent-array.
[editline]9th June 2013[/editline]
[QUOTE=ArgvCompany;40960015]I think I remember there being a list of OpenGL resources somewhere here on Facepunch. Anyone know about it? Because I haven't used OpenGL in a year now. I still remember most things, but I have forgotten small details like argument order and what things need enabling.[/QUOTE]
You looking for something like [url=https://www.khronos.org/files/opengl43-quick-reference-card.pdf]this[PDF][/url]?
[QUOTE=ZeekyHBomb;40960334]I imagine you would have to store the depth along side the sub-arrays, like you did with storing a reference to the parent-array.
[editline]9th June 2013[/editline]
You looking for something like [url=https://www.khronos.org/files/opengl43-quick-reference-card.pdf]this[PDF][/url]?[/QUOTE]
That's a very good reference, thank you!
But I think I also need something like tutorials. Not because I don't know anything about it, but because it's easy to get a quick overview on what I need to enable, and how the general process looks like. I thought I got it memorized, but it doesn't seem to work. So tutorials are mainly what I look for.
[editline]9th June 2013[/editline]
[QUOTE=ZeekyHBomb;40945281]Regarding goto:
I've heard somewhere that it makes a compilers job at control flow analysis harder and thus might hinder optimization.
Does anyone know something more specific? I'll try to look something up later if noone does.[/QUOTE]
That's just in those cases where you could as easily (or easier) have used control statements like if. In general, using low-level constructs which correspond "1:1" to equivalent higher-level constructs makes it more likely that the compiler finds an optimization that you have missed (because you're not as specific about how it does things, it can do it the most efficient way, while when using low-level constructs, it obviously has to do it that way since you explicitly stated it).
Well, there's a [url=https://www.opengl.org/wiki/Getting_Started#Tutorials_and_How_To_Guides]list of tutorials[/url] on the OpenGL Wiki, the Wiki of course also provides a lot of information (although not as sequentially structured).
Maybe this will help you though, until someone who knows the specific list you're looking for posts a link.
Does anybody know why when I try to render this texture:
[IMG]http://i.imgur.com/YlzTzQf.png[/IMG]
It just turns the quad yellow?
I know that the texture is being loaded correctly and being put in the texture buffer correctly. Here is my fragment shader:
[CODE]
#version 330
in vec4 outColor;
in vec2 outUV;
uniform vec4 uniColor;
uniform sampler2D tex;
out vec4 outputColor;
void main()
{
outputColor = texture(tex, outUV);
}
[/CODE]
I am calling
[CODE]glBindTexture(GL_TEXTURE_2D, tex.id);[/CODE]
before I do my rendering. This was working fine the other day, I must have changed something and messed it up. Anybody have any ideas?
The UVs are most likely wrong.
[QUOTE=Tamschi;40967539]The UVs are most likely wrong.[/QUOTE]
I've triple checked them. But then again, I have been told different things about uvs from multiple sources, I am confused, Is (0,0) for UVs in the top left or the bottom left?
[QUOTE=Duskling;40969571]I've triple checked them. But then again, I have been told different things about uvs from multiple sources, I am confused, Is (0,0) for UVs in the top left or the bottom left?[/QUOTE]Topleft. (1,1) is bottomright.
[QUOTE=Duskling;40969571]I've triple checked them. But then again, I have been told different things about uvs from multiple sources, I am confused, Is (0,0) for UVs in the top left or the bottom left?[/QUOTE]
Just output the UVs as the color and you should get a nice 4 color gradient where every corner has it's own color if they're correct.
ZeekyHBomb, I figured I'd try your implementation of the subscript accessor, but I've bumped into the following problem:
binary '[' : no global operator found which takes type 'const std::string' (or there is no acceptable conversion)
However, I do have a overloaded subscript accessor in my Node class with the exact same parameters as the NodeProxy (or AstronomicalObjectProxy) class.
[QUOTE=Duskling;40950223]I am pretty confused with this opengl rendering I am doing. For some reason the thing crashes if I put more than 4 verts in a mesh. It works fine with 4 or less verts. Here is where I create the vertices:
[CODE]
Vertex v1 = new Vertex(-0.1f,0.1f, 0.1f); v1.setRGBA(1.0f, 1.0f, 1.0f, 1.0f); v1.setUV(0.0f, 0.0f); // Top Left (0)
Vertex v2 = new Vertex(0.1f,0.1f, 0.1f); v2.setRGBA(1.0f, 1.0f, 1.0f, 1.0f); v2.setUV(1.0f, 0.0f); // Top Right (1)
Vertex v3 = new Vertex(-0.1f,-0.1f, 0.1f); v3.setRGBA(1.0f, 1.0f, 1.0f, 1.0f); v3.setUV(0.0f, 1.0f); // Bottom Left (2)
Vertex v4 = new Vertex(0.1f,-0.1f, 0.1f); v4.setRGBA(1.0f, 1.0f, 1.0f, 1.0f); v4.setUV(1.0f, 1.0f); // Bottom Right (3)
Vertex v5 = new Vertex(-0.1f, 0.3f, -0.1f); v5.setRGBA(1.0f, 1.0f, 1.0f, 1.0f); v5.setUV(0.0f, 0.0f); // Top Left (4)
Vertex v6 = new Vertex(0.1f, 0.1f, -0.1f); v6.setRGBA(1.0f, 1.0f, 1.0f, 1.0f); v6.setUV(1.0f, 0.0f); // Top Right (5)
Vertex[] newVertices = new Vertex[]{v1, v2, v3, v4, v5, v6};
byte[] newIndices = new byte[]{
0, 1, 2, 3, 4, 5
};
mesh = new Mesh();
mesh.setVertices(newVertices, newIndices);
[/CODE]
In the mesh, the verts and indices are placed in a buffer and then put in a vbo. I have checked and I am 99% sure that this is not where the problem is, all the memory is being allocated correctly and it's all being placed there.
[CODE]
public void setVertices(Vertex[] newVertices, byte[] newIndices){
vertices = newVertices;
indices = newIndices;
vertexBuffer = BufferUtils.createFloatBuffer(40 * vertices.length); // create a vertex buffer
indexBuffer = BufferUtils.createByteBuffer(indices.length); // create the index buffer
// Add the vertices to the vertex buffer
for(int i = 0; i < vertices.length; i++){
vertexBuffer.put(vertices[i].getElements());
}
vertexBuffer.flip();
// Add the indices to the index buffer
indexBuffer.put(indices);
indexBuffer.flip();
// Bind the vbo and fill it with the data from the vertex buffer
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, vertexBuffer, GL_DYNAMIC_DRAW);
// Bind the ebo and fill it with the data from the index buffer
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBuffer, GL_DYNAMIC_DRAW);
}
[/CODE]
And this is where I render. The game crashes right when the glDrawElements is called.
[CODE]
public void render(){
glUseProgram(shaderProgramID); // Use this shader
glBindTexture(GL_TEXTURE_2D, tex.id);
glBindVertexArray(vao); // Bind the vertex attribute array. This is not necessary, but improves performance.
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); // Bind the element buffer before glDrawElements.
// Reset the model matrix
glIdentityModelMatrix();
// Manipulate the model matrix
glSetScale(scale);
glSetPosition(position);
glSetRotation(rotation);
glSetColor(color);
// Update the matrix
glUpdateModelMatrix();
// Position
glEnableVertexAttribArray(0); // enable the position attribute
glVertexAttribPointer(0, vertices.length, GL_FLOAT, false, 40, 0); // tell opengl how to read the position attribute.
// attribute, amount of elements, type, normalized?, stride, offset ( pointer to first component )
// UVs
glEnableVertexAttribArray(2); // enable the uv attribute
glVertexAttribPointer(2, vertices.length, GL_FLOAT, false, 40, 32); // tell opengl how to read the position attribute.
// Render using the indices
glDrawElements(GL_TRIANGLES, indices.length, GL_UNSIGNED_BYTE, 0);
// cleanup
glUseProgram(0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(2);
glBindTexture(GL_TEXTURE_2D, 0);
}
[/CODE]
The game crashes and gives me one of these:
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000005564c360, pid=6448, tid=1852
What do :L[/QUOTE]
You should read up on VAO's because you're not using them right.
Edit:
I'm on my phone sorry about that quote.
[QUOTE=Asgard;40970394]ZeekyHBomb, I figured I'd try your implementation of the subscript accessor, but I've bumped into the following problem:
binary '[' : no global operator found which takes type 'const std::string' (or there is no acceptable conversion)
However, I do have a overloaded subscript accessor in my Node class with the exact same parameters as the NodeProxy (or AstronomicalObjectProxy) class.[/QUOTE]
Member[name] should be (*Member)[name] :v:
[QUOTE=ZeekyHBomb;40970527]Member[name] should be (*Member)[name] :v:[/QUOTE]
Haha, I tried *Member[name] and Member[*name] and every other possible thing you could think of, except that. :v:
[editline]10th June 2013[/editline]
It makes so much sense now that I think of it.
[QUOTE=Asgard;40970558]Haha, I tried *Member[name] and Member[*name] and every other possible thing you could think of, except that. :v:
[editline]10th June 2013[/editline]
It makes so much sense now that I think of it.[/QUOTE]
*Member[name] would be fine if it weren't for the fact that the [] operator has higher precedence than the * operator. In other words, what that does is dereference Member[name], rather than dereferencing Member and then accessing [name] on it.
On a unrelated note, should you always be using smart pointers as class members? I see no real use for them as function parameters, but I see how letting them get auto-destructed is useful for objects. Or should you also use them as function parameters? And as, for example, std::map parameters?
[editline]10th June 2013[/editline]
Oh, yeah. NodeProxy relies on a overloaded subscript operator in the Node class, and vice versa. It won't compile because it complains that there is no operator defined like that. This is because I predeclare class Node in the nodeproxy header file. How can I fix this?
[editline]10th June 2013[/editline]
I should probably just move it over to the source file and stop being lazy :v:
Sure, it can make sense in a lot of cases, sometimes also as function parameters.
Also look into std::reference_wrapper and boost::optional for different usecases where you can also avoid raw pointers.
Here you could use boost::optional<Node&> for example.
Trying to create a mesh from a flock, this is what I currently have;
[img]http://puu.sh/3cEpm/1c60d710f0.png[/img]
Ugly I know. I've tried triangulation but I'm obviously doing it wrong, could anyone point me in the right direction?
I'd like to triangulate a mesh from points that are within a certain distance from one another.
I'm trying to write an application on MIPS Asm, but whenever my start location is on ASM, I'm getting garbage on my labels, like random addresses or something, causing even a simple hello world to fail, ie:
[code].text
.global main
mainzor:
li $a0, 1
la $a1, greetings
li $a2, 14
li $v0, 4004
syscall
nop
jr $ra
nop
.data
greetings: .ascii "Hello World!\n"[/code]
Will write a bunch of garbage into stdout, instead of writing "Hello World!", however, renaming main to whatever, and calling it from C, ie:
[code]
extern void mainzor();
int main(int argc, char* argv[]) {
mainzor();
return 0;
}
[/code]
will write the correct text to stdout properly, I'm compiling them using "mipsel-linux-gcc", with these cflags: "-O0 -ggdb -march=mips32r2 -fno-PIC -Wall"
tl;dr: Is there something I need to do, or some library that needs to be linked in order to achieve this? thanks.
It's been a while since I worked on anything like it, but try setting the entrypoint explicitly in the commandline arguments, or perhaps renaming the global to "_main" could work.
I believe C prepends an underscore to symbols, which would explain why it can pick it up in C, but not in Assembly.
I don't do much assembly, but I think .ascii does not null-terminate (while .asciz does).
Is there a Hello World! in front of the garbage output?
You might just get lucky when you call it from C.
[editline]10th June 2013[/editline]
[url=http://stackoverflow.com/a/10286565/1874964]This code[/url] also uses the .ent and .end directives.
[QUOTE=ZeekyHBomb;40974637]I don't do much assembly, but I think .ascii does not null-terminate (while .asciz does).
Is there a Hello World! in front of the garbage output?
You might just get lucky when you call it from C.
[editline]10th June 2013[/editline]
[url=http://stackoverflow.com/a/10286565/1874964]This code[/url] also uses the .ent and .end directives.[/QUOTE]
No, you don't need asciz for doing write syscalls, since you're only writing the number of chars you want, and not writing until you reach a "0".
And yeah, I get just garbage, no actual hello world.
And these directives didn't solve the issue.
[QUOTE=Dr Magnusson;40974326]It's been a while since I worked on anything like it, but try setting the entrypoint explicitly in the commandline arguments, or perhaps renaming the global to "_main" could work.
I believe C prepends an underscore to symbols, which would explain why it can pick it up in C, but not in Assembly.[/QUOTE]
crt1.o seems to be asking for main.
[QUOTE=JohnnyOnFlame;40975117]No, you don't need asciz for doing write syscalls, since you're only writing the number of chars you want, and not writing until you reach a "0".
And yeah, I get just garbage, no actual hello world.
And these directives didn't solve the issue.
crt1.o seems to be asking for main.[/QUOTE]
Then your count is off, it should be 13.
That probably won't help with the fundamental issue though.
[editline]10th June 2013[/editline]
You could do a gcc -S to see what assembly gcc compiles the C-code to.
[QUOTE=ZeekyHBomb;40975317]Then your count is off, it should be 13.
That probably won't help with the fundamental issue though.
[editline]10th June 2013[/editline]
You could do a gcc -S to see what assembly gcc compiles the C-code to.[/QUOTE]
Good idea! Thanks, I'll try to make some sense out of it. Meanwhile, I'll overengineer it a little:
Overengineering small issues part one, tryit.mk:
[code]CC=mipsel-linux-gcc
C_SRC = tryit.c
S_SRC = $(C_SRC:.c=.S)
AS_OBJ = $(S_SRC:.S=.o)
TARGET = tryit
CFLAGS = -O0 -ggdb -march=mips32r2
all: $(AS_OBJ)
$(CC) -o $(TARGET) $(AS_OBJ)
$(AS_OBJ): $(S_SRC)
$(CC) -c $<
$(S_SRC): $(C_SRC)
$(CC) -S $< -o $@[/code]
part 2, tryit.c:
[code]char *greetings = "Hello, World!\n";
int main(int argc, char *argv[])
{
asm("\
li $a0, 1 # stdout\n\
la $a1, %0 # place where greetings is\n\
li $a2, 14 # number of crap to print\n\
li $v0, 4004 # syscall id\n\
nop\n\
\n\
syscall\n\
nop" : "=m"(*greetings));
return 0;
}[/code]
[QUOTE=Robbis_1;40970093]Just output the UVs as the color and you should get a nice 4 color gradient where every corner has it's own color if they're correct.[/QUOTE]
Great suggestion.
Changed the color output in my frag shader to
[CODE]outputColor = vec4(outUV, 0.0f, 1.0f);[/CODE]
And it doesn't display anything because for some reason outUV is 0,0. So I went and checked it out, and I checked after the vertices were put in the buffer, and they do indeed have UV elements. So if it's not getting passed to the shader I assume it has something to do with the uv coordinate vertex attribute. The position, color, and uv coordinate data all adds up to 36 bytes ( 4 bytes per float, 9 floats ). The color offset is correct, ( 3 * 4 = 12 ), and the uv coordinate offset is correct ( 4 * 4 + 12 = 28 ). What's going on :L
[CODE]
glVertexAttribPointer(0, 3, GL_FLOAT, false, 36, 0); // position
glVertexAttribPointer(1, 4, GL_FLOAT, false, 36, 12); // color
glVertexAttribPointer(2, 2, GL_FLOAT, false, 36, 28); // uv coordinates
[/CODE]
If I know the semi-major axis, eccentricity, inclination, longitude of ascending node, argument of periapsis and the current true anomaly of a body orbiting another body on an inclined elliptical Kepler orbit
how the fuck do I calculate its (X, Y, Z) position relative to the body it's orbiting?
[editline]11th June 2013[/editline]
To clarify, the body being orbited could be considered an "immobile" star (at the origin of the coordinate system) and the body orbiting it a planet. I want to know where the planet is in space if I know the parameters of its orbit and its current position along it.
JavaServer faces... :suicide: Can't find where I'm doing wrong at.
[quote]/index.xhtml @25,76 value="#{guestbookEntry.name}": Target Unreachable, identifier 'guestbookEntry' resolved to null[/quote]
[i]index.xhtml[/i]
[code]<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Guestbook Registration Assignment</title>
</h:head>
<h:body>
<h:form>
<h1>Guestbook Entry</h1>
<p>Please fill in all fields and click Register.</p>
<h:panelGrid>
<!-- Name -->
<h:outputLabel value="Name: "/>
<h:inputText id="input_name" required="true"
requiredMessage="Please enter your name."
value="#{guestbookEntry.name}"
validatorMessage="First name must be fewer than THIRTY characters">
<f:validateLength maximum="30" />
</h:inputText>
<h:message for="input_name" styleClass="error"/>
<!-- eMail address -->
<h:outputLabel value="eMail: "/>
<h:inputText id="input_email" required="true"
requiredMessage="Please enter your email address."
value="#{guestbookEntry.email}">
<f:validateRegex pattern=
"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
</h:inputText>
<h:message for="input_email" styleClass="error"/>
<!-- Message -->
<h:outputLabel value="Message: "/>
<h:inputTextarea id="input_msg" required="true"
requiredMessage="Please enter a message."
value="#{guestbookEntry.message}"/>
<h:message for="input_msg" styleClass="error"/>
<h:commandButton value="Submit" action="#{guestbookBean.register(input_name, input_email, input_msg)}"/>
<h1>Registry</h1>
<h:dataTable>
<ui:repeat value="#{guestbookBean.entries}" var="entry">
<h:column>
<f:facet name="header">Name</f:facet>
#{entry.name}}
</h:column>
<h:column>
<f:facet name="header">eMail</f:facet>
#{entry.email}}
</h:column>
<h:column>
<f:facet name="header">Message</f:facet>
#{entry.message}}
</h:column>
</ui:repeat>
</h:dataTable>
</h:panelGrid>
</h:form>
</h:body>
</html>
[/code]
[i]GuestbookBean.java[/i]
[code]import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ApplicationScoped;
@ManagedBean(name="guestbookBean")
@ApplicationScoped
public class GuestbookBean implements Serializable {
public List<GuestbookEntry> guestbook;
// public GuestbookBean() {
// }
public void register(String n, String e, String m) {
guestbook.add(0, new GuestbookEntry(n, e, m));
}
public GuestbookEntry[] getEntries() {
return guestbook.toArray(new GuestbookEntry[guestbook.size()]);
}
public static class GuestbookEntry {
private String name;
private String email;
private String message;
public GuestbookEntry(String n, String e, String m) {
name = n;
email = e;
message = m;
} // End GUESTBOOKENTRY CONSTRUCTOR
public void setName(String n) {
name = n;
}
public void setEmail(String e) {
email = e;
}
public void setMessage(String m) {
message = m;
}
public String getName() {
return name;
}
public String getEmail() {
return email;
}
public String getMessage() {
return message;
}
} // End GUESTBOOKENTRY CLASS
}
[/code]
[QUOTE=Stonecycle;40988912]JavaServer faces... :suicide: Can't find where I'm doing wrong at.
-snip-
[/QUOTE]
Here:
[CODE]
<h:dataTable>
<ui:repeat value="#{guestbookBean.entries}" var="entry">
<h:column>
<f:facet name="header">Name</f:facet>
#{entry.name}}
</h:column>
<h:column>
<f:facet name="header">eMail</f:facet>
#{entry.email}}
</h:column>
<h:column>
<f:facet name="header">Message</f:facet>
#{entry.message}}
</h:column>
</ui:repeat>
</h:dataTable>
[/CODE]
You are trying to access the entries name, email, and message variables which are private. I believe you would have to do getName(), getEmail(), and getMessage().
Sorry, you need to Log In to post a reply to this thread.