Skip to main content
gamedev.net
🔒 Locked

Lean Question

Started by HellRaiZer May 31, 2003 at 1:18 AM 7 replies 1.4k views
Original Post
HellRaiZer
HellRaiZer
Does anybody have a clue on how can i implement a lean around a corner? You have to move the camera on a spline?
HellRaiZer
blueEbola
blueEbola
It depends on what kind of lean you want, you can have a full lean, a short quick one, etc.

I don''t think you''ll need splines to do it, have you tried manipulating the camera''s view matrix?
HellRaiZer
HellRaiZer
When i change the up vector of the camera,it turns the view but the position is constant.I want to move a little and the camera''s Position like in Soldier of Fortune,Return to Castle Wolfenstein etc.
HellRaiZer
iNsAn1tY
iNsAn1tY
Well, the way I found of doing it (which is kind of like the method in SoF and Jedi Knight II) is this: say your player is 96px tall (6ft * 16px). You load your normal camera transforms, but then you translate up the y axis 48px (96px / 2). Now, the origin is at the player's virtual waist, right? If you put in a rotation about the z axis before you do this 48px translation, you can "lean" your camera around a corner.


glLoadIdentity();

glRotatef(camera.orientation[2], 0.0f, 0.0f, 1.0f);
glRotatef(camera.orientation[0], 1.0f, 0.0f, 0.0f);
glRotatef(camera.orientation[1], 0.0f, 1.0f, 0.0f);
glTranslatef(camera.pos[0], camera.pos[2], camera.pos[2]);

if(bPlayerIsLeaning)
glRotatef(leanangle, 0.0f, 0.0f, 1.0f);

glTranslatef(0.0f, 48.0f, 0.0f);
Of course, this method will simply snap the user into a lean position, but it's not difficult to animate it a little (just add to and subtract from the leanangle variable). Anyway, hope it helps...



Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]


[edited by - iNsAn1tY on May 31, 2003 8:11:12 AM]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
MrNeedHelp
MrNeedHelp
Hellraizer give us a screenshot of ur project , whatever it - i am curious to see !
thanks
HellRaiZer
HellRaiZer
Insanity :
Can you re-write the code using gluLookAt if possible??? Because for

camera transforms i use gluLookAt and i don''t know exactly the

equivelant functions calls to Rotate and Translate!!!! Your code

seems to work with only z-rotations, because you are not using

LookAt. I think there may be a problem when using it!!!

I remember you from a shadow related post. You said that if i wanted

help on shadow maps, you could help. I tried nVidia''s tuts on

projective texturing, but there are some problems when trying to

render the depth texture. Everything was white. I saved the depth

texture on disk to see it and it was ok (not completely white). If

you have some solution or tut on shadow maps (except nVidia) please

say it!!!

MrNeedHelp:
Why you are so curious for my project??? I''m curious too, you know???
Btw i don''t have a way to post a screenshot. You must upload it to

your space, in case to post it here. So, i dont have any space!!!

Thanks again.

HellRaiZer
HellRaiZer
iNsAn1tY
iNsAn1tY
Well, see, the problem is this: I don't use gluLookAt(), so I don't know how you'd code it. Maybe someone else can suggest a method of using the transforms I suggested with gluLookAt?

As to the shadow problem, you must set up the projective texturing very specifically. I got mine to work, but it wasn't a walk in the park. Neither is setting up the register combiners. You need these for shadowmapping, otherwise your shadowmap will be displayed on every polygon, as opposed to only the ones which require it. You must test every fragment of every polygon to see if it's depth value matches that of the shadowmap. If it does, it isn't in shadow. If it doesn't, then it's in shadow. The only way I've found of doing this so far with the nvidia reg coms, and I'm not even sure how to configure them, as I don't have all that much experience with them. I'm not at home at the moment, but I'll post some projective texturing code here which works when I get there...

EDIT: Yeah, my bad. I should have put "email me" in that shadow volume post you made, but I put "post again" and didn't check back. Anyway, I'll post that info when I get home...



Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]


[edited by - iNsAn1tY on June 2, 2003 11:26:09 AM]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
iNsAn1tY
iNsAn1tY
OK, here's that projective texturing code...


GLfloat fSVector[] = { 0.5f, 0.0f, 0.0f, 0.0f };
GLfloat fTVector[] = { 0.0f, 0.5f, 0.0f, 0.0f };
GLfloat fRVector[] = { 0.0f, 0.0f, 1.0f, 0.0f };
GLfloat fQVector[] = { 0.0f, 0.0f, 0.0f, 1.0f };

