Sign in to follow this  

problem with "adding obstacles at run time" (createBox and virtual camera)

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

Hello friends, I modelled a corridor using rectangles and I want to add obstacles (small boxes) in front of me when walking in the corridor. To do this at run time, I use the function D3DXCreateBox(). I add boxes but this changes my camera's view. When I rotate the camera or move the camera in corridor and then when I add the boxes, I go back and obstacles' view changes OR my camera's view changes. How can I add obstacles (boxes) at run time with no view problems? I use the QUATERNION based camera class in http://www.codeguru.com/cpp/g-m/directx/directx8/article.php/c8279/ My function to create obstacles and to render them are : vector<LPD3DXMESH> boxes; // box objects vector<D3DXMATRIX> objWorldMatrices; // positions of box objects void createBox(float x, float y, float z){ D3DXCreateBox(dxObj.getD3DDevice(), BOX_WIDTH, // width BOX_HEIGHT, // height BOX_DEPTH, // depth &boxes[boxNumber-1], NULL); // translation D3DXMatrixTranslation(&objWorldMatrices[engelSayisi-1],x,y,z+5); } void renderBoxes() { int i; for(i = 0; i < engelSayisi; ++i) { // Set the world matrix that positions the object. dxObj.getD3DDevice()->SetTransform(D3DTS_WORLD, &objWorldMatrices[i]); // Draw the object using the previously set world matrix. boxes[i]->DrawSubset(0); } } What is wrong or lack in these codes? If necessary, I would post the entire camera class definition and implementation. Thanks a lot. I need your helps.

Share this post


Link to post
Share on other sites
In the above code,
// translation D3DXMatrixTranslation(&objWorldMatrices[engelSayisi-1],x,y,z+5);

should be

// translation
D3DXMatrixTranslation(&objWorldMatrices[engelSayisi-1],x,y,z+5);

sorry for this.

In while loop in the main.cpp file, I make function calls like:

while(TRUE)
{
//DWORD starting_point = GetTickCount();

// Check to see if any messages are waiting in the queue
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// If the message is WM_QUIT, exit the while loop
if (msg.message == WM_QUIT)
break;

// translate keystroke messages into the right format
TranslateMessage(&msg);

// send the message to the WindowProc function
DispatchMessage(&msg);
}


preRender(dxObj.getD3DDevice()); // prerenders the scene - starts the
//rendering

render_corridor(dxObj.getD3DDevice()); // refresh the corridor
renderBoxes(); // renders the boxes

postRender(dxObj.getD3DDevice()); // completing the rendering process


if (KEY_DOWN(VK_UP))
{
TheCamera.Move( 0.1);
}
else if (KEY_DOWN(VK_F1))
{
++engelSayisi;
boxes.resize(boxNumber);
objWorldMatrices.resize(boxNumber);
createEngel(TheCamera.GetPos().x, TheCamera.GetPos().y,
TheCamera.GetPos().z);
}

}

createEngel() and renderBoxes() functions are defined in the first post.



When creating and rendering the boxes at run time inside the corridor, how can their world positions and views be arranged?

your comments are valuable.

Share this post


Link to post
Share on other sites

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