replaced the cube by a shield

This commit is contained in:
Anselme 2017-09-06 00:02:53 +02:00
parent b92fa1b556
commit b0bd49fa84
14 changed files with 60 additions and 131 deletions

3
deploy/data/shield.mtl Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1ef4f914e2471329c7941da84fa77f85863f650b75b419bf7448378491ce6d3a
size 146

3
deploy/data/shield.obj Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c99ff29465c92c7620f01977970513c7c384aca192c6375e305c2cdc8a34aa64
size 315132

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ca2ba2061f97af05b000b85e8489a7711356efc819f6df4e6058270d1be513f2
size 151774

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:de71bc2611a54b4957c07f49d0d83d19db5cc54621fdbab674d7ce3dbd74605b
size 76948

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:296e0239c71ad95a21756e98ace3d7e9f43e82725a156f6a32b3cecf35ed912e
size 164968

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f878621c0b1fe3be1e92a6475d677a6152a222189358803973e48084deffa731
size 339069

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ae7a152959a26719133063e09ea578786d2265c3bcd29ab9743ff6efb3277f2f
size 9286

View File

@ -1,38 +0,0 @@
{
"TextureResource": [
{
"woodbox albedo",
"woodframe_albedo.png",
24,
1,
1
}
{
"woodbox roughness",
"woodframe_roughness.png",
8,
1,
1
}
{
"woodbox metallic",
"woodframe_metallic.png",
8,
1,
1
}
{
"woodbox normals",
"woodframe_normal.png",
24,
1,
1
}
],
"ResourcePack": [
{
"woodbox",
[{"TextureResource", 0}]
}
]
}

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6bad25466e6184902ee2c2ec7d47f8ae112943d3c92fca387a5b41da0b42a2a5
size 6976127

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:289e65cf6fa41d6c00a62cde57ffb20dbe5f1de6b3e6a3ef4d8a7de8f41524bd
size 15007

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:25c6e56846639f176e8d9ef756b5df8329cba6cd0117812dc79dfa2892ccf560
size 6869334

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f714f443197a22e6f7148004b344f0081f9c7667b85429472d38b9190af43d79
size 1822076

View File

