PDA

View Full Version : Hardcode a vertex



Elencu007
07-27-2013, 09:20 AM
Hello, people. I have a function that outputs the x, y and z coordinates of a vertex after selecting it from 3D sphere mesh. Each vertex in my project also has an id. Now, I need a certain vertex, for example the vertex with the id=40 to move in a different direction, so I have to give it new x, y and z coordinates. Here is the function:


void mouse(int button, int state, int x, int y)
{
GLint viewport[4];
GLdouble modelview[16],
projection[16];
GLfloat wx=x, wy, wz;
if(state!=GLUT_DOWN)
return;
if(button==GLUT_RIGHT_BUTTON)
exit(0);
glGetIntegerv(GL_VIEWPORT,viewport);
y=viewport[3]-y;
wy=y;
glGetDoublev(GL_MODELVIEW_MATRIX,modelview);
glGetDoublev(GL_PROJECTION_MATRIX,projection);
glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&wz);
gluUnProject(wx,wy,wz,modelview,projection,viewpor t,&ox,&oy,&oz);
glutPostRedisplay();
printf("made pick on %f %f %f \n", ox, oy, oz);
pick(x,y);
Vertex.x=ox;
Vertex.y=oy;
Vertex.z=oz;
processhits (nhits, buffer);
if (vertexSelectat==40)
{
Vertex.x=-54.261713;
Vertex.y=-18.614050;
Vertex.z=-163.609310;
}


}

In my project, Vertex is defined as follows:


typedef struct Vertex {
float x, y, z;
int id;
} Vertex;

After I build the project, I get 6 errors "syntax error: missing ';' before '.' after every line where I specify Vertex coordinates. I am new to both OpenGL and C++ so sorry if this is a silly question. Waiting for some help, thank you for your time :). If you request, I can attach the whole project here.

GClements
07-27-2013, 09:28 AM
Before asking questions about using OpenGL from C, you should first learn to program in C.

And "learn" doesn't mean "spend a couple of hours reading a book"; you should be able to write non-trivial programs.

If you have problems with learning C, ask on a forum dedicated to C rather than one dedicated to OpenGL.

Nowhere-01
07-27-2013, 09:35 AM
it's not an opengl question.



typedef struct Vertex { float x, y, z; int id; } Vertex;

here you try to declare an instance of structure named "Vertex", under the name "Vertex". and you try to use it as an object. how compiler should interpret this? it's like writing "int int;". it doesn't complain about this line only because of legacy from C-language, where writing struct name as a postfix actually meant something else.

GClements
07-27-2013, 09:40 AM
here you try to declare an instance of structure named "Vertex"
Wrong. In C, it declares a structure tag named Vertex and a type named Vertex. In C++, it declares the type named Vertex in two different ways. In neither language does a typedef statement declare an instance of anything.

Nowhere-01
07-27-2013, 09:44 AM
yes, but in his mind, that's what he tries to do. he thinks he's declaring an instance of Vertex like that and also that it is legal to call an instance of the type the same name as the type. that's how it looks. i don't think he was aware, that writing struct name after it's body means something different.

Elencu007
07-29-2013, 01:52 AM
Sorry for this question, it was inappropriate to post it here, I noticed my mistake right away. I should have declared a variable of type Vertex, such as: Vertex vertex, then used vertex.x, vertex.y, vertex.z . I also found out a way to solve my problem, by relating how the code reads the .off file with my function. I'm not a programmer and I don't aspire being one, this is just a project, and I can state that I won't need OpenGL in my career (or I will need it rarely). I am sorry again.