Skip to content

Commit

Permalink
you can set mesh postion and scale
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleTheFu committed Oct 3, 2024
1 parent 9b251fc commit 687d06a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
9 changes: 3 additions & 6 deletions geometry/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
#include <assimp/postprocess.h> // Post processing flags
#include <cassert>

Mesh::Mesh(const std::string fileName, Material *pMtrl)
Mesh::Mesh(const std::string fileName, const Vector3 pos, float scale, Material *pMtrl)
{
assert(scale > 0);

std::cout << "starting importer..." << std::endl;
Assimp::Importer importer;
std::cout << "starting importer...1" << std::endl;
Expand All @@ -18,18 +20,14 @@ Mesh::Mesh(const std::string fileName, Material *pMtrl)
aiFace face = scene->mMeshes[0]->mFaces[i];
assert(face.mNumIndices == 3);

int scale = 300;

float x_a = scene->mMeshes[0]->mVertices[face.mIndices[0]].x;
float y_a = scene->mMeshes[0]->mVertices[face.mIndices[0]].y;
float z_a = scene->mMeshes[0]->mVertices[face.mIndices[0]].z;


float x_b = scene->mMeshes[0]->mVertices[face.mIndices[1]].x;
float y_b = scene->mMeshes[0]->mVertices[face.mIndices[1]].y;
float z_b = scene->mMeshes[0]->mVertices[face.mIndices[1]].z;


float x_c = scene->mMeshes[0]->mVertices[face.mIndices[2]].x;
float y_c = scene->mMeshes[0]->mVertices[face.mIndices[2]].y;
float z_c = scene->mMeshes[0]->mVertices[face.mIndices[2]].z;
Expand All @@ -38,7 +36,6 @@ Mesh::Mesh(const std::string fileName, Material *pMtrl)
TriVertex vb(x_b * scale, y_b * scale, z_b * scale);
TriVertex vc(x_c * scale, y_c * scale, z_c * scale);

Vector3 pos(20,20,350);
Tri *tri = new Tri(va, vb, vc, pos, pMtrl);

m_tris.push_back(tri);
Expand Down
2 changes: 1 addition & 1 deletion geometry/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Mesh : public Geometry
{
public:
Mesh(const std::string fileName, Material *pMtrl);
Mesh(const std::string fileName, const Vector3 pos, float scale, Material *pMtrl);

virtual bool hit(const Ray &ray, HitRecord &record, Light *pLight) const override;

Expand Down
20 changes: 15 additions & 5 deletions scene/sceneBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ void SceneBuilder::build()
buildRoom();
buildLight();

buildMirrorBall();
buildRedBall();
buildMixBall();
// buildMirrorBall();
// buildRedBall();
// buildMixBall();
buildBunny();
}

void SceneBuilder::createMaterials()
Expand Down Expand Up @@ -108,7 +109,7 @@ void SceneBuilder::buildLight()

void SceneBuilder::buildSceneWithDefaultConfig()
{
Mesh *bunny = new Mesh(Common::LOW_BUNNY, lambMtrlAqua);
Mesh *bunny = new Mesh(Common::LOW_BUNNY, Vector3::ZERO, 300, lambMtrlAqua);

TriVertex v_a(0, 0, 50);
TriVertex v_b(50, 0, 0);
Expand Down Expand Up @@ -174,4 +175,13 @@ void SceneBuilder::buildMixBall()
{
Ball *mixBall = new Ball(Vector3::ZERO, Vector3(-28, 72, 350), 20, MtrlMix);
m_pObjectPool->add(mixBall);
}
}

void SceneBuilder::buildBunny()
{
Vector3 pos(60, 60, 350);
float scale = 300;

Mesh *bunny = new Mesh(Common::LOW_LOW_BUNNY, pos, scale, lambMtrlAqua);
bunny->addToPool(m_pObjectPool);
}
2 changes: 2 additions & 0 deletions scene/sceneBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class SceneBuilder
void buildRedBall();
void buildMixBall();

void buildBunny();

private:
ObjectPool* m_pObjectPool;

Expand Down

0 comments on commit 687d06a

Please sign in to comment.