Jump to content

  • Log In with Google      Sign In   
  • Create Account

Opengl object positioning?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 HeExists   Members   -  Reputation: 193

Like
0Likes
Like

Posted 15 May 2011 - 08:01 AM

Hi,
I just want to know a simple question regarding the glTranslatef. How do I position 10 plaines one after another in x axis, like a tile map using a plain?
I don't want to use glVertex3f to do so.
   for(int i=0; i<10; i++)
   {
   	glTranslatef(i, 0.f, 0.f);
   	glutSolidPlaine();
   }

Above is what I am doing right now. But It is overlapping each other by half.

Thanks in advance.
Regards

Attached Thumbnails

  • planePosition.JPG


Sponsor:

#2 D.Chhetri   Members   -  Reputation: 181

Like
0Likes
Like

Posted 15 May 2011 - 08:06 AM

You need to translate it by i + width of the plane, i think.
Edge cases will show your design flaws in your code!
Visit my site
Visit my FaceBook
Visit my github

#3 HeExists   Members   -  Reputation: 193

Like
0Likes
Like

Posted 15 May 2011 - 08:31 AM

Hi Chhetri,
I tryed that way. the width of the plaine is 1 unit. But all plaines just move 1/2 unit to +x axis but remain as it is.

Thanks for reply
Regards

#4 __sprite   Members   -  Reputation: 461

Like
0Likes
Like

Posted 15 May 2011 - 08:36 AM

Don't you just want to translate it by the width of the plane each time through the loop (probably after rendering)? (i is not relevant here since calls to glTranslate will be cumulative as you're not pushing / popping from the matrix stack):

e.g. assuming the width of the plane is 5 you want:

// render at (0, 0, 0)
glTranslate(5, 0, 0);

// render at (5, 0, 0)
glTranslate(5, 0, 0);

// render at (10, 0, 0)
glTranslate(5, 0, 0);

// render at (15, 0, 0)

Note that the results will depend on the model space origin of the plane. (If the origin is in the center of the plane, you might want to translate once by half the plane width before rendering, depending on how you want your grid positioned in world space).

#5 HeExists   Members   -  Reputation: 193

Like
0Likes
Like

Posted 15 May 2011 - 08:44 AM

Hi __sprite,
Actually I posted above code for siplicity. Here is my actual code:

void DrawTiles(void)
{
	for(int i=0; i<10; i++)
	{
    	for(int j=0; j<10; j++)
    	{
        	switch(cMap[i][j])
        	{
        	case 0:
            	glBindTexture(GL_TEXTURE_2D, texture1);
            	break;
        	case 1:
            	glBindTexture(GL_TEXTURE_2D, texture2);
            	break;
    	}
        	glPushMatrix();
        	glTranslatef((j, 0.f, i);
        	plaine->DrawPlaine(1.0f);
   		//plaine->setPosition(j, 0.f, i);
   		glPopMatrix();
    	}
	}
}

Pivot position is upper left corner, not middle.

Thanks for reply
Regards




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS