Static positioning (Skybox)

Started by
5 comments, last by DangerDave 20 years, 8 months ago
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.
Dave.
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.
--------------------------------------------------------I'm not crazy, It's the TV that's crazy. Aren't you, TV?--------------------------------------------------------
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]
--------------------------------------------------------I'm not crazy, It's the TV that's crazy. Aren't you, TV?--------------------------------------------------------
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
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..
--------------------------------------------------------I'm not crazy, It's the TV that's crazy. Aren't you, TV?--------------------------------------------------------
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]
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Thanks guys this is exaclty what I needed.

Dave.
Dave.

This topic is closed to new replies.

Advertisement