1 | #include "dxstdafx.h"
|
---|
2 | #include "d3ddefs.h"
|
---|
3 | #include <cstdio>
|
---|
4 | #include <ctime>
|
---|
5 | #include <ostream>
|
---|
6 | #include <cstdlib>
|
---|
7 | #include <cmath>
|
---|
8 | #include <vector>
|
---|
9 | #include "vector4d.h"
|
---|
10 | #include "color.h"
|
---|
11 | #include "object.h"
|
---|
12 | #include "ObjectVector.h"
|
---|
13 |
|
---|
14 | ObjectVector::ObjectVector(){
|
---|
15 | offsetSum=1;
|
---|
16 | }
|
---|
17 |
|
---|
18 | ObjectVector::~ObjectVector(){
|
---|
19 | vector <ObjectModel*>::iterator iter;
|
---|
20 | for(iter=models.begin();iter!=models.end();iter++){
|
---|
21 | SAFE_DELETE(*iter);
|
---|
22 | }
|
---|
23 | models.clear();
|
---|
24 | }
|
---|
25 |
|
---|
26 | ObjectModel* ObjectVector::getObjectModel(UINT modelNum){
|
---|
27 | return (models.at(modelNum));
|
---|
28 | }
|
---|
29 |
|
---|
30 | void ObjectVector::resetAllObjects(LPDIRECT3DDEVICE9 device){
|
---|
31 | vector <ObjectModel*>::iterator iter;
|
---|
32 | for(iter=models.begin();iter!=models.end();iter++){
|
---|
33 | (*iter)->resetDeviceObjects(device);
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | void ObjectVector::initAllObjects(LPDIRECT3DDEVICE9 device){
|
---|
38 | vector <ObjectModel*>::iterator iter;
|
---|
39 | for(iter=models.begin();iter!=models.end();iter++){
|
---|
40 | (*iter)->initDeviceObjects(device);
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | HRESULT ObjectVector::RenderAllWithFX(LPD3DXEFFECT m_pEffect,bool renderToAtlas,D3DXMATRIX modelview,D3DXMATRIX modelviewproj){
|
---|
45 | HRESULT hr;
|
---|
46 | vector <ObjectModel*>::iterator iter;
|
---|
47 | for(iter=models.begin();iter!=models.end();iter++){
|
---|
48 | V_RETURN((*iter)->RenderWithFX(m_pEffect,renderToAtlas,modelview,modelviewproj))
|
---|
49 | }
|
---|
50 | return S_OK;
|
---|
51 | }
|
---|
52 |
|
---|
53 | void ObjectVector::getTriangleByIndex(UINT shooterIndex,Triangle& tri,Vector& vertex1,Vector& vertex2,Vector& vertex3,Vector& texcoord1,Vector& texcoord2,Vector& texcoord3){
|
---|
54 | UINT shooterSum=1;
|
---|
55 | if(models.size()<1){
|
---|
56 | return;
|
---|
57 | }
|
---|
58 | vector <ObjectModel*>::iterator iter;
|
---|
59 | for(iter=models.begin();iter!=models.end();iter++){
|
---|
60 | if(shooterIndex<shooterSum+(*iter)->ntriangles){
|
---|
61 | assert(shooterIndex-shooterSum<(*iter)->ntriangles);
|
---|
62 | int index=shooterIndex-shooterSum;
|
---|
63 | tri=(*iter)->triangles[index];
|
---|
64 | vertex1=(*iter)->vertices[tri.v[0]];
|
---|
65 | vertex2=(*iter)->vertices[tri.v[1]];
|
---|
66 | vertex3=(*iter)->vertices[tri.v[2]];
|
---|
67 | texcoord1=(*iter)->texcoords[tri.t[0]];
|
---|
68 | texcoord2=(*iter)->texcoords[tri.t[1]];
|
---|
69 | texcoord3=(*iter)->texcoords[tri.t[2]];
|
---|
70 | return;
|
---|
71 | }
|
---|
72 | else{
|
---|
73 | shooterSum+=(*iter)->ntriangles;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | vector<ObjectModel*> ObjectVector::getAllObjectModels(){
|
---|
79 | return this->models;
|
---|
80 | }
|
---|
81 |
|
---|
82 | void ObjectVector::addObjectModel(ObjectModel& objectModel){
|
---|
83 | objectModel.setOffset(offsetSum);
|
---|
84 | offsetSum+=objectModel.ntriangles;
|
---|
85 | models.push_back(&objectModel);
|
---|
86 | }
|
---|
87 |
|
---|
88 | bool ObjectVector::createAllD3DVertices(){
|
---|
89 | vector <ObjectModel*>::iterator iter;
|
---|
90 | for(iter=models.begin();iter!=models.end();iter++){
|
---|
91 | if((*iter)->isLoaded()){
|
---|
92 | (*iter)->CreateD3DVertices();
|
---|
93 | }
|
---|
94 | else{
|
---|
95 | return false;
|
---|
96 | }
|
---|
97 | }
|
---|
98 | return true;
|
---|
99 | }
|
---|
100 |
|
---|
101 | void ObjectVector::removeObjectModel(UINT modelNum){
|
---|
102 | vector <ObjectModel*>::iterator iter;
|
---|
103 | int number=1;
|
---|
104 | bool found=false;
|
---|
105 | offsetSum=1;
|
---|
106 | for(iter=models.begin();iter!=models.end();iter++){
|
---|
107 | if(number==modelNum){
|
---|
108 | models.erase(iter);
|
---|
109 | found=true;
|
---|
110 | }
|
---|
111 | else{
|
---|
112 | number++;
|
---|
113 | (*iter)->setOffset(offsetSum);
|
---|
114 | offsetSum+=(*iter)->ntriangles;
|
---|
115 | if(found){
|
---|
116 | (*iter)->CreateD3DVertices();
|
---|
117 | }
|
---|
118 | }
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | void ObjectVector::removeAllObjectModels(){
|
---|
123 | models.clear();
|
---|
124 | }
|
---|