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. Graphics
  4. How to render multiple 3D objects separately? Pin

How to render multiple 3D objects separately? Pin

Scheduled Pinned Locked Moved Graphics
tutorialquestion
5 Posts 4 Posters 14 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 #include "CubeDemo.h"
    #include "d3dApp.h"
    #include "GfxStats.h"
    #include "Vertex.h"
    #include "DirectInput.h"
    #include #include #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 up(0.0f, 1.0f, 0.0f);
    D3DXMatrixLookAtLH(&mView, &pos, &target, &up);
    	D3DXMatrixTranslation(&T, -100.0f, 3.0f, (float)z);
    	HR(mFX->SetMatrix(mhWVP, &(R
    
    G F 2 Replies Last reply
    0
    • M Member 12268183

      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 #include "CubeDemo.h"
      #include "d3dApp.h"
      #include "GfxStats.h"
      #include "Vertex.h"
      #include "DirectInput.h"
      #include #include #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 up(0.0f, 1.0f, 0.0f);
      D3DXMatrixLookAtLH(&mView, &pos, &target, &up);
      	D3DXMatrixTranslation(&T, -100.0f, 3.0f, (float)z);
      	HR(mFX->SetMatrix(mhWVP, &(R
      
      G Offline
      G Offline
      Graham Breach
      wrote on last edited by
      #2

      You're setting the world transform, then drawing the cube followed by the cylinder. Either draw the cylinder before applying the world transform for the cube, or apply a new world transform before drawing the cylinder.

      M 1 Reply Last reply
      0
      • G Graham Breach

        You're setting the world transform, then drawing the cube followed by the cylinder. Either draw the cylinder before applying the world transform for the cube, or apply a new world transform before drawing the cylinder.

        M Offline
        M Offline
        Member 12268183
        wrote on last edited by
        #3

        Thank you very much for your help.

        1 Reply Last reply
        0
        • M Member 12268183

          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 #include "CubeDemo.h"
          #include "d3dApp.h"
          #include "GfxStats.h"
          #include "Vertex.h"
          #include "DirectInput.h"
          #include #include #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 up(0.0f, 1.0f, 0.0f);
          D3DXMatrixLookAtLH(&mView, &pos, &target, &up);
          	D3DXMatrixTranslation(&T, -100.0f, 3.0f, (float)z);
          	HR(mFX->SetMatrix(mhWVP, &(R
          
          F Offline
          F Offline
          Forrest90
          wrote on last edited by
          #4

          Thank you !

          R 1 Reply Last reply
          0
          • F Forrest90

            Thank you !

            R Offline
            R Offline
            Romain34
            wrote on last edited by
            #5

            ;) ;) ;) ;)

            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