Jump to content
  • Advertisement

Archived

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

DangerDave

Static positioning (Skybox)

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

Is it possible to render a skybox so the player is always centred in it without translating the skybox by the players x,y,z coordinates (moving with the player)? Since the skybox is just a static object (allbeit one that rotates) I would have thought you could skip the world translations and whatnot. And more generally how do you go about putting static images on the screen? Dave.

Share this post


Link to post
Share on other sites
Advertisement
I implemented (stealed) my skybox from one of the DX examples..
actually I''m using a sphere instead :D . It''s fast to render (only 12x12 segments) and It''s easier to map with your desired background.
U can also use a sphere in a space-game.. works great.

Share this post


Link to post
Share on other sites
erm. allready forgot what example that was..
but to the code of

RenderBackground()
...

if (BackGroundMesh && lpDevice){
D3DMATRIX matView;
// first get the translation..

lpDevice->GetTransform( D3DTRANSFORMSTATE_VIEW, &matView );
// next line is for centering the thing..

matView._41 = 0.0f; matView._42 = 0.0f; matView._43 = 0.0f;
lpDevice->SetTransform( D3DTRANSFORMSTATE_VIEW, &matView );
// no z-buffer or lighting for skybox..

lpDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, FALSE );
lpDevice->SetRenderState( D3DRENDERSTATE_ZWRITEENABLE, FALSE );
lpDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE);
BackGroundMesh->Render(lpDevice);
// restore z-buffer & lighting after rendering

lpDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, TRUE );
lpDevice->SetRenderState( D3DRENDERSTATE_ZWRITEENABLE, TRUE);
lpDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, TRUE);


hope this helps.

[edited by - Pothead on August 18, 2003 10:35:54 AM]

Share this post


Link to post
Share on other sites
If you draw you sky box first (around the camera) with Z writing disabled, then draw everything else, the sky box will seem to be behind everything, which is the effect you want, even though you drew it first. (Thats what the above code sample is doing, a bit of an explination wouldnt have gone amiss )

You will still have to make sure the camera and the sky box are at the same coordinates, but thats not to hard to do

Share this post


Link to post
Share on other sites
yep. I should have stated out that the above code has to be rendered before everything else..
these lines:
// first get the translation..
lpDevice->GetTransform( D3DTRANSFORMSTATE_VIEW, &matView );
// next line is for centering the thing..
matView._41 = 0.0f; matView._42 = 0.0f; matView._43 = 0.0f;
lpDevice->SetTransform( D3DTRANSFORMSTATE_VIEW, &matView );

modifies the translation matrix so that only rotation is taken into account. what modifies the position are the values _41,_42 and _43 so you dont have to worry about camera position while drawin your sky/stars whatever is behind everything that rotates but doesn''t move..

Share this post


Link to post
Share on other sites
It's a lot easier to render the skybox after setting up the camera. Just translate the the center of the skybox to the camera locatation!!!

In OpenGl:
    glPushMatrix();
glTranslatef( eyex, eyey, eyez );
RenderSkyBox();
glPopMatrix();
...
In D3D:
    D3DXMatrixTranslation( &matWorld, eyex, eyey, eyez );
pD3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
RenderSkyBox();
...


And of course, don't forget to clear the Z buffer, and turn off z-write and Z-test.

[edited by - JohnBolton on August 18, 2003 5:51:39 PM]

Share this post


Link to post
Share on other sites

  • 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!