Sign in to follow this  

Skybox

This topic is 3571 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 guys, After reading lots of posts here I came up with this: // create my box (width=1,height=1,depth=1) centered at camera (origin for now) CreateBox(); // render D3DXMatrixOrthoLH(&projectionMatrix,0.75f,0.75f,-1.0f,1.0f); g_d3d_device->SetTransform(D3DTS_PROJECTION,&projectionMatrix); D3DXMatrixIdentity(&viewMatrix); g_d3d_device->SetTransform(D3DTS_VIEW,&viewMatrix); D3DXMatrixRotationYawPitchRoll(&worldMatrix,camera_yaw,camera_pitch,0.0f); g_d3d_device->SetTransform(D3DTS_WORLD,&worldMatrix); g_d3d_device->SetRenderState(D3DRS_ZENABLE,D3DZB_FALSE); g_d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST,0,36); // then change transformations to draw my objects on top Is that a proper way of doing it ? Am I correct is thinking that the width and height of D3DXMatrixOrthoLH() has to be a minimum of (0.71,0.71) ? Should I use D3DXMatrixOrthoLH() at all ? Also, should my texture be square or have a 4:3 ratio ? I know I'll have to "perspective correct" my textures but I don't want to get to that until I know for sure my render code is right. Thank you.

Share this post


Link to post
Share on other sites
There is a sample with the Diretx SDK called HDRFormats. There are two files in that sample (skybox.h and skybox.cpp) containing a simple, easy to use and well written class for a skybox. Hope this helps.

Share this post


Link to post
Share on other sites
You don't want to use an orthographic projection, you want to use a perspective projection. In fact you probably want to use the same perspective projection that you use for the rest of your scene. You also don't need to use a world transform, you can set that to indentity. Then for your view transform use your view matrix but with the translation portion (._41, ._42, ._43) set to 0.

Share this post


Link to post
Share on other sites
Hi MJP,

I did it like you said and I don't see anything at all:

// initialize

CreateBox();

D3DXMatrixPerspectiveFovLH(&projectionMatrix,D3DX_PI/4,1.0f,1.0f,100.0f);
g_d3d_device->SetTransform(D3DTS_PROJECTION,&projectionMatrix);

// render

D3DXVECTOR3 vEyePt(0.0f,0.0f,0.0f);
D3DXVECTOR3 vLookatPt(0.0f,0.0f,1.0f);
D3DXVECTOR3 vUpVec(0.0f,1.0f,0.0f);

D3DXMatrixLookAtLH(&viewMatrix,&vEyePt,&vLookatPt,&vUpVec);
g_d3d_device->SetTransform(D3DTS_VIEW,&viewMatrix);

viewMatrix._41=0.0f;
viewMatrix._42=0.0f;
viewMatrix._43=0.0f;

D3DXMatrixIdentity(&worldMatrix);
g_d3d_device->SetTransform(D3DTS_WORLD,&worldMatrix);

g_d3d_device->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0),1.0f,0);

g_d3d_device->BeginScene();

g_d3d_device->SetStreamSource(0,g_vertex_buffer,0,sizeof(CUSTOMVERTEX));
g_d3d_device->SetFVF(D3DFVF_CUSTOMVERTEX);

g_d3d_device->SetTexture(0,g_texture_01);
g_d3d_device->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
g_d3d_device->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
g_d3d_device->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
g_d3d_device->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_DISABLE);

g_d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST,0,12);

g_d3d_device->EndScene();

g_d3d_device->Present(NULL,NULL,NULL,NULL);

I must be doing something wrong. If I translate the box (using the world matrix) 10 units away from me (positive z) I see the box, but when I'm inside it I can't see anything. It's not the culling.

Please help.

Share this post


Link to post
Share on other sites
Quote:
Original post by Endemoniada
I must be doing something wrong. If I translate the box (using the world matrix) 10 units away from me (positive z) I see the box, but when I'm inside it I can't see anything. It's not the culling.

Please help.

The near-clip plane of your camera is 1 units. Is the size of your box is also 1 units? If so, the camera is clipping your box.

Share this post


Link to post
Share on other sites
Hi, I think you may need to set back face culling
something like this before you draw
Device->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE)

Share this post


Link to post
Share on other sites
Hey guys,

I got it to work, it was the near-z that was causing the problem.

It doesn't look right though: when I rotate around the y-axis (yaw) about 45 degrees then rotate around the x-axis (pitch) it looks like it's rolling. I understand why that's happening but what do I do to fix it ? Is that where I ned to have "perspective corrected" textures or am I simply applying the rotation matrix all wrong ?

Thanks.

Share this post


Link to post
Share on other sites

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