Archived

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

Hog

Space field

Recommended Posts

Hog    122
Ok just trying to get me head round this If I had a space ship model located at the origin and I wanted to allow the user to use the keys to move the camera around the space ship in any direction then this I believe would be quite simply. But if I wanted the background to display a space scene all the time how would I go about this? Would it be something like this?? The space ship remains static at the origin. The camera does all the moving. The space ship and the camera are inside a large sphere which has a space image texture loaded to its interior, thus no matter where the camaera moves within the confine of the sphere the background would be space. Is this how it is done? Is it possible to put a texture indise a sphere and actually display it?

Share this post


Link to post
Share on other sites
evolutional    1393
Okay..

Imagine that your ''universe'' is contained within the walls of a giant cuboid.

The 6 faces of the cuboids are the sides of your univserse, if they face inwards (normals pointing in) then the textures you apply will be reversed. If you point them inwards then the textures you apply will be mapped correctly and the surfaces won''t be culled by your renderer

Share this post


Link to post
Share on other sites
Hog    122
Does this method/approach only hold true if I create the cuboid with a list of vertices?

for example would this work...

If I created a cubiod in anim8or, converted to x format then when I loaded the mesh scaled it to say 1000 square and placed the camera at the origin. Would I be able to load a texture to int inside faces?

Share this post


Link to post
Share on other sites
evolutional    1393
Should do, if you have each face with inward pointing normals.

It''s no different to modelling a room in MS3d and having the camera inside it.

have a look at the low-poly tutorials on Psionic3D; he explains how to create a FPS style room in a modeller and have it used as a ''level'' in a game.

The principle is the same as what you''re trying to do.

Share this post


Link to post
Share on other sites
neneboricua19    634
A cube who's inside is textured with some kind of background image is called a skybox. If you try to make a skybox a particular size, then when you place the objects of your game inside this skybox, you're going to have to always keep in mind that you can't place objects outside the limits of the skybox.

To get around this, what you do is just make your skybox a reasonable size (could be anything. 2x2x2, 10x10x10, etc...) and just disable the z-buffer right before you draw the skybox. At the beginning of your render method, you turn off the z-buffer (using SetRenderState), draw your skybox at the position of the camera, then turn the z-buffer back on (again, using SetRenderState). Then you draw the rest of your world as normal.

Turning off the z-buffer and drawing the skybox first basically initializes the background for the scene. Everyting that you draw afterword will be drawn on top of the skybox background reguardless of how far away it actually is. This creates the illusion that the background is really far away.

neneboricua

[edited by - neneboricua19 on January 20, 2004 4:10:15 PM]

Share this post


Link to post
Share on other sites
Hog    122
Kool

However, this puzzles me...

Say I have my skybox and I have scaled it 1000*1000*1000, (I think this should create a nice world?), and place the camera in it.

So if I have the camera at the origin, how would I know where to set the position of the skybox?

I mean, which vertex decides the starting location of the skybox, or am I showing an incedible ignorance here

Share this post


Link to post
Share on other sites
neneboricua19    634
There was a point when all This is the idea: you build your skybox about the origin. So if you want the length of the sides to be, say 100, then the vertices of your box are at (-50, 50, 50), (50, 50, 50), etc...

In your code, you then translate the box to the location of your camera. It would look something like this:

D3DXMATRIX matTranslate;
D3DXMatrixTranslation( &matTranslate, m_pCamera->GetPosition().x, m_pCamera->GetPosition().y, m_pCamera->GetPosition().z );
m_pd3dDevice->SetTransform( D3DTS_WORLD, &matTranslate );
m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
m_pSkyBox->Render()
m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );

This will place the center of the skybox at the position of the camera.

Hope this helps,
neneboricua

Share this post


Link to post
Share on other sites
DrunkenHyena    805
quote:
Original post by downgraded
Should do, if you have each face with inward pointing normals.



Normals have nothing to do with it. Normals are used for lighting and you should have lighting turned off when rendering your skybox. What you have to watch is the winding order of your vertices, which determine the "facing" of the triangles. If they are facing outwards, then they will be culled (unless you turn culling off for the rendering of the skybox). So you would generally want to reverse the winding order of the box. Scaling it by (-1,-1,-1) should do the trick too, just don''t do both.



Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites