I'm relatively new to the world of 3D games programming and I am not sure if I am understanding some key concepts correctly.

Right now I have created a sphere that is 2.0f in radius which surround the camera to act as a sky box ( I disabled culling to ensure that it did not block structutes in my world, and then turned culling back on once it was drawn ), its position is currently relative to the world, which is a problem.

The problem is that when I walk over terrain my camera exits the 2.0f sphere causing me to see the default black colored sky, in order to solve this I think I need to move the sphere relative to the cameras world matrix.

I currently have this function, which takes in the master WVP matrices with an output parameter for the cameras world matrix:

void Camera::GetWorldMatrix(D3DXMATRIX w, D3DXMATRIX v, D3DXMATRIX p, 
                            D3DXMATRIX& camWorld)
    // How can I determine the cameras world matrix here?

How I get the cameras world matrix relative to the master world matrix?

  • \$\begingroup\$ Could you simply set the sphere's world matrix to be the same as the cameras (minus the radius of the sphere from the x, y, and z coords) everytime you update the camera's position? \$\endgroup\$
    – Banath
    Mar 18, 2015 at 21:35
  • \$\begingroup\$ Hey I think that could work, I'll give that a shot...typical of me to over think things :P \$\endgroup\$
    – Alesso
    Mar 18, 2015 at 21:39
  • \$\begingroup\$ or make the camera a parent of the sphere so when you set the camera pos the sphere moves with it (thinking about typical scene graphing) \$\endgroup\$
    – War
    Mar 18, 2015 at 21:42
  • \$\begingroup\$ hmm, how could I make the camera a parent @Wardy, new concepts to me! \$\endgroup\$
    – Alesso
    Mar 18, 2015 at 21:45
  • \$\begingroup\$ You were right @Banath, I added the new height offset at each intersect to the y component, that fixed my problem - thankyou :) \$\endgroup\$
    – Alesso
    Mar 18, 2015 at 21:50

1 Answer 1


Just move the skybox with the view. Just the translation of the view though. You wouldn't want the skybox to rotate and scale with your view. I suggest looking at this http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/ to understand matrices better. From what I've found this has a very simple explanation of them. To get an idea of what a transform matrix looks like (which the paper doesn't describe as much): enter image description here

This picture should help. When multiplied together you produce a transformation matrix. I usually keep the properties of my camera elsewhere. In some data structure that holds things like FOV, nearZ, farZ, position, etc.

In code I suggest something like this (Psuedocode):

D3DXMATRIX T = D3DXMatrixTranslation(eyePos.x, eyePos.y, eyePos.z);
D3DMATRIX WVP = D3DXMatrixMultiply(T, camera->GetView() * camera->GetProj());

// Then skipping some rendering code I fed the WVP to the shader where it then (in HLSL)
// did this for every vertex in the skybox
vout.PosH = mul(float4(vin.PosL, 1.0f), gWorldViewProj).xyww;
vout.PosL = vin.PosL;

gWorldViewProj is WVP it's just in the shader and named differently.

getView and GetProj return D3DXMATRIX view and proj matrices

  • \$\begingroup\$ Thanks Andrew, this looks very useful - I hacked a solution together with a float offset but that causes some unwanted flickering, transforming the matrix looks like what I need \$\endgroup\$
    – Alesso
    Mar 18, 2015 at 22:02
  • \$\begingroup\$ In terms of the matrixes to multiply, it would be the cameras view by the master world matrix? \$\endgroup\$
    – Alesso
    Mar 18, 2015 at 22:03
  • \$\begingroup\$ @Alesso updated my answer to include some code. That is the exact implementation in my "playground" graphics engine. (Where I play with graphics) and if you notice ONLY the translation was put into T (which serves as the world matrix for the skybox.) \$\endgroup\$ Mar 18, 2015 at 22:21
  • \$\begingroup\$ This worked a treat, I don't have enough rep to upvote for some reason, thanks for your help, I'm very greatful! \$\endgroup\$
    – Alesso
    Mar 18, 2015 at 23:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .