Jump to content
  • Advertisement
Sign in to follow this  
glmisscelan

Model paralell to surface

This topic is 3978 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

hi, I getting some problems trying to rendering my model paralell to surface. I made my model on milkshape looking at z axis (0,0,1) When i render the model i do this:
glPushMatrix();
glTranslatef(modelpos.x, modelpos.y, modelpos.z); //here i tranlate the model to its position
glRotatef(model.angleyrotation, 0, 1, 0); //rotate the model depending of selected direction

Until here everthing goes right. After doing this i try to move my model paralell to surface, thats what im do:
tvector3f updir           = vec_init_direccion(VEC_DIR_Y);  //updir
tvector3f axisforrotation = vec_producto_vectorial_p(surfacenomal, &updir); //cross product to get the axis for rotation
float angle               = vec_angulo_p(&updir, surfacenomal); //get the angle between the this two vectors
glRotatef(angle, axisforrotation.x, axisforrotation.y, axisforrotation.z); //apply it
glPopMatrix();

The problem is that my model always rotated axisforrotation acording to its original position (z axis) after it the model is rotated by Y axis acording to its direction, but i made first the rotation on Y axis and after the axisforrotation!!. Why it works on that way? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement

Hey ,

are u sure b4 u do ur transformations that ur object on the origin point ?

please post more info about ur current matrix b4 u do the pushing,
this is all i can think about .

take care.

Share this post


Link to post
Share on other sites
Consider the follwing:

glScalef(...);
glTranslatef(...);

This will actually translate first and then apply the scale. This is because the matrices are multiplied from the right (ScalingMatrix * TranslationMatrix) * VertexPosition.

Maybe you have to reorder your transformations to get the desired result.

Share this post


Link to post
Share on other sites
Hi,

I tried to reorder the glrotatef calls but if i put the axisforrotation call first i get very strange results.

Before this, thats the way i set the camera


glLoadIdentity();
gluLookAt(t_cam.v_position.current.x,
t_cam.v_position.current.y,
t_cam.v_position.current.z, //current camera position
modelpos.x, modelpos.y, modelpos.z, //model position
0.0, 1.0, 0.0);



And after this i dont touch any openglmatrix until the models draw procedure.

Thanks for your help!!.

Share this post


Link to post
Share on other sites
u sure u do rotation off the axis?

try to remove last rotation and see what u get?

Share this post


Link to post
Share on other sites
First, thanks for your time and help.

At the begining i have no axis rotation for paralell surface, so i didt make this line:

glRotatef(angle, axisforrotation.x, axisforrotation.y, axisforrotation.z);

And it worked perfect, not parallel to surface, but it worked well, but i wanted my model to be able to creep, and i will only add this line when my model is in that position.

Here some pics (green line is zaxis and red line is de model surface). As you can see my modelsurface is always rotated on its original axis (z) and only seems to work in pic 1 when it goes in z direction.

description of your image

description of your image

description of your image

Thanks!!!

Share this post


Link to post
Share on other sites
hmmm i think i got it..

try to make ur vector be on one of main axises ex. i,

to do this u need :

1) compute the angle between ur normal on current surrface by.

normal (dot) i = cos(theta)

2) do rotation to allign it on i axis.

glRotatef(-theta,1,0,0);

3) do rotation based on ur computed angle.

4) return the vector to orignal place.

glRotatef(theta,1,0,0);

i am sure there is bug somewhere >.>;;

but try and see ^^;

take care.

[Edited by - ff8 on December 2, 2007 4:55:21 PM]

Share this post


Link to post
Share on other sites

nvm my last post has some errors >.>;;

i think u need to make XZ-plan perpendicular ur normal.

to do this :

1) compute angle between normal and x-axis .

angleX=cos^-1(normal (dot) i)

2) compute angle between normal and z-zxis.

angleZ=cos^-1(normal (dot) k)

then do this :

glTranslatef(...);
glRotatef(-angleX,1,0,0);
glRotatef(-angleZ,0,0,1);


i hope this works and plz ^^;;;

take care.

Share this post


Link to post
Share on other sites
hi again

i dont know if you told me something like this


float angleX = vec_angulo_p(&xaxis, surfacenomal);
float angleZ = vec_angulo_p(&zaxis, surfacenomal);

glRotatef(-angleX, 1,0,0);
glRotatef(-angleZ, 0,0,1);

glRotatef(angle, axisforrotation.x, axisforrotation.y, axisforrotation.z);

glRotatef(angleZ, 0,0,1);
glRotatef(angleX, 1,0,0);



with this i get the rotation on x model axis, before it was on z model axis.

This is quite frustrating, anyway i really apreciate your help!

i have a couple of ideas but i will try it tomorrow, now im very tired!.

Thanks

Share this post


Link to post
Share on other sites

try this alone w/o ur rotating vector :


glTranslatef(...);
glRotatef(-angleX,1,0,0);
glRotatef(-angleZ,0,0,1);


glRotatef(angle, axisforrotation.x, axisforrotation.y, axisforrotation.z); <- no need

after trying it tell me what u get ,

take care.

Share this post


Link to post
Share on other sites
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!