Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

AMesh.cpp File Reference


Detailed Description

implements the 'mesh_' functions in AEngine.h

Definition in file AMesh.cpp.

#include "AEngine.h"
#include "AUtil.h"

Include dependency graph for AMesh.cpp:

Include dependency graph

Go to the source code of this file.

Compounds

class  MeshRequestEntryComparer
 so we can sort mesh rendering request entries More...


Functions

void mesh_init ()
void mesh_render (const AMesh mesh, const Vec3D pos, const Vec3D size, const Vec3D dir, const ATexture texture, const ATexture bumpmap, const Vec3D stripColor)
void mesh_flush ()
 throw away all pending mesh-rendering requests

void mesh_processRenderRequests ()


Function Documentation

void mesh_flush  
 

throw away all pending mesh-rendering requests

Definition at line 76 of file AMesh.cpp.

Referenced by flushRenderRequests().

00077 {
00078         AS.mesh_renderList.resize(0);
00079 }

void mesh_init  
 

Definition at line 39 of file AMesh.cpp.

References sys_console(), util_loadPixelShader(), and util_loadVertexShader().

Referenced by sys_go().

00040 {
00041         if(AS.res_meshes.size()==0) return;
00042 
00043         // create Vertex&Index Buffer
00044         int vbByteSize = (int)AS.mesh_raw_vb.size() * sizeof(MeshVertex);
00045         int ibByteSize = (int)AS.mesh_raw_ib.size() * sizeof(USHORT);
00046         sys_console() << "Mesh : VertexBuffer Size = " << (int)AS.mesh_raw_vb.size() << endl;
00047         sys_console() << "Mesh : IndexBuffer  Size = " << (int)AS.mesh_raw_ib.size() << endl;
00048 
00049         AS.pDevice->CreateVertexBuffer( vbByteSize, D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED, &(AS.mesh_vb) );
00050         AS.pDevice->CreateIndexBuffer(  ibByteSize, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &(AS.mesh_ib) );
00051         
00052         MeshVertex *pVBdata;
00053         USHORT     *pIBdata;
00054         if( FAILED( AS.mesh_vb->Lock(0,0, (BYTE**)&pVBdata, 0) )) throw Error("Can't Lock MeshVB");
00055         if( FAILED( AS.mesh_ib->Lock(0,0, (BYTE**)&pIBdata, 0) )) throw Error("Can't Lock MeshIB");
00056 
00057         memcpy( pVBdata, &(AS.mesh_raw_vb[0]), vbByteSize );
00058         memcpy( pIBdata, &(AS.mesh_raw_ib[0]), ibByteSize );    
00059         
00060         AS.mesh_vb->Unlock();
00061         AS.mesh_ib->Unlock();
00062 
00063         // create V&P Shaders
00064         AS.vshader_mesh = util_loadVertexShader( "shaders\\mesh.vso", dwMeshVertexDecl );
00065         AS.pshader_mesh = util_loadPixelShader(  "shaders\\mesh.pso" ); 
00066 }

void mesh_processRenderRequests  
 

:

Definition at line 82 of file AMesh.cpp.

References MeshRenderRequestEntry::bumpmap, device_setIndexSource(), device_setPixelShader(), device_setRenderState(), device_setRenderStateBlendMode(), device_setStreamSource(), device_setTexture(), device_setTextureStageState(), device_setVertexShader(), MeshRenderRequestEntry::dir, MeshEntry::IBstart, Matx, MeshRenderRequestEntry::mesh, MeshRenderRequestEntry::pos, MeshRenderRequestEntry::size, MeshEntry::size, MeshRenderRequestEntry::stripColor, MeshRenderRequestEntry::texture, MeshEntry::TriCount, MeshEntry::VBcount, and MeshEntry::VBmin.

Referenced by processRenderRequests().

