Class Object

This commit is contained in:
xkamikoo 2021-02-23 19:36:37 +01:00
parent 8d2f13843e
commit 1b2815b668
6 changed files with 312 additions and 192 deletions

View File

@ -32,6 +32,7 @@
<ClCompile Include="src\Box.cpp" /> <ClCompile Include="src\Box.cpp" />
<ClCompile Include="src\Camera.cpp" /> <ClCompile Include="src\Camera.cpp" />
<ClCompile Include="src\main.cpp" /> <ClCompile Include="src\main.cpp" />
<ClCompile Include="src\Object.cpp" />
<ClCompile Include="src\Physics.cpp" /> <ClCompile Include="src\Physics.cpp" />
<ClCompile Include="src\picopng.cpp" /> <ClCompile Include="src\picopng.cpp" />
<ClCompile Include="src\Render_Utils.cpp" /> <ClCompile Include="src\Render_Utils.cpp" />
@ -39,10 +40,12 @@
<ClCompile Include="src\Texture.cpp" /> <ClCompile Include="src\Texture.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Object.h" />
<ClInclude Include="Skybox.h" /> <ClInclude Include="Skybox.h" />
<ClInclude Include="src\Camera.h" /> <ClInclude Include="src\Camera.h" />
<ClInclude Include="src\mesh.h" /> <ClInclude Include="src\mesh.h" />
<ClInclude Include="src\model.h" /> <ClInclude Include="src\model.h" />
<ClInclude Include="src\Object.h" />
<ClInclude Include="src\objload.h" /> <ClInclude Include="src\objload.h" />
<ClInclude Include="src\Physics.h" /> <ClInclude Include="src\Physics.h" />
<ClInclude Include="src\picopng.h" /> <ClInclude Include="src\picopng.h" />

View File

@ -92,6 +92,9 @@
<ClCompile Include="src\Physics.cpp"> <ClCompile Include="src\Physics.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\Object.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\stb_image.h"> <ClInclude Include="src\stb_image.h">
@ -127,5 +130,11 @@
<ClInclude Include="src\Physics.h"> <ClInclude Include="src\Physics.h">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Object.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\Object.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

137
src/Object.cpp Normal file
View File

