void cSky::Render(LPDIRECT3DDEVICE9 pDxDevHandle, D3DXVECTOR3 Translation)
{
Pos=Translation;
D3DXMATRIX m_Translation;
D3DXMatrixIdentity(&m_Translation);
pDxDevHandle->SetStreamSource(0, p_SkyBox_VB, 0, sizeof(TEXTURED_VERTEX3D));
pDxDevHandle->SetFVF(CUSTOM_FVF_TEXTURED);
pDxDevHandle->SetIndices(p_SkyBox_IB);
pDxDevHandle->SetTexture(0,Tex.Use());
D3DXMatrixTranslation(&m_Translation,Pos.x,Pos.y,Pos.z);
pDxDevHandle->SetTransform(D3DTS_WORLD, &m_Translation);
pDxDevHandle->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,8,0,36);//its a cube!
}
Translation problems
I've been working on a skybox, and I want it to follow my camera (positon only, no rotations). easy you say, but even when I pass in the camera's eyepos, it barely moves. any ideas where the bug could be?
heres the rendering code for the skybox to get you started
You know, I was hoping this was about languages so I could make a joke about translation and rotation. I guess I'll just have to settle for giving a real answer :(
Well, I'm not sure how you do your camera, but simple code often looks like this:
In this case, the skybox's position would be camera.x, camera.y, camera.z, and all rotations are 0. The net effect is that the box is untranslated, but rotated.
Well, I'm not sure how you do your camera, but simple code often looks like this:
// pseudocodecamera_view: load_identity rotate_z(-camera.rz) rotate_y(-camera.ry) rotate_x(-camera.rx) translate(-camera.x-camera.y,-camera.z)render: camera_view translate(object.x,object.y,object.z) rotate_x(object.rx) rotate_y(object.ry) rotate_z(object.rz) draw(object)
In this case, the skybox's position would be camera.x, camera.y, camera.z, and all rotations are 0. The net effect is that the box is untranslated, but rotated.
Thanks for trying dude, but I'm defiately getting wierd behaviour. even if I put my own translation vector, like D3DXVECTOR3 (128,128,128); my box is drawn near the origin. It's like i've got some hidden scaling, but I've not used any scaling anywhere.
D3DXMatrixIdentity(&m_Translation);
Well, it looks like what you're doing is starting with the identity matrix instead of the current matrix, and I'm not sure what you're doing if anything to preserve the current matrix for after you render the skybox.
Tried that now, but I'm still getting a tiny translation instead of a full-scale one. I have a Height mapped terrain, which renders in the expected place, it only seems to be my skybox that does. very strange.
Now that I've done that though, I can begin to see the camera's rotation affecting the skybox.
any way I can get the camera's position in world space? that would surely be where I'd want to put the skybox.
Now that I've done that though, I can begin to see the camera's rotation affecting the skybox.
any way I can get the camera's position in world space? that would surely be where I'd want to put the skybox.
I suppose I'm not sure how you set up your view matrix; many people specify the location of the camera, and then set their view matrix based on that. What do you do?
Would it not be easier to set the camera's position, and thus the view matrix, back to the origin for skybox rendering, rather than translating the skybox with the camera? When rendering the skybox, zero out the view matrix' translation elements, so that the camera is at the skybox' centre. This can be done using the LookAt function and specifying that the camera's position at 0,0,0. You can then reset the view matrix to the normal way for rendering other non-skybox objects. I think that thats the more conventional way of rendering skyboxes.
Anyways, I agree with erissian. Your function seems to be fine, so there is probuary a problem with the way you're managing your view matrix. I think posting some more of the code (specifically the part that calls the skybox render function) may help in solving this one.
Anyways, I agree with erissian. Your function seems to be fine, so there is probuary a problem with the way you're managing your view matrix. I think posting some more of the code (specifically the part that calls the skybox render function) may help in solving this one.
ok, guys, thanks for the help.
the code is created for modularity, so its a bit fragmented
This is the main loop, called from a D3DX9App class. Tidy
this is the camera's basic workings, they consist of a view matrix updater, and some control routines.
and the accessor seen in the main loop
the code is created for modularity, so its a bit fragmented
This is the main loop, called from a D3DX9App class. Tidy
void cGame::MainLoop(float FTime){ CheckForDebugEntry(); //keyboard handler to breakpoint CheckForQuitMsg(); //keyboard handler for quit Cam.Update(m_pDxDev, FTime); //update camera Skybox.Render(m_pDxDev,Cam.GetEyePos());//render skybox HeightMap.Render(m_pDxDev); //render heightmap }
this is the camera's basic workings, they consist of a view matrix updater, and some control routines.
void cCamera::UpdateViewMatrix(LPDIRECT3DDEVICE9 p_dx_Device){ D3DXMatrixIdentity( &m_mView ); D3DXVec3Normalize( &m_vTargetPos, &m_vTargetPos ); D3DXVec3Cross( &m_vRight, &m_vUpVector, &m_vTargetPos ); D3DXVec3Normalize( &m_vRight, &m_vRight ); D3DXVec3Cross( &m_vUpVector, &m_vTargetPos, &m_vRight ); D3DXVec3Normalize( &m_vUpVector, &m_vUpVector ); m_mView._11 = m_vRight.x; m_mView._12 = m_vUpVector.x; m_mView._13 = m_vTargetPos.x; m_mView._14 = 0.0f; m_mView._21 = m_vRight.y; m_mView._22 = m_vUpVector.y; m_mView._23 = m_vTargetPos.y; m_mView._24 = 0.0f; m_mView._31 = m_vRight.z; m_mView._32 = m_vUpVector.z; m_mView._33 = m_vTargetPos.z; m_mView._34 = 0.0f; m_mView._41 = D3DXVec3Dot( &m_vEyePos, &m_vRight ); m_mView._42 = D3DXVec3Dot( &m_vEyePos, &m_vUpVector ); m_mView._43 = D3DXVec3Dot( &m_vEyePos, &m_vTargetPos ); m_mView._44 = 1.0f; p_dx_Device->SetTransform( D3DTS_VIEW, &m_mView ); m_vUpVector=D3DXVECTOR3(0,1,0);}void cCamera::Update(LPDIRECT3DDEVICE9 p_dx_Device, float fTime){ // Move the camera's view by the mouse SetViewByMouse(); // This checks to see if the keyboard was pressed CheckForMovement(fTime); // Does what it says - Updates the View Matrix UpdateViewMatrix(p_dx_Device);}
and the accessor seen in the main loop
//basic accessors D3DXVECTOR3 GetEyePos() {return m_vEyePos;}
found a tutorial @ http://www.toymaker.info/Games/html/skybox.html
basically told me something similar to MattWhite06
so, thanks :)
basically told me something similar to MattWhite06
Quote:
When rendering the skybox, zero out the view matrix' translation elements, so that the camera is at the skybox' centre.
so, thanks :)
Quote:
found a tutorial @ http://www.toymaker.info/Games/html/skybox.html
basically told me something similar to MattWhite06
Cool, glad it helped. However, if you translate the skybox with the camera like you did, it should still work even though it isn't the conventional way. So, am going to have a crack at finding the bug anyways! [smile]
Quote:
m_mView._41 = D3DXVec3Dot( &m_vEyePos, &m_vRight );
m_mView._42 = D3DXVec3Dot( &m_vEyePos, &m_vUpVector );
m_mView._43 = D3DXVec3Dot( &m_vEyePos, &m_vTargetPos );
I may be wrong, but shouldn't this bit be simply your camera's position, but negative? Dot Producting will give you answers between -1 and 1, and may explain why your only getting slight movement of your skybox. Maybe this is the correct way instead?
m_mView._41 = -m_vEyePos.x; m_mView._42 = -m_vEyePos.y; m_mView._43 = -m_vEyePos.z;
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement