Sign in to follow this  

Skybox rotation/movement problem (again)

This topic is 4858 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'm having the same (?) problem as I've seen others have with skyboxes. That is that I cannot get my skybox to stay still. I guess It's an easy fix, but I don't know what to do. I have a fixed camera, and is only moving/rotating one mesh. Unfortunately the skybox moves just like the single mesh does... This is what I do in my render: 1.) I call clear on my device with D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER 2.) I then call BeginScene. 3.) I then sets the view transform using my camera's matrix. 4.) Copies the matrix used in 1, and changes it to: matView._41 = 0; matView._42 = 0; matView._43 = 0; I then set the view matrix again, disable the Z buffer and lightning, renders the skybox, enables lightning, and z buffer and set the original view transform matrix. 5.) Sets the world transform using my mesh matrix. 6.) Renders the mesh. 7.) Finally I call EndScene So the question is: What have I missed? It feels like I've tried all sorts of things but so far without luck. Any ideas anyone? Thanks, Kristoffer

Share this post


Link to post
Share on other sites
Don't kill me if I'm wrong, but I think you need to undo the world transforms between rendering the mesh and the skybox, because:

..
View Transform: Sky
Render: Sky
World Transform: Mesh
Render: Mesh
..

(next pass)

..
View Transform: Sky
Render: Sky (with world transform still in effect)
..

So it looks like to me that you still have the world transforms for the mesh set when you render the skybox, thus the skybox is drawn with the same translations + rotations.

I'm 99% sure this is the problem. But then again, I'm often wrong. Good luck!

Share this post


Link to post
Share on other sites
If you want to move one mesh but not the others in your scene, you have to make a copy of the world matrix first then set it back to that after transforming and rendering the rotating mesh. For example:


D3DXMATRIX matEarth, matScale, matRotateY, matOld;

D3DXMatrixIdentity(&matOld);

// Calculate the earths position
D3DXMatrixRotationY(&matRotateY, timeGetTime()/1000.0f);
D3DXMatrixScaling(&matScale, 2.0f, 2.0f, 2.0f);


D3DXMatrixMultiply(&matEarth, &matScale, &matRotateY);

//Render the earth
m_pD3DDevice->SetTransform(D3DTS_WORLD, &matEarth);
m_dwTotalPolygons += m_pEarth->Render();

m_pD3DDevice->SetTransform(D3DTS_WORLD, &matOld); // Reset the world.so everything doesn't rotate together.




Hope that helps. Basically after step 6 you need to set the world matrix back to how it was before you did the transform. Oh by the way in mine I totally reset the world matrix but if you want to get its current state use pD3dDevice->GetTransform(D3DTS_WORLD, &matOld);

Share this post


Link to post
Share on other sites
Quote:
Original post by xegoth
If you want to move one mesh but not the others in your scene, you have to make a copy of the world matrix first then set it back to that after transforming and rendering the rotating mesh.

That never seems quite to work for me. Ah oh well. The many problems with VB6...

But yeah, that *should* work.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanks guy!,

I'll test your tips tonight :)

/Kristoffer

Share this post


Link to post
Share on other sites
1. Set world matrix to identity
2. Save view matrix
3. Change view matrix as you said e.g.
matView._41 = 0.0f; matView._42 = 0.0f; matView._43 = 0.0f;
4. Turn off z buffer and lighting
5. Render skybox
6. Turn back on z buffer and lighting
7. Set previously saved view matrix

This is if you want to render the skbox first. If you are fill rate limited you may want to render it last. If you do you need to still have z tests but not z writes.

Make sure each mesh can be rendered in any order so it does not affect future renderings. One good way of doing this is to use state blocks. With these blocks you can store the required changes and restore them after rendering.

Share this post


Link to post
Share on other sites

This topic is 4858 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this