void RenderScene(void)
{

GLuint x = 0, y = 0;

// Clear the colour and depth buffers...

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Select and reset the modelview matrix...

glMatrixMode(GL_MODELVIEW);
glPushMatrix();

// Do user rotations and translations...

glRotatef(sysUser.fOrientation[2], 0.0f, 0.0f, 1.0f);
glRotatef(sysUser.fOrientation[0], 1.0f, 0.0f, 0.0f);
glRotatef(sysUser.fOrientation[1], 0.0f, 1.0f, 0.0f);
glTranslatef(-sysUser.fPosition[0], -sysUser.fPosition[1], -sysUser.fPosition[2]);

/////////////////////////////////////////////////////////////////////////////////

// First pass...

/////////////////////////////////////////////////////////////////////////////////


// Bind your textures...

glBindTexture(GL_TEXTURE_2D, uiTextureObjects[1]);
glColor3f(1.0f, 1.0f, 1.0f);

// Draw the scene...


/////////////////////////////////////////////////////////////////////////////////

// Second pass...

/////////////////////////////////////////////////////////////////////////////////


// Switch to the texture matrix, and set

// up everything for the spotlight...

glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glTranslatef(0.5f, 0.5f, 0.0f);
glRotatef(0.0f, 1.0f, 0.0f, 0.0f);
glScalef(0.5f, 0.5f, 1.0f);
glFrustum(-0.035, 0.035, -0.035, 0.035, 0.1, 1.9);
glTranslatef(0.0f, -3.0f, 0.0f);

// Bind the projector texture...

glBindTexture(GL_TEXTURE_2D, uiTextureObjects[7]);
glColor3f(1.0f, 1.0f, 1.0f);

// Disable texcoords, enable texcoord

// generation and enable blending...

glTexGenfv(GL_S, GL_EYE_PLANE, fSVector);
glTexGenfv(GL_T, GL_EYE_PLANE, fTVector);
glTexGenfv(GL_R, GL_EYE_PLANE, fRVector);
glTexGenfv(GL_Q, GL_EYE_PLANE, fQVector);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_GEN_Q);
glEnable(GL_BLEND);

// Draw the scene again...


// Re-enable texcoords, disable texcoord

// generation and disable blending...

glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glDisable(GL_TEXTURE_GEN_Q);
glDisable(GL_BLEND);

// Pop the texture matrix...

glPopMatrix();

/////////////////////////////////////////////////////////////////////////////////

// End of rendering...

/////////////////////////////////////////////////////////////////////////////////


// Pop the modelview matrix...

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

}

void SetupRC(void)
{

// Set the aspects of the OpenGL state

// machine needed to create the scene...

glBlendFunc(GL_ONE, GL_ONE); // Set up (one:one) blending...

glEnable(GL_DEPTH_TEST); // Enable depth testing...

glDepthFunc(GL_LEQUAL); // Set lequal depth replacement...

glEnable(GL_CULL_FACE); // Cull the back faces of polygons...

glShadeModel(GL_SMOOTH); // Set the shading model to smooth...

glEnable(GL_TEXTURE_2D); // Enable 2D textures...


// Set up automatic texture generation...

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);

}
That's it. The SetupRC() and RenderScene functions in there are all you need. SetupRC() basically initializes all the state variables, and initializes auto texcoord generation. In RenderScene(), the scene is drawn first without the projected texture, then with it. Notice how blending is enabled, along with texture coordinate generation, then turned off after. This is just shows a basic spotlight as an example, but it's not difficult to get a light's depth map and render it, as you've already done.

However, I'm not sure that this is robust projective texturing. I think there are some issues not dealt with in this code which would need to be included. I think you have multiply in the transpose of the modelview matrix after you've created the projection in the texture matrix (as mentioned in the nvidia paper), but I'm not sure. This demo seems to work fine. Search on Google under "projective textures". Hope this all helps...



Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]


[edited by - iNsAn1tY on June 2, 2003 4:03:03 PM]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
zer0wolf
zer0wolf
I have no problem with storing images on my server space at retrospiral.net. If you''d like for me host any images for ya, I will

---------------------------------------------------
laziness is the foundation of efficiency
retrospiral.net | llamas! | megatokyo | FreeBSD | gamedev.net | google

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.