@ -0,0 +1,137 @@
#include "Object.h"
void Object::Draw(glm::mat4 perspectiveMatrix, glm::mat4 cameraMatrix)
{
glUseProgram(shaderID);
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelM;
glUniformMatrix4fv(glGetUniformLocation(shaderID, "modelMatrix"), 1, GL_FALSE, (float*)&modelM);
glUniformMatrix4fv(glGetUniformLocation(shaderID, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniform3f(glGetUniformLocation(shaderID, "objectColor"), color.r, color.g, color.b);
if (textureID != -1)
Core::SetActiveTexture(textureID, "diffuseTexture", shaderID, 0);
modelParent->Draw(shaderID);
glUseProgram(0);
}
void Object::ChangePosition(glm::vec3 movement)
{
modelM = glm::translate(modelM, movement);
this->position += movement;
}
void Object::SetPosition(glm::vec3 position)
{
this->position = position;
SetMatrix();
}
void Object::ChangeScale(glm::vec3 scale)
{
modelM = glm::scale(modelM, scale);
this->scale += scale;
}
void Object::SetScale(glm::vec3 scale)
{
this->scale = scale;
SetMatrix();
}
void Object::ChangeRotation(glm::vec3 rotate, float angle)
{
modelM = glm::rotate(modelM, angle, rotate);
this->rotation += rotate;
this->angle += angle;
}
void Object::SetRotation(glm::vec3 rotate, float angle)
{
this->rotation = rotate;
this->angle = angle;
SetMatrix();
}
void Object::SetMatrix()
{
modelM = glm::translate(glm::mat4(1.0f), position);
modelM = glm::rotate(modelM, angle, rotation);
modelM = glm::scale(modelM, scale);
invModelM = glm::inverseTranspose(modelM);
}
void Object::SetMatrix(glm::vec3 position, glm::vec3 scale, glm::vec3 rotate, float angle)
{
this->position = position;
this->rotation = rotate;
this->scale = scale;
this->angle = angle;
SetMatrix();
}
Object::Object( std::string name,
std::shared_ptr<Model> modelParent,
GLuint textureID,
GLuint shaderID,
glm::vec3 color,
glm::vec3 position,
glm::vec3 rotation,
glm::vec3 scale,
float angle,
bool dynamic)
{
this->name = name;
SetMatrix(position, scale, rotation, angle);
this->modelParent = modelParent;
this->textureID = textureID;
this->shaderID = shaderID;
this->color = color;
this->dynamic = dynamic;
}
Object::Object( std::string name,
std::shared_ptr<Model> modelParent,
GLuint shaderID,
glm::vec3 color,
glm::vec3 position,
glm::vec3 rotation,
glm::vec3 scale,
float angle,
bool dynamic)
{
this->name = name;
SetMatrix(position, scale, rotation, angle);
this->textureID = -1;
this->modelParent = modelParent;
this->shaderID = shaderID;
this->color = color;
this->dynamic = dynamic;
}
glm::vec3 Object::getScaleFromMatrix(glm::mat4 modelMatrix)
{
float x = glm::length(glm::vec3(modelMatrix[0][0], modelMatrix[1][0], modelMatrix[2][0]));
float y = glm::length(glm::vec3(modelMatrix[0][1], modelMatrix[1][1], modelMatrix[2][1]));
float z = glm::length(glm::vec3(modelMatrix[0][2], modelMatrix[1][2], modelMatrix[2][2]));
return glm::vec3(x, y, z);
}
glm::vec3 Object::getPositionFromMatrix(glm::mat4 modelMatrix)
{
return glm::vec3(modelMatrix[3][0], modelMatrix[3][1], modelMatrix[3][2]);
}
glm::vec3 Object::findOrbit(float time, glm::vec3 center, glm::vec3 orbit, glm::vec3 radius)
{
glm::mat4 planetModelMatrix = glm::mat4(1.0f);
planetModelMatrix = glm::translate(planetModelMatrix, center);
planetModelMatrix = glm::rotate(planetModelMatrix, time, orbit);
planetModelMatrix = glm::translate(planetModelMatrix, radius);
return getPositionFromMatrix(planetModelMatrix);
}

86
src/Object.h Normal file
View File

@ -0,0 +1,86 @@
#pragma once
#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include "glew.h"
#include "freeglut.h"
#include "glm.hpp"
#include "ext.hpp"
#include "model.h"
#include "Texture.h"
class Object
{
public:
void Draw(glm::mat4 perspectiveMatrix, glm::mat4 cameraMatrix);
void ChangePosition(glm::vec3 movement);
void SetPosition(glm::vec3 position);
void ChangeScale(glm::vec3 scale);
void SetScale(glm::vec3 scale);
void ChangeRotation(glm::vec3 rotate, float angle);
void SetRotation(glm::vec3 rotate, float angle);
void SetMatrix(glm::vec3 position, glm::vec3 scale, glm::vec3 rotate, float angle);
void SetMatrix(glm::mat4 _mat) { this->modelM = _mat; }
std::string GetName() { return this->name; }
glm::mat4 GetMatrix() { return this->modelM; }
glm::mat4 GetInvMatrix() { return this->invModelM; }
glm::vec3 GetColor() { return this->color; }
glm::vec3 GetPosition() { return position; }
glm::vec3 GetScale() { return scale; }
bool isDynamic() { return dynamic; }
std::shared_ptr<Model> GetParent() { return modelParent; }
Object( std::string name,
std::shared_ptr<Model> modelParent,
GLuint textureID,
GLuint shaderID,
glm::vec3 color,
glm::vec3 position,
glm::vec3 rotation,
glm::vec3 scale,
float angle,
bool dynamic);
Object(std::string name,
std::shared_ptr<Model> modelParent,
GLuint shaderID,
glm::vec3 color,
glm::vec3 position,
glm::vec3 rotation,
glm::vec3 scale,
float angle,
bool dynamic);
glm::vec3 getScaleFromMatrix(glm::mat4 modelMatrix);
glm::vec3 getPositionFromMatrix(glm::mat4 modelMatrix);
glm::vec3 findOrbit(float time, glm::vec3 center, glm::vec3 orbit, glm::vec3 radius);
private:
void SetMatrix();
std::shared_ptr<Model> modelParent;
std::string name;
glm::mat4 modelM;
glm::mat4 invModelM;
GLuint textureID;
GLuint shaderID;
glm::vec3 color;
glm::vec3 position;
glm::vec3 rotation;
glm::vec3 scale;
float angle;
bool dynamic;
};

View File

@ -14,8 +14,11 @@
#include "Shader_Loader.h" #include "Shader_Loader.h"
#include "Camera.h" #include "Camera.h"
#include "Texture.h" #include "Texture.h"
#include "Object.h"
#include "model.h" #include "model.h"
#include <WinUser.h> #include <WinUser.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
static PxFilterFlags simulationFilterShader(PxFilterObjectAttributes attributes0, static PxFilterFlags simulationFilterShader(PxFilterObjectAttributes attributes0,
PxFilterData filterData0, PxFilterObjectAttributes attributes1, PxFilterData filterData1, PxFilterData filterData0, PxFilterObjectAttributes attributes1, PxFilterData filterData1,
@ -81,12 +84,8 @@ Physics pxScene(0.0 /* gravity (m/s^2) */, simulationFilterShader,
const double physicsStepTime = 1.f / 60.f; const double physicsStepTime = 1.f / 60.f;
double physicsTimeToProcess = 0; double physicsTimeToProcess = 0;
int SCR_WIDTH = 1240; int SCR_WIDTH = 1240;
int SCR_HEIGHT = 720; int SCR_HEIGHT = 720;
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
int winId; int winId;
Core::Shader_Loader shaderLoader; Core::Shader_Loader shaderLoader;
@ -195,18 +194,6 @@ int FindUnusedParticle() {
return 0; // All particles are taken, override the first one return 0; // All particles are taken, override the first one
} }
struct Object
{
std::string name;
glm::mat4 modelM;
glm::mat4 invModelM;
std::shared_ptr<Model> modelParent;
GLuint textureID;
GLuint shaderID;
glm::vec3 color;
bool isDynamic;
};
//Light //Light
struct Light { struct Light {
glm::vec3 position; glm::vec3 position;
@ -372,54 +359,6 @@ glm::mat4 createCameraMatrix()
return Core::createViewMatrix(cameraPos, cameraDir, up); return Core::createViewMatrix(cameraPos, cameraDir, up);
} }
//funkcja rysujaca modele za pomoca assimpa
void drawFromAssimpModel(GLuint program, std::shared_ptr<Model> model, glm::mat4 modelMatrix)
{
glUseProgram(program);
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
model->Draw(program);
glUseProgram(0);
}
//funkcja rysujaca modele, ktore nie maja wlasnej tekstury za pomoca assimpa
void drawFromAssimpTexture(GLuint program, std::shared_ptr<Model> model, glm::mat4 modelMatrix, GLuint texID)
{
glUseProgram(program);
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
Core::SetActiveTexture(texID, "diffuseTexture", program, 0);
model->Draw(program);
glUseProgram(0);
}
void drawObject(Object & obj)
{
glUseProgram(obj.shaderID);
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * obj.modelM;
glUniformMatrix4fv(glGetUniformLocation(obj.shaderID, "modelMatrix"), 1, GL_FALSE, (float*)&obj.modelM);
glUniformMatrix4fv(glGetUniformLocation(obj.shaderID, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniform3f(glGetUniformLocation(obj.shaderID, "objectColor"), obj.color.r, obj.color.g, obj.color.b);
if (obj.textureID != -1)
Core::SetActiveTexture(obj.textureID, "diffuseTexture", obj.shaderID, 0);
obj.modelParent->Draw(obj.shaderID);
glUseProgram(0);
}
void drawAsteroids() void drawAsteroids()
{ {
glUseProgram(programAsteroid); glUseProgram(programAsteroid);
@ -593,7 +532,7 @@ Object* findObject(std::string name)
{ {
for (int i = 0; i < objects.size(); i++) for (int i = 0; i < objects.size(); i++)
{ {
if (objects[i].name == name) if (objects[i].GetName() == name)
return &objects[i]; return &objects[i];
} }
return nullptr; return nullptr;
@ -601,11 +540,9 @@ Object* findObject(std::string name)
physx::PxRigidDynamic* getActor(std::string name) physx::PxRigidDynamic* getActor(std::string name)
{ {
cout << "meh " << name << std::endl;
for (int i = 0; i < dynamicObjects.size(); i++) for (int i = 0; i < dynamicObjects.size(); i++)
{ {
cout << ((Object*)dynamicObjects[i]->userData)->name << std::endl <<std::flush; if (((Object*)dynamicObjects[i]->userData)->GetName() == name)
if (((Object*)dynamicObjects[i]->userData)->name == name)
return dynamicObjects[i]; return dynamicObjects[i];
} }
return nullptr; return nullptr;
@ -615,10 +552,9 @@ void updateObjects()
{ {
Object* obj = findObject("Corvette"); Object* obj = findObject("Corvette");
glm::mat4 shipModelMatrix = obj->modelM; glm::mat4 shipModelMatrix = obj->GetMatrix();
//glm::translate(cameraPos + cameraDir * 0.7f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0001f)); //glm::translate(cameraPos + cameraDir * 0.7f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0001f));
//obj->modelM = shipModelMatrix; //obj->modelM = shipModelMatrix;
obj->invModelM = glm::inverse(obj->modelM);
//glm::mat4 offset = glm::translate(shipModelMatrix, glm::vec3(0, 0, 1000)); //glm::mat4 offset = glm::translate(shipModelMatrix, glm::vec3(0, 0, 1000));
//cameraPos = glm::vec3(offset[3][0], offset[3][1], offset[3][2]); //cameraPos = glm::vec3(offset[3][0], offset[3][1], offset[3][2]);
@ -633,25 +569,31 @@ void updateObjects()
obj->modelM = crewmateModelMatrix; obj->modelM = crewmateModelMatrix;
obj->invModelM = glm::inverse(crewmateModelMatrix); obj->invModelM = glm::inverse(crewmateModelMatrix);
*/ */
//earth & moon //earth & moon
glm::mat4 earthModelMatrix = drawPlanet(lastTime / 5.0f, sunPos*glm::vec3(1.5f, 1, 1), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(-10.5f, 0.0f, -10.5f), glm::vec3(0.5f, 0.5f, 0.5f)); //glm::mat4 earthModelMatrix = drawPlanet(lastTime / 5.0f, sunPos*glm::vec3(1.5f, 1, 1), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(-10.5f, 0.0f, -10.5f), glm::vec3(0.5f, 0.5f, 0.5f));
glm::mat4 moonModelMatrix = drawMoon(earthModelMatrix, lastTime / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0, 2, 2), glm::vec3(1.5f, 1.0f, 1.0f), glm::vec3(0.3f, 0.3f, 0.3f)); //glm::mat4 moonModelMatrix = drawMoon(earthModelMatrix, lastTime / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0, 2, 2), glm::vec3(1.5f, 1.0f, 1.0f), glm::vec3(0.3f, 0.3f, 0.3f));
earthModelMatrix = glm::rotate(earthModelMatrix, lastTime / 5.0f, glm::vec3(0.0f, 0.0f, 0.1f)); //earthModelMatrix = glm::rotate(earthModelMatrix, lastTime / 5.0f, glm::vec3(0.0f, 0.0f, 0.1f));
obj = findObject("Moon"); Object *moon = findObject("Moon");
obj->modelM = moonModelMatrix; Object *earth = findObject("Earth");
obj->invModelM = glm::inverse(moonModelMatrix);
obj = findObject("Earth"); //auto earthPos = glm::vec3(-10.5f, 0.0f, -10.5f);
obj->modelM = earthModelMatrix; auto earthPos = earth->findOrbit(lastTime / 5.0f, sunPos, glm::vec3(0, 1, 0), glm::vec3(-10.5f, 0.0f, -10.5f));
obj->invModelM = glm::inverse(earthModelMatrix); earth->SetPosition(earthPos);
earth->SetRotation(glm::vec3(0, 0, 1), lastTime);
obj = findObject("Mars"); auto moonPos = moon->findOrbit(lastTime, earthPos, glm::vec3(1,0,0), glm::vec3(0, 1.5, 0));
moon->SetPosition(moonPos);
moon->SetRotation(glm::vec3(1, 0, 0), lastTime / 5.0f);
Object *mars = findObject("Mars");
glm::mat4 marsModelMatrix = drawPlanet(lastTime / 5.0f, sunPos2, glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(-6.5f, 0.0f, -6.5f), glm::vec3(0.4f, 0.4f, 0.4f)); glm::mat4 marsModelMatrix = drawPlanet(lastTime / 5.0f, sunPos2, glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(-6.5f, 0.0f, -6.5f), glm::vec3(0.4f, 0.4f, 0.4f));
marsModelMatrix = glm::rotate(marsModelMatrix, lastTime / 3.0f, glm::vec3(0.0f, 0.0f, 1.0f)); marsModelMatrix = glm::rotate(marsModelMatrix, lastTime / 3.0f, glm::vec3(0.0f, 0.0f, 1.0f));
obj->modelM = marsModelMatrix;
obj->invModelM = glm::inverse(marsModelMatrix); auto marsPos = mars->findOrbit(lastTime / 5.0f, sunPos2, glm::vec3(0, 1, 0), glm::vec3(-6.5f, 0.0f, -6.5f));
mars->SetPosition(marsPos);
mars->SetRotation(glm::vec3(0, 0, 1), lastTime / 2.0f);
} }
void updatePhysics() void updatePhysics()
@ -677,7 +619,7 @@ void updatePhysics()
auto &c3 = transform.column3; auto &c3 = transform.column3;
// set up the model matrix used for the rendering // set up the model matrix used for the rendering
obj->modelM = glm::mat4( obj->GetMatrix() = glm::mat4(
c0.x, c0.y, c0.z, c0.w, c0.x, c0.y, c0.z, c0.w,
c1.x, c1.y, c1.z, c1.w, c1.x, c1.y, c1.z, c1.w,
c2.x, c2.y, c2.z, c2.w, c2.x, c2.y, c2.z, c2.w,
@ -737,8 +679,11 @@ void renderScene()
updatePhysics(); updatePhysics();
updateObjects(); updateObjects();
//for (Object & obj : objects)
// drawObject(obj);
for (Object &obj : objects) for (Object &obj : objects)
drawObject(obj); obj.Draw(perspectiveMatrix, cameraMatrix);
//asteroidpart //asteroidpart
glUseProgram(programAsteroid); glUseProgram(programAsteroid);
@ -849,20 +794,6 @@ void renderScene()
glutSwapBuffers(); glutSwapBuffers();
} }
glm::vec3 getScale(glm::mat4 modelMatrix)
{
float x = glm::length(glm::vec3(modelMatrix[0][0], modelMatrix[1][0], modelMatrix[2][0]));
float y = glm::length(glm::vec3(modelMatrix[0][1], modelMatrix[1][1], modelMatrix[2][1]));
float z = glm::length(glm::vec3(modelMatrix[0][2], modelMatrix[1][2], modelMatrix[2][2]));
return glm::vec3(x, y, z);
}
glm::vec3 getPosition(glm::mat4 modelMatrix)
{
return glm::vec3(modelMatrix[3][0], modelMatrix[3][1], modelMatrix[3][2]);
}
physx::PxMat44 transformMat(glm::mat4 mat) physx::PxMat44 transformMat(glm::mat4 mat)
{ {
float newMat[16] = {mat[0][0], mat[0][1], mat[0][2], mat[0][3], float newMat[16] = {mat[0][0], mat[0][1], mat[0][2], mat[0][3],
@ -873,6 +804,17 @@ physx::PxMat44 transformMat(glm::mat4 mat)
return PxMat44(newMat); return PxMat44(newMat);
} }
void compareMat(physx::PxMat44 mat1, glm::mat4 mat2)
{
for (int i = 0; i <= 3; i++)
{
for (int j = 0; j <= 3; j++)
{
cout << mat1[i][j] << " " << mat2[i][j] << std::endl;
}
}
}
void initPhysics() void initPhysics()
{ {
material = pxScene.physics->createMaterial(0.5, 0.5, 0.5); material = pxScene.physics->createMaterial(0.5, 0.5, 0.5);
@ -881,11 +823,13 @@ void initPhysics()
for (auto &obj : objects) for (auto &obj : objects)
{ {
if (obj.isDynamic == true) if (obj.isDynamic() == true)
{ {
glm::vec3 pos = getPosition(obj.modelM); glm::vec3 pos = obj.getPositionFromMatrix(obj.GetMatrix());
dynamicObjects.emplace_back(pxScene.physics->createRigidDynamic(PxTransform(pos.x, pos.y, pos.z))); dynamicObjects.emplace_back(pxScene.physics->createRigidDynamic(PxTransform(pos.x, pos.y, pos.z)));
dynamicObjects.back()->setGlobalPose(PxTransform(transformMat(obj.modelM))); auto trans2 = transformMat(obj.GetMatrix());
auto trans = PxTransform(trans2);
dynamicObjects.back()->setGlobalPose(trans);
dynamicObjects.back()->attachShape(*rectangleShape); dynamicObjects.back()->attachShape(*rectangleShape);
dynamicObjects.back()->userData = &obj; dynamicObjects.back()->userData = &obj;
dynamicObjects.back()->setLinearVelocity(physx::PxVec3(0, 0, 0)); dynamicObjects.back()->setLinearVelocity(physx::PxVec3(0, 0, 0));
@ -894,9 +838,9 @@ void initPhysics()
} }
else else
{ {
glm::vec3 pos = getPosition(obj.modelM); glm::vec3 pos = obj.getPositionFromMatrix(obj.GetMatrix());
staticObjects.emplace_back(pxScene.physics->createRigidStatic(PxTransform(pos.x, pos.y, pos.z))); staticObjects.emplace_back(pxScene.physics->createRigidStatic(PxTransform(pos.x, pos.y, pos.z)));
staticObjects.back()->setGlobalPose(PxTransform(transformMat(obj.modelM))); staticObjects.back()->setGlobalPose(PxTransform(transformMat(obj.GetMatrix())));
staticObjects.back()->attachShape(*sphereShape); staticObjects.back()->attachShape(*sphereShape);
staticObjects.back()->userData = &obj; staticObjects.back()->userData = &obj;
pxScene.scene->addActor(*staticObjects.back()); pxScene.scene->addActor(*staticObjects.back());
@ -1027,88 +971,33 @@ void initBloom()
void initObjects() void initObjects()
{ {
Object obj; Object obj = Object("BigSun", sphere, sunTexture, programSun, glm::vec3(3.5f, 3.8f, 3.8f),
glm::mat4 sunModelMatrix = glm::mat4(1.0f); sunPos, glm::vec3(0.1f), glm::vec3(3.0f, 3.0f, 3.0f), 0.0f, false);
sunModelMatrix = glm::translate(sunModelMatrix, sunPos);
sunModelMatrix = glm::scale(sunModelMatrix, glm::vec3(3.0f, 3.0f, 3.0f));
obj.name = "BigSun";
obj.modelM = sunModelMatrix;
obj.invModelM = glm::inverse(sunModelMatrix);
obj.modelParent = sphere;
obj.textureID = sunTexture;
obj.shaderID = programSun;
obj.color = glm::vec3(3.5f, 3.8f, 3.8f);
obj.isDynamic = false;
objects.push_back(obj); objects.push_back(obj);
glm::mat4 sunModelMatrix2 = glm::mat4(1.0f); obj = Object("SmollSun", sphere, sunTexture, programSun, glm::vec3(0.9f, 0.9f, 2.0f),
sunModelMatrix2 = glm::translate(sunModelMatrix2, sunPos2); sunPos2, glm::vec3(0.1f), glm::vec3(1), 0, false);
obj.name = "SmollSun";
obj.modelM = sunModelMatrix2;
obj.invModelM = glm::inverse(sunModelMatrix2);
obj.color = glm::vec3(0.9f, 0.9f, 2.0f);
obj.isDynamic = false;
objects.push_back(obj); objects.push_back(obj);
glm::mat4 earthModelMatrix; Object planet = Object("Earth", sphere, earthTexture, programTex, glm::vec3(1.0f),
glm::mat4 moonModelMatrix; glm::vec3(-10.5f, 0.0f, -10.5f), glm::vec3(0.0f, 0.0f, 0.1f), glm::vec3(0.5f, 0.5f, 0.5f), 0, false);
Object planet;
planet.name = "Earth";
planet.modelM = earthModelMatrix;
planet.invModelM = glm::inverse(earthModelMatrix);
planet.modelParent = sphere;
planet.textureID = earthTexture;
planet.shaderID = programTex;
planet.color = glm::vec3(1.0f);
planet.isDynamic = false;
objects.push_back(planet); objects.push_back(planet);
glm::mat4 marsModelMatrix; planet = Object("Mars", sphere, marsTexture, programTex, glm::vec3(1.0f),
glm::vec3(-6.5f, 0.0f, -6.5f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.4f), 0, false);
planet.name = "Mars";
planet.modelM = marsModelMatrix;
planet.invModelM = glm::inverse(marsModelMatrix);
planet.modelParent = sphere;
planet.textureID = marsTexture;
planet.shaderID = programTex;
planet.color = glm::vec3(1.0f);
planet.isDynamic = false;
objects.push_back(planet); objects.push_back(planet);
Object moon; Object moon = Object("Moon", sphere, moonTexture, programTex, glm::vec3(1.0f),
moon.name = "Moon"; glm::vec3(0, 2, 2), glm::vec3(1.5f, 1.0f, 1.0f), glm::vec3(0.3f, 0.3f, 0.3f), 0, false);
moon.modelM = moonModelMatrix;
moon.invModelM = glm::inverse(moonModelMatrix);
moon.modelParent = sphere;
moon.textureID = moonTexture;
moon.shaderID = programTex;
moon.color = glm::vec3(1.0f);
moon.isDynamic = false;
objects.push_back(moon); objects.push_back(moon);
glm::mat4 crewmateModelMatrix = glm::translate(glm::vec3(0, 1, 1)) * glm::rotate(lastTime / 10, glm::vec3(1, 0, 1)) * glm::scale(glm::vec3(0.01)); Object crewmateObj = Object("Space Humster", crewmate, programNormal, glm::vec3(1.0f),
glm::vec3(0, 1, 1), glm::vec3(1, 0, 1), glm::vec3(0.01), 0, true);
Object crewmateObj;
crewmateObj.name = "Space Humster";
crewmateObj.modelM = crewmateModelMatrix;
crewmateObj.invModelM = glm::inverse(crewmateModelMatrix);
crewmateObj.modelParent = crewmate;
crewmateObj.shaderID = programNormal;
crewmateObj.color = glm::vec3(1.0f);
crewmateObj.isDynamic = true;
objects.push_back(crewmateObj); objects.push_back(crewmateObj);
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.7f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0001f));; //glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.7f + glm::vec3(0, -0.25f, 0)) * glm::rotate(-cameraAngle + glm::radians(90.0f), glm::vec3(0, 1, 0)) * glm::scale(glm::vec3(0.0001f));;
Object ship = Object("Corvette", corvette, programNormal, glm::vec3(1.0f),
Object ship; cameraPos+glm::vec3(0.6,-0.3,0), glm::vec3(0, 1, 0), glm::vec3(0.0001f), 75, true);
ship.name = "Corvette";
ship.modelM = shipModelMatrix;
ship.invModelM = glm::inverse(shipModelMatrix);
ship.modelParent = corvette;
ship.shaderID = programNormal;
ship.color = glm::vec3(1.0f);
ship.isDynamic = true;
objects.push_back(ship); objects.push_back(ship);
} }

View File

@ -1,31 +1,27 @@
#pragma once #pragma once
#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include "glew.h" #include "glew.h"
#include "freeglut.h" #include "freeglut.h"
#include "glm.hpp" #include "glm.hpp"
#include "ext.hpp" #include "ext.hpp"
#include <iostream>
#include <cmath>
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include "stb_image.h" #include "stb_image.h"
#include "mesh.h" #include "mesh.h"
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <map>
#include <vector>
using namespace std; using namespace std;
unsigned int TextureFromFile(const char* path, const string& directory, bool gamma = false); static unsigned int TextureFromFile(const char* path, const string& directory, bool gamma = false);
class Model class Model
{ {
@ -216,7 +212,7 @@ private:
}; };
unsigned int TextureFromFile(const char* path, const string& directory, bool gamma) static unsigned int TextureFromFile(const char* path, const string& directory, bool gamma)
{ {
string filename = string(path); string filename = string(path);
filename = directory + '/' + filename; filename = directory + '/' + filename;