Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. How to render multiple 3D objects separately?

How to render multiple 3D objects separately?

Scheduled Pinned Locked Moved Managed C++/CLI
tutorialquestion
1 Posts 1 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 12268183
    wrote on last edited by
    #1

    I would like to control two 3D objects separately using direct3d library. I drawn one cube and one cylinder. Unfortunately when I move the cube by the keyboard, I move the cylinder too. How to move only one of the 3d objects? Regards My code is here:

    #include <windows.h>
    #include "CubeDemo.h"
    #include "d3dApp.h"
    #include "GfxStats.h"
    #include "Vertex.h"
    #include "DirectInput.h"
    #include <crtdbg.h>
    #include <list>
    #include "d3dUtil.h"
    CubeDemo::CubeDemo(HINSTANCE hInstance, std::string winCaption,
    D3DDEVTYPE devType, DWORD requestedVP)
    : D3DApp(hInstance, winCaption, devType, requestedVP), MAX_SPEED(1500.0f), ACCELE(1000.0f)
    {
    mGfxStats = new GfxStats();
    // 10 units from origin.
    mCameraRadius = 10.0f;
    // Somewhere in the 3rd quadrant of xz-plane.
    mCameraRotationY = 1.2 * D3DX_PI;
    xPos = 0.0f;
    yPos = 0.0f;
    // 5 units off the ground.
    mCameraHeight = 1.0f;
    HR(D3DXCreateCylinder(gd3dDevice, 4.0f, 5.0f, 6.0f, 10, 4, &mCylinder, 0));
    // If you look at the drawCylinders and drawSpheres functions, you see
    // that we draw 14 cylinders and 14 spheres.
    int numCylVerts = mCylinder->GetNumVertices() * 14;
    int numCylTris = mCylinder->GetNumFaces() * 14;

    mGfxStats->addVertices(mNumGridVertices);
    mGfxStats->addVertices(numCylVerts);
    mGfxStats->addTriangles(mNumGridTriangles);
    mGfxStats->addTriangles(numCylTris);
    
    buildGeoBuffers();
    buildFX();
    buildVertexBuffer();
    buildIndexBuffer();
    onResetDevice();
    InitAllVertexDeclarations();
    checkDeviceCaps();
    

    }
    void CubeDemo::buildFX()
    {
    // Create the FX from a .fx file.
    ID3DXBuffer* errors = 0;
    HR(D3DXCreateEffectFromFile(gd3dDevice, "transform.fx",
    0, 0, D3DXSHADER_DEBUG, 0, &mFX, &errors));
    if( errors )
    MessageBox(0, (char*)errors->GetBufferPointer(), 0, 0);
    // Obtain handles.
    mhTech = mFX->GetTechniqueByName("TransformTech");
    mhWVP = mFX->GetParameterByName(0, "gWVP");
    }
    bool CubeDemo::checkDeviceCaps()
    {
    D3DCAPS9 caps;
    HR(gd3dDevice->GetDeviceCaps(&caps));
    if (caps.VertexShaderVersion < D3DVS_VERSION(3, 0))
    return false;
    if (caps.VertexShaderVersion < D3DPS_VERSION(3, 0))
    return true;
    }
    void CubeDemo::drawCylinders()
    {
    D3DXMATRIX T, R;
    D3DXMatrixRotationX(&R, D3DX_PI * 0.5f);
    int z = 30;

    D3DXVECTOR3 pos(100, 0, 0);
    D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
    D3DXVECTOR3
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups