-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShapes.cpp
More file actions
80 lines (63 loc) · 2.31 KB
/
Shapes.cpp
File metadata and controls
80 lines (63 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "Shapes.h"
#include <stdio.h>
#include <vector>
#include <Resources/IModelResource.h>
#include <Resources/ResourceManager.h>
#include <Scene/GeometryNode.h>
#include <Geometry/Face.h>
#include <cufft.h>
#include <cutil.h>
#include <driver_types.h> // includes cudaError_t
#include <cuda_gl_interop.h>
#include <cuda_runtime_api.h> // includes cudaMalloc and cudaMemset
using namespace OpenEngine::Geometry;
using namespace OpenEngine::Scene;
using namespace OpenEngine::Resources;
PolyShape::PolyShape(std::string name, float scaleX, float scaleY, float scaleZ) {
// Load the model
IModelResourcePtr mod_res = ResourceManager<IModelResource>::Create(name);
mod_res->Load();
if (mod_res->GetSceneNode() == NULL)
logger.info << "Error loading model" << logger.end;
GeometryNode* geo_node = (GeometryNode*)mod_res->GetSceneNode();
mod_res->Unload();
FaceSet* face_set = geo_node->GetFaceSet();
vector<float4> vList; //Vertices
vector<float4> nList; //Normals
FaceList::iterator itr;
for( itr = face_set->begin(); itr!=face_set->end(); itr++ ) {
FacePtr face = *itr;
for( int i=0; i<3; i++){
float4 v = { face->vert[i][0],
face->vert[i][1],
face->vert[i][2],
1.0};
float4 n = { face->norm[i][0],
face->norm[i][1],
face->norm[i][2],
1.0};
// Scale model
v.x *= scaleX;
v.y *= scaleY;
v.z *= scaleZ;
v.w = 1.0f;
vList.push_back(v);
nList.push_back(n);
}
}
// Copy vertices into static buffer
vertices = new float4[vList.size()];
normals = new float4[nList.size()];
numVertices=0;
std::vector<float4>::iterator it;
for( it=vList.begin(); it!=vList.end(); it++ ) {
//printf("[%i] %f %f %f\n", numVertices,(*it).x, (*it).y, (*it).z);
vertices[numVertices++] = *it;
}
numNormals=0;
for( it=nList.begin(); it!=nList.end(); it++ ) {
//printf("[%i] %f %f %f\n", numVertices,(*it).x, (*it).y, (*it).z);
normals[numNormals++] = *it;
}
printf("[PolyShape] numVertices loaded: %i - numNormals: %i\n", numVertices, numNormals);
}