@ -13,79 +13,34 @@
#include "resourcemanager.h"
#include <imgui/imgui.h>
#define PHYSICS_OFFSET 0.01f
#define PHYSICS_SHAPES_OFFSET 0.0025f
Potator::Potator(PlayerCharacterNode * player,
int cube_action,
int shield_action,
int bottle_action,
int object_action) :
m_player(player),
m_throwCubeAction(cube_action),
m_throwShieldAction(shield_action),
m_throwBottleAction(bottle_action),
m_throwObjectAction(object_action)
{
glm::vec3 cubeDim(1);
glm::vec3 s = cubeDim*0.5f;
float density = 1.f;
// creating shield
m_shieldMeshes = Loader::loadMesh("shield.obj");
for(Mesh* m : m_shieldMeshes)
m->initGL();
// creating cube
m_cubeMesh = new Mesh("woodBox");
m_cubeMesh->addVertex(glm::vec3(-1*s.x, -1*s.y, 1*s.z),glm::vec3(0, 0, 1),glm::vec2(0, 0));
m_cubeMesh->addVertex(glm::vec3(-1*s.x, 1*s.y, 1*s.z),glm::vec3(0, 0, 1),glm::vec2(0, 1));
m_cubeMesh->addVertex(glm::vec3( 1*s.x, -1*s.y, 1*s.z),glm::vec3(0, 0, 1),glm::vec2(1, 0));
m_cubeMesh->addVertex(glm::vec3( 1*s.x, 1*s.y, 1*s.z),glm::vec3(0, 0, 1),glm::vec2(1, 1));
btCompoundShape* shieldShape = new btCompoundShape();
m_cubeMesh->addVertex(glm::vec3(-1*s.x, -1*s.y, -1*s.z),glm::vec3(0, 0, -1),glm::vec2(1, 0));
m_cubeMesh->addVertex(glm::vec3(-1*s.x, 1*s.y, -1*s.z),glm::vec3(0, 0, -1),glm::vec2(1, 1));
m_cubeMesh->addVertex(glm::vec3( 1*s.x, -1*s.y, -1*s.z),glm::vec3(0, 0, -1),glm::vec2(0, 0));
m_cubeMesh->addVertex(glm::vec3( 1*s.x, 1*s.y, -1*s.z),glm::vec3(0, 0, -1),glm::vec2(0, 1));
btTransform woodTransform = btTransform::getIdentity();
woodTransform.setRotation(btQuaternion(0, 3.1416f, 0));
shieldShape->addChildShape(woodTransform, new btCylinderShapeZ(btVector3(0.57f + PHYSICS_SHAPES_OFFSET, 0.57f + PHYSICS_SHAPES_OFFSET, 0.03f + PHYSICS_SHAPES_OFFSET)));
btTransform guardTransform = btTransform::getIdentity();
guardTransform.setOrigin(btVector3(0.f, 0.f, -0.08f));
shieldShape->addChildShape(guardTransform, new btConeShapeZ(0.17 + PHYSICS_SHAPES_OFFSET, -0.17 + PHYSICS_SHAPES_OFFSET));
m_cubeMesh->addVertex(glm::vec3(-1*s.x, 1*s.y, -1*s.z),glm::vec3(0, 1, 0),glm::vec2(0, 0));
m_cubeMesh->addVertex(glm::vec3(-1*s.x, 1*s.y, 1*s.z),glm::vec3(0, 1, 0),glm::vec2(0, 1));
m_cubeMesh->addVertex(glm::vec3( 1*s.x, 1*s.y, -1*s.z),glm::vec3(0, 1, 0),glm::vec2(1, 0));
m_cubeMesh->addVertex(glm::vec3( 1*s.x, 1*s.y, 1*s.z),glm::vec3(0, 1, 0),glm::vec2(1, 1));
m_shieldShape = shieldShape;
m_cubeMesh->addVertex(glm::vec3(-1*s.x, -1*s.y, -1*s.z),glm::vec3(0, -1, 0),glm::vec2(1, 0));
m_cubeMesh->addVertex(glm::vec3(-1*s.x, -1*s.y, 1*s.z),glm::vec3(0, -1, 0),glm::vec2(1, 1));
m_cubeMesh->addVertex(glm::vec3( 1*s.x, -1*s.y, -1*s.z),glm::vec3(0, -1, 0),glm::vec2(0, 0));
m_cubeMesh->addVertex(glm::vec3( 1*s.x, -1*s.y, 1*s.z),glm::vec3(0, -1, 0),glm::vec2(0, 1));
m_cubeMesh->addVertex(glm::vec3( 1*s.x, -1*s.y, 1*s.z),glm::vec3( 1, 0, 0),glm::vec2(0, 0));
m_cubeMesh->addVertex(glm::vec3( 1*s.x, 1*s.y, 1*s.z),glm::vec3( 1, 0, 0),glm::vec2(0, 1));
m_cubeMesh->addVertex(glm::vec3( 1*s.x, -1*s.y, -1*s.z),glm::vec3( 1, 0, 0),glm::vec2(1, 0));
m_cubeMesh->addVertex(glm::vec3( 1*s.x, 1*s.y, -1*s.z),glm::vec3( 1, 0, 0),glm::vec2(1, 1));
m_cubeMesh->addVertex(glm::vec3(-1*s.x, -1*s.y, 1*s.z),glm::vec3(-1, 0, 0),glm::vec2(1, 0));
m_cubeMesh->addVertex(glm::vec3(-1*s.x, 1*s.y, 1*s.z),glm::vec3(-1, 0, 0),glm::vec2(1, 1));
m_cubeMesh->addVertex(glm::vec3(-1*s.x, -1*s.y, -1*s.z),glm::vec3(-1, 0, 0),glm::vec2(0, 0));
m_cubeMesh->addVertex(glm::vec3(-1*s.x, 1*s.y, -1*s.z),glm::vec3(-1, 0, 0),glm::vec2(0, 1));
for(int id=0; id<24; id+=8)
{
m_cubeMesh->addTriangle(id+0, id+1, id+2);
m_cubeMesh->addTriangle(id+2, id+1, id+3);
m_cubeMesh->addTriangle(id+6, id+5, id+4);
m_cubeMesh->addTriangle(id+7, id+5, id+6);
}
PBRMaterial *mat = new PBRMaterial();
Image* img = Loader::loadImage("woodframe_albedo.png", 24);
mat->setTexture(PBRMaterial::ALBEDO_SLOT, new Texture(img));
img = Loader::loadImage("woodframe_metallic.png", 8);
mat->setTexture(PBRMaterial::METALLIC_SLOT, new Texture(img));
img = Loader::loadImage("woodframe_roughness.png", 8);
mat->setTexture(PBRMaterial::ROUGHNESS_SLOT, new Texture(img));
img = Loader::loadImage("woodframe_normal.png", 24);
mat->setTexture(PBRMaterial::NORMALS_SLOT, new Texture(img));
m_cubeMesh->setMaterial(mat);
m_cubeMesh->computeTangents();
m_cubeMesh->initGL();
btVector3 halfExtents(s.x+PHYSICS_OFFSET, s.y+PHYSICS_OFFSET, s.z+PHYSICS_OFFSET);
m_cubeShape = new btBoxShape(halfExtents);
m_cubeMass = cubeDim.x*cubeDim.y*cubeDim.z*density;
m_shieldMass = 0.5f;
// creating bottle
m_bottleMeshes = Loader::loadMesh("bottle.obj");
@ -93,12 +48,18 @@ Potator::Potator(PlayerCharacterNode * player,
m->initGL();
btCompoundShape* bottleShape = new btCompoundShape();
btTransform bottleTransform = btTransform::getIdentity();
bottleTransform.setOrigin(btVector3(0.f, 0.19f, 0.f));
bottleShape->addChildShape(bottleTransform, new btConeShape(0.12+PHYSICS_OFFSET, 0.38+PHYSICS_OFFSET));
btTransform ballTransform = btTransform::getIdentity();
ballTransform.setOrigin(btVector3(0.f, 0.098f, 0.f));
bottleShape->addChildShape(ballTransform, new btSphereShape(0.11 + PHYSICS_SHAPES_OFFSET));
btTransform supportTransform = btTransform::getIdentity();
supportTransform.setOrigin(btVector3(0.f, 0.025f, 0.f));
bottleShape->addChildShape(supportTransform, new btCylinderShape(btVector3(0.07f + PHYSICS_SHAPES_OFFSET, 0.04f + PHYSICS_SHAPES_OFFSET, 0.07f + PHYSICS_SHAPES_OFFSET)));
btTransform neckTransform = btTransform::getIdentity();
neckTransform.setOrigin(btVector3(0.f, 0.26f, 0.f));
bottleShape->addChildShape(neckTransform, new btCylinderShape(btVector3(0.03f + PHYSICS_SHAPES_OFFSET, 0.08f + PHYSICS_SHAPES_OFFSET, 0.03f + PHYSICS_SHAPES_OFFSET)));
m_bottleShape = bottleShape;
m_bottleMass = 0.25f;
m_bottleMass = 0.03f;
// creating sword :
m_swordMeshes = Loader::loadMesh("sword.obj");
@ -107,18 +68,18 @@ Potator::Potator(PlayerCharacterNode * player,
btCompoundShape* swordShape = new btCompoundShape();
btVector3 guardBox = btVector3(0.03+PHYSICS_OFFSET, 0.04+PHYSICS_OFFSET, 0.25+PHYSICS_OFFSET);
btVector3 guardBox = btVector3(0.03 + PHYSICS_SHAPES_OFFSET, 0.04 + PHYSICS_SHAPES_OFFSET, 0.25 + PHYSICS_SHAPES_OFFSET);
swordShape->addChildShape(btTransform::getIdentity(), new btBoxShape(guardBox));
btTransform bladeTransform = btTransform::getIdentity();
bladeTransform.setOrigin(btVector3(0.f, 0.486705f, 0.f));
swordShape->addChildShape(bladeTransform, new btConeShape(0.07+PHYSICS_OFFSET, 2.15+PHYSICS_OFFSET));
swordShape->addChildShape(bladeTransform, new btConeShape(0.07 + PHYSICS_SHAPES_OFFSET, 2.15 + PHYSICS_SHAPES_OFFSET));
m_swordShape = swordShape;
m_swordMass = 0.5f;
}
void Potator::throwCube()
void Potator::throwShield()
{
glm::vec3 pos(0, 10, 0);
glm::vec3 dir(0, 1, 0);
@ -129,7 +90,10 @@ void Potator::throwCube()
}
float throwForce = 5.f;
createGib(new MeshNode(m_cubeMesh), m_cubeShape, m_cubeMass, pos, dir*throwForce, 30000);
GraphicalContainerNode *node = new GraphicalContainerNode();
for(Mesh * m : m_shieldMeshes)
node->addChild(new MeshNode(m));
createGib(node, m_shieldShape, m_shieldMass, pos, dir*throwForce, 30000);
}
void Potator::throwBottle()
@ -175,8 +139,8 @@ void Potator::update()
Input *input = getEngine().getInput();
for(Action action : input->getActions())
{
if(action.action == m_throwCubeAction)
throwCube();
if(action.action == m_throwShieldAction)
throwShield();
else if(action.action == m_throwBottleAction)
throwBottle();
else if(action.action == m_throwObjectAction)

View File

@ -10,13 +10,13 @@ class Mesh;
class Potator : public GibGeneratorNode
{
PlayerCharacterNode *m_player;
int m_throwCubeAction;
int m_throwShieldAction;
int m_throwBottleAction;
int m_throwObjectAction;
Mesh* m_cubeMesh;
btCollisionShape* m_cubeShape;
float m_cubeMass;
std::vector<Mesh*> m_shieldMeshes;
btCollisionShape* m_shieldShape;
float m_shieldMass;
std::vector<Mesh*> m_bottleMeshes;
btCollisionShape* m_bottleShape;
@ -26,19 +26,19 @@ class Potator : public GibGeneratorNode
btCollisionShape* m_swordShape;
float m_swordMass;
void throwCube();
void throwShield();
void throwBottle();
void throwSword();
public:
Potator(PlayerCharacterNode * player = nullptr,
int cube_action = NO_ACTION,
int shield_action = NO_ACTION,
int sphere_action = NO_ACTION,
int object_action = NO_ACTION);
void setPlayer(PlayerCharacterNode *player) { m_player = player; }
void setCubeThrowingAction(int action) { m_throwCubeAction = action; }
void setShieldThrowingAction(int action) { m_throwShieldAction = action; }
void setSphereThrowingAction(int action) { m_throwBottleAction = action; }
void setObjectThrowingAction(int action) { m_throwObjectAction = action; }