Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Hardcode a vertex

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    4

    Hardcode a vertex

    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:

    Code :
    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,viewport,&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:

    Code :
    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.
    Last edited by Elencu007; 07-28-2013 at 08:19 AM.

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    474
    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.

  3. #3
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    it's not an opengl question.

    Code :
    typedef struct Vertex {   float x, y, z;   int id; } [B]Vertex[/B];

    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.

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    474
    Quote Originally Posted by Nowhere-01 View Post
    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.

  5. #5
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    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.
    Last edited by Nowhere-01; 07-27-2013 at 10:17 AM.

  6. #6
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    4
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •