Archived

This topic is now archived and is closed to further replies.

Please help me

This topic is 6107 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 everyone, I went through just about all of NeHe''s tutorials for GL and wanted to say they are the best tutorials I''ve ever read about OpenGL! However now I''m working with DirectX 8. I tried to implement one of NeHe''s tutorial (the one where you can walk around the world), but for some reason the results aren''t the same. Maybe someone here can help me. I''m trying to get the code below to work: Level1.Level.MeshPos.x -= (float)sin (Level1.Level.MeshAngle.y*piover180)*0.005f; Level1.Level.MeshPos.z -= (float)cos(Level1.Level.MeshAngle.y*piover180)*0.005f; The above code gets called whenever the user hits the UP arrow key, however it doesn''t work like it did in OpenGL. I''m probably missing something simple, but maybe you could point it out to me? Thank you very much for any help anyone can give me, -Sam. p.s. The above code is the same as it is in the tutorial (I think it''s tutorial 10, but I''m not sure)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
In OpenGL is the Z-axis pointing out of screen D3D default is the other way around. I think that you can set the coordinate system in D3D so it will be like OpenGL.

Share this post


Link to post
Share on other sites
Hi,

Thanks for your reply! However I don''t think I know what you mean. Acording to my experiments in DX8 all the axis seem the same.

-Sam.

p.s. I forgot to mention that I also tried the following:

Level1.Level.MeshPos.x -= (float)sin(Level1.Level.MeshAngle.y)*0.005f;
Level1.Level.MeshPos.z -= (float)cos(Level1.Level.MeshAngle.y)*0.005f;

Only difference is no piover180, but it still doesn''t work Thanks for any help anyone can give.

Share this post


Link to post
Share on other sites
Arrgh! I can sympathise on this one.

unfortunately, all I can say is keep plugging at it...

I''ve done this three times now.

I write the code, as I think it should work.
It doesn''t.
I fiddle with it for hours.
It still doesn''t work.
I change it back to what I thought I started with and it works...

very annoying, and probably says a lot about my coding skills!

good luck though!




I used to be indecisive. Now I''m not so sure...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Arrgh! I can sympathise on this one.

unfortunately, all I can say is keep plugging at it...

I''ve done this three times now.

I write the code, as I think it should work.
It doesn''t.
I fiddle with it for hours.
It still doesn''t work.
I change it back to what I thought I started with and it works...

very annoying, and probably says a lot about my coding skills!

good luck though!




I used to be indecisive. Now I''m not so sure...

Share this post


Link to post
Share on other sites
What are the symptoms ? I mean, you say it doesn''t work like it''s supposed to do, but in what way is it diffrent ?

(eg, you walk backwards instead of forward? or you fly up in the air? perhaps pink elephants spawn and do the kalinka?.. now that would be really weird.. )



return 1;

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
To be honest I can''t really tell whats going on, but I''ll try to describe it. When the level first loads, and everything is setup at angle 0 and position 0, everything works fine. Because whenever I press the up arrow key, the camera moves forward like it''s supposed to. However when I rotate just a little bit & then press the up arrow key, the camera still moves in the same direction as it did before when I didn''t rotate!

However if I rotate a lot (>20 degrees), then the camera moves in yet another direction...but not where I want it to go! It''s very wierd!

I can''t find a pattern to whats going on...it''s really confusing!

(BTW: actually the elephants are blue )

Thanks for any help.

-Sam.

Share this post


Link to post
Share on other sites
When the anonymous poster said the z-axis was reversed, what he meant was this:

The x-axis increases as it goes right. That means an object at x-coordinate 2 is to the right of an object at x-coordinate 1.

The y-axis increases as it goes up. So an object at y-coordinate 2 is above an object at y-coordinate 1.

But which direction does the z-axis go? Well, it can go either way (farther or closer). One way is called "right-handed", the other is "left-handed." OpenGL is right-handed, and Direct3D is left-handed by default, though you can make it right-handed. If you''re using the D3DX functions, D3DXLookAtLH is left-handed, D3DXLookAtRH is right-handed. There are LH and RH versions of the other view-related matrix operations as well.

But I don''t even think that''s the cause of your problem. It sounds like the problem is with setting your transformation matrix. How do you calculate it?

~CGameProgrammer( );

Share this post


Link to post
Share on other sites
I don''t have a clue of how direct3d does the transformation stuff, but if it''s like opengl (glRotate*(), glTranslate*())
Check to see that you do rotate the scene BEFORE translating it, the symptom described seems like you translate the scene first, and then rotate it. wich will not work very good, since when you rotate the scene you will rotate around an axis that is positioned behind/before to the left/right of you.


return 1;

Share this post


Link to post
Share on other sites
Hi,

Here is the code that rotates and transforms the matrix:

...
D3DXMATRIX matWorld,matWorld2;

D3DXMatrixRotationX( &matWorld, W.WorldAngle.x);
D3DXMatrixRotationY( &matWorld2, W.WorldAngle.y);

// now multiply the two matricies together:
D3DXMatrixMultiply(&matWorld,&matWorld,&matWorld2);

D3DXMatrixRotationZ( &matWorld2, W.WorldAngle.z);

// then multiply again:
D3DXMatrixMultiply(&matWorld,&matWorld,&matWorld2);

// Now that we have the rotations, we need to get the position
D3DXMatrixTranslation(&matWorld2,W.WorldPos.x,W.WorldPos.y,W.WorldPos.z);

D3DXMatrixMultiply(&matWorld,&matWorld2,&matWorld);

g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
...

Then the code goes on to actually rendering the world. Is this what you wanted?

I still don''t understand what could be wrong!

I also checked out NeXe, but he''s not up to the tutorial that I need...but I''ll keep checking.


-Sam.

Share this post


Link to post
Share on other sites
No, I don''t need to know what you do with your world matrix, just what you do with your view matrix. The view matrix defines the camera''s position. You do move the camera, don''t you? Or do you move the entire world instead? Meaning, when the user presses a key, do you change World.x or Camera.x?

~CGameProgrammer( );

Share this post


Link to post
Share on other sites
Sorry ''bout that. Actually I don''t change the view matrix at all...I move the whole world around.

However, while I was looking through flipcode.com, I saw another post about someone else having a similar problem. I read throught the post, and modified some code that someone else posted as a solution. So anyway I modified it, then put it in my engine, and everything works now!

The below code works...maybe it will help someone:

Level1.Level.MeshPos.x += (float)sin(Level1.Level.MeshAngle.y)*0.005f;
Level1.Level.MeshPos.z -= (float)cos(Level1.Level.MeshAngle.y)*0.005f;


That works fine for moving forward, and it''s the opposite for moving backward!

Thanks again for all the help you''ve given me!

-Sam.

Share this post


Link to post
Share on other sites
Good to hear you''ve fixed it... I didn''t get a chance to help or I would''ve hehe.

Oh, By the way, For anyone learning DirectX, the nexe site is at http://nexe.gamedev.net

They don''t actually have lesson 10 ported yet, but its a site worth keeping your eye on.

~Cobra~

Share this post


Link to post
Share on other sites
hi
i have a similar problem.
the following code works (its of one of nehe''s tutorials)

xpos+=(float)cos(zrotate*0.0174532925)*0.05;
ypos+=(float)sin(zrotate*0.0174532925)*0.05;

but this code doesn''t work:

xpos+=(float)cos(zrotate)*0.05;
ypos+=(float)sin(zrotate)*0.05;

if i use this code the cube i''m controling does not move in the right angle.
i really don''t have any idea why it does not work.

cu ][nika][

Share this post


Link to post
Share on other sites
I think (I may be wrong) the answer to your problem is as follows. The sin() and cos() functions take there inputs in radians. However OpenGL uses degrees. So when you times your degrees by 0.0174532925f, you convert the degrees into radians.

However DX8 takes radians...that''s why I don''t have to do this is the code I gave in my last post.

I could be wrong.

-Sam.

Share this post


Link to post
Share on other sites