00083 {
00084         if(AS.res_meshes.size()==0) return;
00085         if(AS.mesh_renderList.size()==0) return;
00086 
00087         device_setVertexShader( AS.vshader_mesh );
00088         device_setPixelShader(  AS.pshader_mesh );
00089         device_setStreamSource( 0, AS.mesh_vb, sizeof(MeshVertex) );
00090         device_setIndexSource( AS.mesh_ib );
00091         device_setRenderState( D3DRS_ZENABLE,  TRUE );
00092         device_setRenderState( D3DRS_ZWRITEENABLE,  TRUE );
00093         device_setRenderState( D3DRS_SPECULARENABLE, FALSE );
00094         device_setTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
00095         device_setTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
00096         device_setTextureStageState( 0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR );
00097 
00099         device_setRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
00100         device_setRenderStateBlendMode( BlendModes::NONE );
00101 
00102         sort(AS.mesh_renderList.begin(), AS.mesh_renderList.end(), MeshRequestEntryComparer());
00103 
00104         Matx matTrans, matScale, matTheta, matFinal, matLighting;
00105         int last = (int)AS.mesh_renderList.size();
00106 
00107         
00108         for( int i=0; i<last; i++ )
00109         {
00110                 MeshRenderRequestEntry &e = AS.mesh_renderList[i];
00111                 MeshEntry &m = AS.res_meshes[e.mesh];
00112                 
00113                 // construct xform matrix
00114                 D3DXMatrixTranslation( &matTrans, e.pos[0], e.pos[1], e.pos[2] );
00115                 D3DXMatrixRotationZ( &matTheta, D3DXToRadian(e.dir[0]) );
00116                 D3DXMatrixScaling( &matScale, e.size[0]/m.size[0], e.size[1]/m.size[1], e.size[2]/m.size[2] );
00117                 matFinal = matScale * matTheta * matTrans * AS.camera_world2projMatrix;
00118                 D3DXMatrixTranspose( &matFinal, &matFinal);
00119                 D3DXMatrixTranspose( &matLighting, &matTheta);
00120 
00121                 AS.pDevice->SetVertexShaderConstant( 0, &matFinal, 4 );                 // world->proj matrix
00122                 AS.pDevice->SetVertexShaderConstant( 4, &matLighting, 4 );              // rotate normals matrix
00123 
00124                 FLOAT lightVec[4] = { 0.5882f, 0.1961f, 0.2843f, 0.0f };
00125                 AS.pDevice->SetVertexShaderConstant( 8, &lightVec, 1 );
00126 
00127                 FLOAT t = 0.4f;
00128                 FLOAT ambient[4] = { t,t,t,0.0f };
00129                 AS.pDevice->SetVertexShaderConstant( 9, &ambient, 1 );
00130 
00131                 // strip color
00132                 AS.pDevice->SetPixelShaderConstant( 0, &e.stripColor, 1 );
00133 
00134                 // set texture & bumpmap
00135                 device_setTexture( 0, AS.res_textures[e.texture] );
00136                 if(e.bumpmap!=NULL)  device_setTexture( 0, AS.res_textures[e.bumpmap] );
00137 
00138                 // let the hardware render
00139                 AS.pDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, m.VBmin, m.VBcount, m.IBstart, m.TriCount );
00140         }       
00141 }

void mesh_render const AMesh    mesh,
const Vec3D    pos,
const Vec3D    size,
const Vec3D    dir,
const ATexture    texture,
const ATexture    bumpmap,
const Vec3D    stripColor
 

Definition at line 69 of file AMesh.cpp.

Referenced by Jet::draw(), Artillery::draw(), RocketLauncher::draw(), HeavyTank::draw(), LightTank::draw(), City::draw(), MilitaryUnit::drawBox(), City::drawSelectBox(), Overhead::overheadRender(), BattleJets::render(), BattleGroup::render(), BattleEntry::renderBullets(), BattleEntry::renderDebris(), and BattleEntry::renderEnvironment().

00071 {
00072         AS.mesh_renderList.push_back( MeshRenderRequestEntry(mesh,pos,size,dir,
00073                                                                                                                  texture,bumpmap,stripColor) ); 
00074 }


Generated on Wed Apr 23 05:50:30 2003 for Modern Warfare by doxygen1.3-rc2