fixed incorrect camera ratio, added coumpound shape for sword throwing
This commit is contained in:
parent
4d5c352f4c
commit
9c62efeb67
@ -34,7 +34,7 @@ class GibGeneratorNode : public ContainerNode
|
||||
public:
|
||||
void createGib(GraphicalNode* graphicalPart,
|
||||
btCollisionShape *physicsShape,
|
||||
float mass,
|
||||
float masses,
|
||||
const glm::vec3 &pos = glm::vec3(0),
|
||||
const glm::vec3 &velocity = glm::vec3(0),
|
||||
unsigned int lifeSpan = 5000);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <pipeline.h>
|
||||
#include <deferredpipeline.h>
|
||||
#include <algorithm>
|
||||
#include <SFML/Window.hpp>
|
||||
// Scene
|
||||
#include <mesh.h>
|
||||
#include <iostream>
|
||||
@ -28,6 +29,8 @@ SceneTree::~SceneTree()
|
||||
void SceneTree::setMainCamera(CameraNode *camNode)
|
||||
{
|
||||
((DeferredPipeline*)m_pipeline)->setCamera(camNode->getCamera());
|
||||
sf::Vector2u size = getEngine().getWindow()->getSize();
|
||||
camNode->getCamera()->resize(size.x, size.y);
|
||||
}
|
||||
|
||||
SceneIterator<Light*>* SceneTree::getLights()
|
||||
|
@ -8,15 +8,18 @@
|
||||
#include "scene/meshnode.h"
|
||||
#include "tools/loader.h"
|
||||
#include "texture.h"
|
||||
#include "scene/graphicalcontainernode.h"
|
||||
|
||||
#define PHYSICS_OFFSET 0.05f
|
||||
#define PHYSICS_OFFSET 0.01f
|
||||
|
||||
Potator::Potator(PlayerCharacterNode * player,
|
||||
int cube_action,
|
||||
int sphere_action) :
|
||||
int sphere_action,
|
||||
int object_action) :
|
||||
m_player(player),
|
||||
m_throwCubeAction(cube_action),
|
||||
m_throwSphereAction(sphere_action)
|
||||
m_throwSphereAction(sphere_action),
|
||||
m_throwObjectAction(object_action)
|
||||
{
|
||||
glm::vec3 cubeDim(1);
|
||||
float sphereRadius = 0.5f;
|
||||
@ -63,7 +66,10 @@ Potator::Potator(PlayerCharacterNode * player,
|
||||
m_cubeMesh->addTriangle(id+7, id+5, id+6);
|
||||
}
|
||||
|
||||
Image* wood = Loader::loadImage("../data/woodbox.jpg", false);
|
||||
Loader::setObjDirectory("../data/");
|
||||
Loader::setMtlDirectory("../data/");
|
||||
Loader::setTexDirectory("../data/");
|
||||
Image* wood = Loader::loadImage("woodbox.jpg", false);
|
||||
PhongMaterial *mat = new PhongMaterial();
|
||||
mat->setTexture(PhongMaterial::DIFFUSE_SLOT, new Texture(wood), "wood_texture");
|
||||
mat->specular = glm::vec3(0.3f);
|
||||
@ -96,6 +102,23 @@ Potator::Potator(PlayerCharacterNode * player,
|
||||
|
||||
float sphereVolume = 4.18879020479f*(sphereRadius*sphereRadius*sphereRadius); // (4*pi)/3 = 4.18879020479
|
||||
m_sphereMass = sphereVolume*density;
|
||||
|
||||
// creating sword :
|
||||
m_swordMeshes = Loader::loadMesh("sword.obj");
|
||||
for(Mesh* m : m_swordMeshes)
|
||||
m->initGL();
|
||||
|
||||
btCompoundShape* swordShape = new btCompoundShape();
|
||||
|
||||
btVector3 guardBox = btVector3(0.03+PHYSICS_OFFSET, 0.04+PHYSICS_OFFSET, 0.25+PHYSICS_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));
|
||||
|
||||
m_swordShape = swordShape;
|
||||
m_swordMass = 0.5f;
|
||||
}
|
||||
|
||||
void Potator::throwCube()
|
||||
@ -107,9 +130,9 @@ void Potator::throwCube()
|
||||
dir = m_player->getDirection();
|
||||
pos = m_player->getEyePosition() + dir*2.f;
|
||||
}
|
||||
float throwForce = 20.f;
|
||||
float throwForce = 10.f;
|
||||
|
||||
createGib(new MeshNode(m_cubeMesh), m_cubeShape, m_cubeMass, pos, dir*throwForce, 10000);
|
||||
createGib(new MeshNode(m_cubeMesh), m_cubeShape, m_cubeMass, pos, dir*throwForce, 30000);
|
||||
}
|
||||
|
||||
void Potator::throwSphere()
|
||||
@ -121,9 +144,26 @@ void Potator::throwSphere()
|
||||
dir = m_player->getDirection();
|
||||
pos = m_player->getEyePosition() + dir*2.f;
|
||||
}
|
||||
float throwForce = 20.f;
|
||||
float throwForce = 10.f;
|
||||
|
||||
createGib(new MeshNode(m_sphereMesh), m_sphereShape, m_sphereMass, pos, dir*throwForce, 10000);
|
||||
createGib(new MeshNode(m_sphereMesh), m_sphereShape, m_sphereMass, pos, dir*throwForce, 30000);
|
||||
}
|
||||
|
||||
void Potator::throwSword()
|
||||
{
|
||||
glm::vec3 pos(0, 10, 0);
|
||||
glm::vec3 dir(0, 1, 0);
|
||||
if(m_player != nullptr)
|
||||
{
|
||||
dir = m_player->getDirection();
|
||||
pos = m_player->getEyePosition() + dir*2.f;
|
||||
}
|
||||
float throwForce = 10.f;
|
||||
|
||||
GraphicalContainerNode *node = new GraphicalContainerNode();
|
||||
for(Mesh * m : m_swordMeshes)
|
||||
node->addChild(new MeshNode(m));
|
||||
createGib(node, m_swordShape, m_swordMass, pos, dir*throwForce, 300000);
|
||||
}
|
||||
|
||||
void Potator::update()
|
||||
@ -136,5 +176,7 @@ void Potator::update()
|
||||
throwCube();
|
||||
else if(action == m_throwSphereAction)
|
||||
throwSphere();
|
||||
else if(action == m_throwObjectAction)
|
||||
throwSword();
|
||||
}
|
||||
}
|
||||
|
@ -12,26 +12,35 @@ class Potator : public GibGeneratorNode
|
||||
PlayerCharacterNode *m_player;
|
||||
int m_throwCubeAction;
|
||||
int m_throwSphereAction;
|
||||
int m_throwObjectAction;
|
||||
|
||||
Mesh* m_cubeMesh;
|
||||
btCollisionShape* m_cubeShape;
|
||||
float m_cubeMass;
|
||||
|
||||
Mesh* m_sphereMesh;
|
||||
btCollisionShape* m_sphereShape;
|
||||
float m_sphereMass;
|
||||
|
||||
std::vector<Mesh*> m_swordMeshes;
|
||||
btCollisionShape* m_swordShape;
|
||||
float m_swordMass;
|
||||
|
||||
void throwCube();
|
||||
void throwSphere();
|
||||
void throwSword();
|
||||
|
||||
public:
|
||||
Potator(PlayerCharacterNode * player = nullptr,
|
||||
int cube_action = NO_ACTION,
|
||||
int sphere_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 setSphereThrowingAction(int action) { m_throwSphereAction = action; }
|
||||
void setObjectThrowingAction(int action) { m_throwObjectAction = action; }
|
||||
|
||||
virtual void update();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user