All pastes #792168 Raw Edit

Object.cpp

public text v1 · immutable
·published 2007-11-21 05:42 UTC
rendered paste body
#include "Object.h"
#include <string>

void Object::loadMesh(char *fileName, LPDIRECT3DDEVICE9 device){
    D3DXLoadMeshFromX( "tiger.x", D3DXMESH_SYSTEMMEM, 
                                   device, NULL, 
                                   &pD3DXMtrlBuffer, NULL, &g_dwNumMaterials, 
                                   &g_pMesh );

    D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();

    g_pMeshMaterials = new D3DMATERIAL9[g_dwNumMaterials];
    g_pMeshTextures  = new LPDIRECT3DTEXTURE9[g_dwNumMaterials];

    for( DWORD i=0; i<g_dwNumMaterials; i++ ){
        g_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;
        g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse;

        g_pMeshTextures[i] = NULL;
        D3DXCreateTextureFromFile( device, d3dxMaterials[i].pTextureFilename, &g_pMeshTextures[i] );
        // Done with the material buffer
    }
    pD3DXMtrlBuffer->Release();
}

Object::Object(void){
    g_pMesh          = NULL;
    g_pMeshMaterials = NULL;
    g_pMeshTextures  = NULL;
    g_dwNumMaterials = 0L; 

    pos.x = pos.y = pos.z = 0;
    rot.x = rot.y = rot.z = 0;
}

Object::~Object(void){
    if( g_pMeshMaterials != NULL ) 
        delete[] g_pMeshMaterials;

    if( g_pMeshTextures )
    {
        for( DWORD i = 0; i < g_dwNumMaterials; i++ )
        {
            if( g_pMeshTextures[i] )
                g_pMeshTextures[i]->Release();
        }
        delete[] g_pMeshTextures;
    }
    if( g_pMesh != NULL )
        g_pMesh->Release();
}

void Object::setPos(float x, float y, float z){
    pos.x = x;
    pos.y = y;
    pos.z = z;
}

void Object::setRot(float x, float y, float z){
    rot.x = x;
    rot.y = y;
    rot.z = z;
}