Jump to content
  • Advertisement
Sign in to follow this  
MotionCoil

OpenGL Question on translation

This topic is 4813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all I got myself into a big muddle with my other engine so I have started on an engine to give me all the basics on OpenGL. I have ported all the other aspects I wrote (like the console, texture manager, font system, interface items etc) over to the new engine. However I decided to work on my own map very simple format that I could quickly write a basic map editor for. The syntax looks a bit like this (heres the TestLevel Example):
[HEADER]
NTEX=2
NGEO=3
SCALE=0.1 0.1 0.1
[/HEADER]

[TEXPOOL]
Wall1.BMP
Wall2.BMP
[/TEXPOOL]

[GEO]
[CUBE]
Pos=0.0 0.0 -1.0
DIM=1.0 10.0 -10.0
TEX=0 0 0 0 0 0
[/CUBE]

[CUBE]
Pos=0.0 0.0 -1.0
DIM=10.0 10.0 -1.0
TEX=1 1 1 1 1 1
[/CUBE]
[/GEO]

Anyway, I know how to improve on this (Tex coords, different primitives etc) but the test level is just to see if it renders properly. Ok, i'm coming across big problems! For some obscure reason I am unable to do the most basic of things... What I want to do is make a room out of cube primitives. The 2 primitives in the example render properly.
 -
| |
| |__
|____|

^
|
Cam
Except rotate it 90' on the Y Axis so you are in the 'cams' position so it looks like this:
 ----------
|          |
|          |
|          |
|          |
 ----------
Ok, now you know what it looks like. Thats Cube 1 being 1 unit wide, 10 units high, and 10 units depth. The second cube is 10 units wide, 10 units high and 1 unit depth. I have scaled it down by a factor (As shown in the map file) of 0.01 on every dimension. Now, I need to display a third cube but this one needs to go here(Coloured in):
 ____
|\\\\| <-HERE
| |
| |__
|____|

^
|
Cam
Now, How i'm doing the display is translating according to the "Pos x y z" in the map file. So if the Map file says "Pos 0.0 0.0 -1.0" I translate(0.0 0.0 -1.0) Looking at the map file you can see for the first 2 cubes I have translated -1 unit down the z axis. Umm, well, heres the source code so you can see when and where I do the different bits:
	
	
	int Width, Height, Depth, Index;
 for(Index = 0; Index<nGeo; Index++)
 {
	 glPushMatrix();
	 
	 Width = Geo[Index].Width;
	 Height = Geo[Index].Height;
	 Depth = Geo[Index].Depth;
	     glTranslatef(Geo[Index].PosX,Geo[Index].PosY,Geo[Index].PosZ);
	
	
	glScalef(Scalar[0],Scalar[0],Scalar[0]);	
	//glRotatef(rQuad,1,0,0);	

	
	glBindTexture(GL_TEXTURE_2D,  tPool[Geo[Index].IDtop]);
	glBegin(GL_QUADS);								// Draw A Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( Width, -Height,Depth);			// Top Right Of The Quad (Top)
		glTexCoord2f(0.0f, 1.0f); glVertex3f(0, -Height,Depth);				// Top Left Of The Quad (Top)
		glTexCoord2f(0.0f, 0.0f); glVertex3f(0, -Height, 0);					// Bottom Left Of The Quad (Top)
		glTexCoord2f(1.0f, 0.0f); glVertex3f( Width, -Height, 0);				// Bottom Right Of The Quad (Top)
	glEnd();
//.... and continue with the drawing of the rest of the cube
// According to dimensions
glPopMatrix();
}

So from this I assume that the translations are not scaled (are they scaled ever?) because I do the translation before the scaling. I also push the matrix before scaling or translating and then pop it after I have down all the drawing so I basically start afresh on the next cube. According to the map the first 2 cubes are drawing according to how they should be drawn. However, the rendering comes unstuck when I want to draw a cube in the position the other side of cube one (The position I showed in the diagram- the coloured in cube). I wasn't sure how many units I should translate down the Z axis so I tried 1 more unit so the third cube has a pos of X=0 Y=0 Z=-2. However this did not actually change the Z position of the cube but actually made it smaller. So I decided to change the scaling to 1.0 so it wasn't scaled at all and then moved the whole thing -60 units down the Z axis so I could see the whole thing. Since its on a ratio of 1:1 I tried translating the 3rd cube to -70 so It would join up with the 10 units in the 1st cube goes down the Z axis. Ok, so I try this and it the 3rd cube stays on the same Z as the rest of the cubes but appears smaller. I have no idea whats going on. All I want to do it make it so it translates the right distance into the Z axis (according to the map file) so I can add an opposite wall to cube 2. I'm very confused and I don't think I've made much sense on this post but I'm really stuck! Thanks for any help I'm very confused

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!