Author Topic: [C++] Opengl Glut 3D Mesh Topolgy  (Read 6794 times)

0 Members and 1 Guest are viewing this topic.

Offline da beast

  • ZX 81
  • *
  • Posts: 4
  • Karma: 0
  • Yes I does! just the way i are
    • View Profile
[C++] Opengl Glut 3D Mesh Topolgy
« on: June 09, 2011 »
It's supposed to rain until next TUESDAY!  SOoOOo I am going to work on my "stalled" project... Because it hasn't moved anywhere in awhile!

I have a project I started in C++ that I am doing for fun to expand my knowledge!  The first phase is a structure that can have unlimited nodes and pointers to other nodes, kind of like a mesh topologyhttp://sing.stanford.edu/gnawali/ctp/vinelab/topolog/topo.gif.  I have a rough draft of it done!  This is the most extensively I have used classes, I even am using a namespace which is a new concept to me! So my knowledge is already expanding. 

I want to build a visual for this structure using openGL.  I have checked out a couple tutorials http://www.lighthouse3d.com/tutorials/glut-tutorial/ because I have never actually done anything with openGL before!

My first question is:  How do objects such as two nodes and a conection(pointer) work together in coding to get a great openGL visual?  Are they all drawn separately?


~da*beast!

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: [C++] Opengl Glut 3D Mesh Topolgy
« Reply #1 on: June 09, 2011 »
Well as a knee jerk reaction I'd try a simple Neuron class that stores a STD List or Vector of pointers.
It should then be possible to have a function inside the Neuron class that:
1. Draws a simple box or sphere representing the Neuron at the proper (x,y,z) value. GLUT has some inbuilt drawing functions for primatives.
2. Iterates through all connected Neurons and draws a bridging line from (this->x, this->y, this->z) to (connected->x, connected->y, connected->z) (You might have some redundant drawing calls).

You'll probably want to store each Neuron in a List or Vector so you can cycle through them calling their draw functions.

I'm not the best coder here just tossing out ideas.
« Last Edit: June 09, 2011 by Pixel_Outlaw »
Challenge Trophies Won:

Offline da beast

  • ZX 81
  • *
  • Posts: 4
  • Karma: 0
  • Yes I does! just the way i are
    • View Profile
Re: [C++] Opengl Glut 3D Mesh Topolgy
« Reply #2 on: June 09, 2011 »
Thanks for the reply Pixel.  I didn't take your route exactly but I followed your logic.  I have two cubes and a line.  The problem is the line is not touching both cubes! 

Code: [Select]
void drawNodes() {

glColor3f(1.0f, 1.0f, 1.0f);

// Draw node
glTranslatef(0.0f ,0.75f, 0.0f);
glutSolidCube(1);

// Draw node2
glTranslatef(0.0f, 2.0f, 0.0f);
glutSolidCube(1);

glBegin(GL_LINES); //Begin drawing lines
       
    // 2 end points on line
glVertex3f(0.0f, 0.75f, 0.0f);
glVertex3f(0.0f, 2.0f, 0.0f);


glEnd();


}

This is my draw function
~da*beast!

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: [C++] Opengl Glut 3D Mesh Topolgy
« Reply #3 on: June 09, 2011 »


I think you are translating the world coordinates twice. This means that you have changed the position of the world's origin. You might consider pushing a transformation on, executing the drawing code, the popping it off the stack. Then draw your lines in the world coordinates.

I've not used glut but often those shape drawing commands like to draw a shape at position (0,0,0). This means you have to shift the world cordinates to where you want, draw the shape then return to the original coordinates.
Challenge Trophies Won:

Offline da beast

  • ZX 81
  • *
  • Posts: 4
  • Karma: 0
  • Yes I does! just the way i are
    • View Profile
Re: [C++] Opengl Glut 3D Mesh Topolgy
« Reply #4 on: June 09, 2011 »


I think you are translating the world coordinates twice. This means that you have changed the position of the world's origin. You might consider pushing a transformation on, executing the drawing code, the popping it off the stack. Then draw your lines in the world coordinates.

I've not used glut but often those shape drawing commands like to draw a shape at position (0,0,0). This means you have to shift the world cordinates to where you want, draw the shape then return to the original coordinates.


Thanks pixel! It's starting to make sense :P

Code: [Select]

void drawNode() {

glColor3f(1.0f, 1.0f, 1.0f);

// Draw node
glTranslatef(0.0f ,0.75f, 0.0f);
glutSolidCube(1);

glBegin(GL_LINES); //Begin drawing lines
       
    // 2 end points on line
glVertex3f(0.0f, 0.75f, 0.0f);
glVertex3f(0.0f, 2.0f, 0.0f);


glEnd();

// Draw node2
glTranslatef(0.0f, 2.0f, 0.0f);
glutSolidCube(1);

}


// Draw 36 Nodes
for(int i = -3; i < 3; i++)
for(int j=-3; j < 3; j++)
{
glPushMatrix();
glTranslatef(i*10.0f, 0.0f, j * 10.0f);
drawNode();
glPopMatrix();
}
}

~da*beast!