Jump to content
  • Advertisement
Sign in to follow this  

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

This topic is 3802 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); // Draw the object using the previously set world matrix. boxes->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

sorry for this.

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

//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)

// translate keystroke messages into the right format

// send the message to the WindowProc function

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

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

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

TheCamera.Move( 0.1);
else if (KEY_DOWN(VK_F1))
createEngel(TheCamera.GetPos().x, TheCamera.GetPos().y,


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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!