Humster disappear s

This commit is contained in:
xkamikoo 2021-02-24 01:04:09 +01:00
parent 6a998252e9
commit 4cbbfea666
3 changed files with 28 additions and 51 deletions

View File

@ -2,6 +2,8 @@
void Object::Draw(glm::mat4 perspectiveMatrix, glm::mat4 cameraMatrix) void Object::Draw(glm::mat4 perspectiveMatrix, glm::mat4 cameraMatrix)
{ {
if (!exists) return;
glUseProgram(shaderID); glUseProgram(shaderID);
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelM; glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelM;

View File

@ -19,6 +19,7 @@ class Object
{ {
public: public:
void Draw(glm::mat4 perspectiveMatrix, glm::mat4 cameraMatrix); void Draw(glm::mat4 perspectiveMatrix, glm::mat4 cameraMatrix);
void ChangePosition(glm::vec3 movement); void ChangePosition(glm::vec3 movement);
void SetPosition(glm::vec3 position); void SetPosition(glm::vec3 position);
@ -44,36 +45,20 @@ public:
bool isKinematic() { return kinematic; } bool isKinematic() { return kinematic; }
std::shared_ptr<Model> GetParent() { return modelParent; } std::shared_ptr<Model> GetParent() { return modelParent; }
Object( std::string name, Object( std::string name, std::shared_ptr<Model> modelParent, GLuint textureID, GLuint shaderID, glm::vec3 color,
std::shared_ptr<Model> modelParent, glm::vec3 position, glm::vec3 rotation, glm::vec3 scale, float angle, bool dynamic, bool kinematic);
GLuint textureID,
GLuint shaderID,
glm::vec3 color,
glm::vec3 position,
glm::vec3 rotation,
glm::vec3 scale,
float angle,
bool dynamic,
bool kinematic);
Object(std::string name, Object(std::string name, std::shared_ptr<Model> modelParent, GLuint shaderID, glm::vec3 color, glm::vec3 position,
std::shared_ptr<Model> modelParent, glm::vec3 rotation, glm::vec3 scale, float angle, bool dynamic, bool kinematic);
GLuint shaderID,
glm::vec3 color,
glm::vec3 position,
glm::vec3 rotation,
glm::vec3 scale,
float angle,
bool dynamic,
bool kinematic);
bool exists = true;
glm::vec3 getScaleFromMatrix(glm::mat4 modelMatrix); glm::vec3 getScaleFromMatrix(glm::mat4 modelMatrix);
glm::vec3 getPositionFromMatrix(glm::mat4 modelMatrix); glm::vec3 getPositionFromMatrix(glm::mat4 modelMatrix);
glm::vec3 findOrbit(float time, glm::vec3 center, glm::vec3 orbit, glm::vec3 radius); glm::vec3 findOrbit(float time, glm::vec3 center, glm::vec3 orbit, glm::vec3 radius);
private: private:
void SetMatrix(); void SetMatrix();
std::shared_ptr<Model> modelParent; std::shared_ptr<Model> modelParent;
std::string name; std::string name;

View File

@ -20,6 +20,7 @@
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h" #include "stb_image.h"
physx::PxRigidDynamic* getActor(std::string name);
static PxFilterFlags simulationFilterShader(PxFilterObjectAttributes attributes0, static PxFilterFlags simulationFilterShader(PxFilterObjectAttributes attributes0,
PxFilterData filterData0, PxFilterObjectAttributes attributes1, PxFilterData filterData1, PxFilterData filterData0, PxFilterObjectAttributes attributes1, PxFilterData filterData1,
PxPairFlags& pairFlags, const void* constantBlock, PxU32 constantBlockSize) PxPairFlags& pairFlags, const void* constantBlock, PxU32 constantBlockSize)
@ -43,31 +44,16 @@ public:
// using pairHeader.actors[0] and pairHeader.actors[1] // using pairHeader.actors[0] and pairHeader.actors[1]
auto ac = pairHeader.actors[0]; auto ac = pairHeader.actors[0];
auto ac2 = pairHeader.actors[1]; auto ac2 = pairHeader.actors[1];
/*if (ac->userData == renderables.back() || ac2->userData == renderables.back()) auto actorName1 = ((Object*)ac->userData)->GetName();
auto actorName2 = ((Object*)ac2->userData)->GetName();
if ((actorName1 == "Space Humster" && actorName2 == "Corvette") || (actorName2 == "Space Humster" && actorName1 == "Corvette"))
{ {
std::cout << "Liczba CP:" << nbPairs << std::endl; cout << "Znalazles chomika! :)" << endl;
auto humster = getActor("Space Humster");
for (PxU32 i = 0; i < nbPairs; i++) ((Object*)humster->userData)->exists = false;
{ humster->setActorFlag(PxActorFlag::eDISABLE_SIMULATION, true);
const PxContactPair& cp = pairs[i];
// HINT: two get the contact points, use
// PxContactPair::extractContacts
std::vector<PxContactPairPoint> buffer;
for (int i = 0; i < cp.contactCount; i++)
buffer.push_back(PxContactPairPoint());
cp.extractContacts(&buffer[0], sizeof(buffer));
for (int i = 0; i < buffer.size(); i++)
{
auto position = buffer[i].position;
std::cout << position.x << ' ' << position.y << ' ' << position.x << std::endl;
} }
} }
}*/
}
virtual void onConstraintBreak(PxConstraintInfo* constraints, PxU32 count) {} virtual void onConstraintBreak(PxConstraintInfo* constraints, PxU32 count) {}
virtual void onWake(PxActor** actors, PxU32 count) {} virtual void onWake(PxActor** actors, PxU32 count) {}
virtual void onSleep(PxActor** actors, PxU32 count) {} virtual void onSleep(PxActor** actors, PxU32 count) {}
@ -154,7 +140,6 @@ physx::PxShape* sphereShape;
physx::PxMaterial* material; physx::PxMaterial* material;
std::vector<physx::PxRigidDynamic*> dynamicObjects; std::vector<physx::PxRigidDynamic*> dynamicObjects;
std::vector<physx::PxRigidStatic*> staticObjects; std::vector<physx::PxRigidStatic*> staticObjects;
physx::PxRigidDynamic* getActor(std::string name);
Object* findObject(std::string name); Object* findObject(std::string name);
glm::mat4 shipRotationMatrix; glm::mat4 shipRotationMatrix;
@ -797,12 +782,16 @@ void initPhysics()
{ {
material = pxScene.physics->createMaterial(0.5, 0.5, 0.5); material = pxScene.physics->createMaterial(0.5, 0.5, 0.5);
rectangleShape = pxScene.physics->createShape(PxBoxGeometry(1, 1, 1), *material);
for (auto &obj : objects) for (auto &obj : objects)
{ {
if (obj.isDynamic() == true) if (obj.isDynamic() == true)
{ {
if (obj.GetName() == "Space Humster")
rectangleShape = pxScene.physics->createShape(PxBoxGeometry(0.3f, 0.3f, 0.3f), *material);
else if (obj.GetName() == "Corvette")
rectangleShape = pxScene.physics->createShape(PxBoxGeometry(0.5f, 0.5f, 0.5f), *material);
else rectangleShape = pxScene.physics->createShape(PxBoxGeometry(1, 1, 1), *material);
glm::vec3 pos = obj.GetPosition(); glm::vec3 pos = obj.GetPosition();
glm::vec3 rot = obj.GetRotation(); glm::vec3 rot = obj.GetRotation();
auto dynamicObj = pxScene.physics->createRigidDynamic(PxTransform(pos.x, pos.y, pos.z)); auto dynamicObj = pxScene.physics->createRigidDynamic(PxTransform(pos.x, pos.y, pos.z));
@ -819,6 +808,7 @@ void initPhysics()
pxScene.scene->addActor(*dynamicObj); pxScene.scene->addActor(*dynamicObj);
dynamicObjects.push_back(dynamicObj); dynamicObjects.push_back(dynamicObj);
rectangleShape->release();
} }
else else
{ {
@ -834,7 +824,7 @@ void initPhysics()
mat.setPosition(PxVec3(pos.x, pos.y, pos.z)); mat.setPosition(PxVec3(pos.x, pos.y, pos.z));
mat.rotate(PxVec3(rot.x, rot.y, rot.z)); mat.rotate(PxVec3(rot.x, rot.y, rot.z));
dynamicObj->setGlobalPose(PxTransform(mat)); dynamicObj->setGlobalPose(PxTransform(mat));
dynamicObj->attachShape(*rectangleShape); dynamicObj->attachShape(*sphereShape);
dynamicObj->userData = &obj; dynamicObj->userData = &obj;
dynamicObj->setLinearVelocity(physx::PxVec3(0, 0, 0)); dynamicObj->setLinearVelocity(physx::PxVec3(0, 0, 0));
dynamicObj->setAngularVelocity(physx::PxVec3(0, 0, 0)); dynamicObj->setAngularVelocity(physx::PxVec3(0, 0, 0));
@ -858,7 +848,7 @@ void initPhysics()
sphereShape->release(); sphereShape->release();
} }
} }
rectangleShape->release();
} }
void initAsteroids() void initAsteroids()