Merge branch 'master' of github.com:Faerbit/swp
This commit is contained in:
commit
98e8d10cdd
@ -264,6 +264,7 @@ std::vector<int> Converter::newComposition(int type, float posX, float posZ){
|
||||
XMLElement* trigger = doc->NewElement("trigger");
|
||||
newComposition->InsertEndChild(trigger);
|
||||
XMLElement* name = doc->NewElement("name");
|
||||
XMLElement* undo = doc->NewElement("undo");
|
||||
XMLElement* xPosition = doc->NewElement("xPosition");
|
||||
XMLElement* yPosition = doc->NewElement("yPosition");
|
||||
XMLElement* zPosition = doc->NewElement("zPosition");
|
||||
@ -278,6 +279,7 @@ std::vector<int> Converter::newComposition(int type, float posX, float posZ){
|
||||
XMLElement* toChangeObjNum = doc->NewElement("toChangeObjNum");
|
||||
|
||||
name->SetText("-");
|
||||
undo->SetText("false");
|
||||
xPosition->SetText("0");
|
||||
yPosition->SetText("0");
|
||||
zPosition->SetText("0");
|
||||
@ -292,6 +294,7 @@ std::vector<int> Converter::newComposition(int type, float posX, float posZ){
|
||||
toChangeObjNum->SetText("0");
|
||||
|
||||
trigger->InsertEndChild(name);
|
||||
trigger->InsertEndChild(undo);
|
||||
trigger->InsertEndChild(xPosition);
|
||||
trigger->InsertEndChild(yPosition);
|
||||
trigger->InsertEndChild(zPosition);
|
||||
|
@ -76,6 +76,8 @@
|
||||
<bColour>0.3</bColour>
|
||||
<intensity>4.0</intensity>
|
||||
<flameOffset>-1.5</flameOffset>
|
||||
<flameHeight>3.0</flameHeight>
|
||||
<flameWidth>0.8</flameWidth>
|
||||
</light>
|
||||
</composition>
|
||||
|
||||
|
@ -11776,18 +11776,19 @@
|
||||
<idBlue>105</idBlue>
|
||||
<typeID>20</typeID>
|
||||
<trigger>
|
||||
<name>-</name>
|
||||
<name>resetPlayer</name>
|
||||
<undo>false</undo>
|
||||
<xPosition>0</xPosition>
|
||||
<yPosition>0</yPosition>
|
||||
<yPosition>-100000</yPosition>
|
||||
<zPosition>0</zPosition>
|
||||
<targetIdGreen>-</targetIdGreen>
|
||||
<targetIdBlue>-</targetIdBlue>
|
||||
<distance>1.0</distance>
|
||||
<distance>100015</distance>
|
||||
<isBiggerThan>false</isBiggerThan>
|
||||
<objectNum>0</objectNum>
|
||||
<luaScript>-</luaScript>
|
||||
<luaScript>resetPlayer.lua</luaScript>
|
||||
<toChangeIdGreen>0</toChangeIdGreen>
|
||||
<toChangeIdBlue>0</toChangeIdBlue>
|
||||
<toChangeIdBlue>105</toChangeIdBlue>
|
||||
<toChangeObjNum>0</toChangeObjNum>
|
||||
</trigger>
|
||||
</composition>
|
||||
|
17
data/levels/scripts/resetPlayer.lua
Normal file
17
data/levels/scripts/resetPlayer.lua
Normal file
@ -0,0 +1,17 @@
|
||||
local global = require( "global" )
|
||||
if(global.triggeredResetPlayer == nil) then
|
||||
global.triggeredResetPlayer = false
|
||||
end
|
||||
function trigger(objectToChange)
|
||||
if(global.triggeredResetPlayer == false) then
|
||||
if(not level) then
|
||||
print("No level found in Lua!")
|
||||
return
|
||||
end
|
||||
|
||||
level:resetPlayer()
|
||||
|
||||
--global.triggeredResetPlayer = true
|
||||
print("reset player")
|
||||
end
|
||||
end
|
31
level.cc
31
level.cc
@ -38,6 +38,7 @@ void Level::load() {
|
||||
.addFunction("deleteObject", &Level::deleteObject)
|
||||
.addFunction("getObjectCount", &Level::getPhysicsObjectsVectorSize)
|
||||
.addFunction("moveObject", &Level::moveObject)
|
||||
.addFunction("resetPlayer", &Level::resetPlayer)
|
||||
.endClass();
|
||||
//Push the level to Lua as a global variable
|
||||
luabridge::push(luaState, this);
|
||||
@ -63,23 +64,28 @@ void Level::update(float runTimeSinceLastUpdate, float runTime, glm::vec2 mouseD
|
||||
// Ignore first two mouse updates, because they are incorrect
|
||||
// DON'T try to move this functionallity elsewhere
|
||||
static int i = 0;
|
||||
if (i <2) {
|
||||
if (i <20) {
|
||||
i++;
|
||||
mouseDelta.x=mouseDelta.y=0;
|
||||
}
|
||||
|
||||
int runs = 2;
|
||||
|
||||
if(i>=20)
|
||||
{
|
||||
mouseDelta.x = -mouseDelta.x;
|
||||
}
|
||||
|
||||
for(int j = runs; j > 0; j--)
|
||||
{
|
||||
physics.takeUpdateStep(runTimeSinceLastUpdate/runs);
|
||||
if(i>=2)
|
||||
{
|
||||
mouseDelta.x = -mouseDelta.x;
|
||||
camera.updateRotation(mouseDelta/100.0f/(float)runs);
|
||||
physics.updateCameraPos(mouseDelta, 50/runs, camera.getDistance());
|
||||
|
||||
camera.updateRotation(mouseDelta/100.0f/(float)runs);
|
||||
physics.updateCameraPos(mouseDelta, 50/runs, camera.getDistance());
|
||||
|
||||
camera.setPosition(physics.getCameraPosition());
|
||||
camera.setDirection(physics.getCameraToPlayer());
|
||||
}
|
||||
camera.setPosition(physics.getCameraPosition());
|
||||
camera.setDirection(physics.getCameraToPlayer());
|
||||
|
||||
if(wPressed){
|
||||
physics.rollForward(camera.getVector(),strength/runs);
|
||||
}
|
||||
@ -182,7 +188,12 @@ void Level::deleteObject(int objectIndex){
|
||||
void Level::resetPlayer(){
|
||||
Loader loader = Loader();
|
||||
glm::vec3 newPosition = loader.reloadPlayerPosition(xmlFilePath, this);
|
||||
//TODO cameraCenter.setPosition(newPosition);
|
||||
physics.forceMove(newPosition, playerIndex);
|
||||
physics.forceMoveCamera(newPosition + glm::vec3(1,0,0));
|
||||
}
|
||||
|
||||
void Level::setPlayerIndex(int index){
|
||||
playerIndex = index;
|
||||
}
|
||||
|
||||
void Level::setStrength(float strength) {
|
||||
|
2
level.hh
2
level.hh
@ -57,6 +57,7 @@ class Level {
|
||||
lua_State* getLuaState();
|
||||
Terrain* getTerrain();
|
||||
void resetPlayer();
|
||||
void setPlayerIndex(int index);
|
||||
private:
|
||||
lua_State* luaState=nullptr;
|
||||
std::vector<Object*> objects;
|
||||
@ -67,6 +68,7 @@ class Level {
|
||||
glm::vec4 fogColour;
|
||||
Light directionalLight;
|
||||
Object* cameraCenter;
|
||||
int playerIndex;
|
||||
Object* skydome;
|
||||
Physics physics;
|
||||
Camera camera;
|
||||
|
4
light.cc
4
light.cc
@ -1,10 +1,12 @@
|
||||
#include "light.hh"
|
||||
|
||||
Light::Light(glm::vec3 position, glm::vec3 colour, float intensity, float flameYOffset)
|
||||
Light::Light(glm::vec3 position, glm::vec3 colour, float intensity, float flameYOffset, float flameHeight, float flameWidth)
|
||||
: Entity(position, glm::vec3(0.0f, 0.0f, 0.0f)) {
|
||||
this->colour = colour;
|
||||
this->intensity = intensity;
|
||||
this->flameYOffset = flameYOffset;
|
||||
this->flameHeight = flameHeight;
|
||||
this->flameWidth = flameWidth;
|
||||
}
|
||||
|
||||
Light::Light() {
|
||||
|
4
light.hh
4
light.hh
@ -6,7 +6,7 @@
|
||||
|
||||
class Light : public Entity {
|
||||
public:
|
||||
Light(glm::vec3 position, glm::vec3 colour, float intensity, float flameYOffset = 0.0f);
|
||||
Light(glm::vec3 position, glm::vec3 colour, float intensity, float flameYOffset = 0.0f, float flameHeight = 0.0f, float flameWidth = 0.0f);
|
||||
Light();
|
||||
glm::vec3 getColour();
|
||||
float getIntensity();
|
||||
@ -14,6 +14,8 @@ class Light : public Entity {
|
||||
~Light();
|
||||
private:
|
||||
float flameYOffset;
|
||||
float flameHeight;
|
||||
float flameWidth;
|
||||
float intensity;
|
||||
glm::vec3 colour;
|
||||
};
|
||||
|
@ -258,6 +258,7 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
||||
|
||||
if(compositionType == 20){
|
||||
level->setCameraCenter(object);
|
||||
level->setPlayerIndex(objectIdentifier[1]);
|
||||
}
|
||||
}//objectData found
|
||||
}//finding the objectData
|
||||
@ -298,7 +299,9 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
||||
if (flameOffset != NULL){
|
||||
float offset = 0;
|
||||
errorCheck(flameOffset->QueryFloatText(&offset));
|
||||
Light light = Light(lightPosition, lightColour, lightIntensity, offset);
|
||||
float flameHeight = queryBool(xmlLight, "flameHeight");
|
||||
float flameWidth = queryBool(xmlLight, "flameWidth");
|
||||
Light light = Light(lightPosition, lightColour, lightIntensity, offset, flameHeight, flameWidth);
|
||||
level->addLight(light);
|
||||
}
|
||||
else {
|
||||
|
34
physics.cc
34
physics.cc
@ -414,9 +414,29 @@ void Physics::addSphere(float rad, Entity entity, float mass, float dampningL, f
|
||||
throw std::invalid_argument( "Bodies out of Sync" );
|
||||
}
|
||||
|
||||
void Physics::prepareCollisionDetection()
|
||||
{
|
||||
playerTerrainCol = playerObjectColision = false;
|
||||
int numManifods = world->getDispatcher()->getNumManifolds();
|
||||
|
||||
for (int i=0;i<numManifods;i++)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
bool Physics::playerWithGround()
|
||||
{
|
||||
return playerTerrainCol;
|
||||
}
|
||||
|
||||
bool Physics::playerWithObject()
|
||||
{
|
||||
return playerObjectColision;
|
||||
}
|
||||
|
||||
void Physics::addCamera() //Camera Creator automatically called when player is created
|
||||
{
|
||||
btSphereShape* sphere = new btSphereShape(0.5f); //we use this to make a more interesting camera, that does not interpenetrate with the terrain/objects
|
||||
btSphereShape* sphere = new btSphereShape(0.2f); //we use this to make a more interesting camera, that does not interpenetrate with the terrain/objects
|
||||
|
||||
btVector3 inertia(0,0,0); //rotation handled elsewhere (as it always has to look at the player)
|
||||
|
||||
@ -481,7 +501,7 @@ void Physics::updateCameraPos(glm::vec2 mouseMovement, float strength, float dis
|
||||
this->cameraDistance = distance;
|
||||
//note: in mouseMovement x and y are flipped in contrast to bullet
|
||||
btVector3 dodo = btVector3(0,1,0).cross(btVector3(currentDirection.x(),0,currentDirection.z()));
|
||||
currentDirection = currentDirection.rotate(dodo,-mouseMovement.x / 100);//mathhelper 3.14159265359
|
||||
currentDirection = currentDirection.rotate(dodo,-mouseMovement.x / 50);//mathhelper 3.14159265359
|
||||
|
||||
btVector3 compare = currentDirection;
|
||||
compare.setY(0);
|
||||
@ -496,7 +516,7 @@ void Physics::updateCameraPos(glm::vec2 mouseMovement, float strength, float dis
|
||||
currentDirection = compare;
|
||||
}
|
||||
|
||||
currentDirection = currentDirection.rotate(btVector3(0,1,0),mouseMovement.y/100);
|
||||
currentDirection = currentDirection.rotate(btVector3(0,1,0),-mouseMovement.y/100);
|
||||
currentDirection.normalize();
|
||||
}
|
||||
|
||||
@ -557,6 +577,14 @@ void Physics::addStaticGroundPlane()
|
||||
void Physics::forceMove(glm::vec3 newPosition, unsigned indice)//ugly, but needed for reset
|
||||
{
|
||||
bodies[indice]->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(newPosition.x,newPosition.y,newPosition.z)));
|
||||
bodies[indice]->setLinearVelocity(btVector3(0,0,0));
|
||||
}
|
||||
|
||||
void Physics::forcePlayer(glm::vec3 newPosition)//ugly, but needed for reset
|
||||
{
|
||||
playerBall->setCenterOfMassTransform(btTransform(btQuaternion(0,0,0,1),btVector3(newPosition.x,newPosition.y,newPosition.z)));
|
||||
playerBall->setLinearVelocity(btVector3(0,0,0));
|
||||
forceMoveCamera(newPosition + glm::vec3(currentDirection.x()*cameraDistance,currentDirection.y()*cameraDistance,currentDirection.z()*cameraDistance));
|
||||
}
|
||||
|
||||
void Physics::forceMoveCamera(glm::vec3 newPosition)
|
||||
|
@ -74,6 +74,10 @@ class Physics {
|
||||
void forceMove(glm::vec3 newPosition, unsigned indice);
|
||||
void forceMoveCamera(glm::vec3 newPosition);
|
||||
void addConvexBody(Entity entity, std::string path, float mass, float dampningL, float dampningA, unsigned indice, float scaling, bool rotate);
|
||||
void prepareCollisionDetection();
|
||||
bool playerWithGround();
|
||||
bool playerWithObject();
|
||||
void forcePlayer(glm::vec3 newPosition);
|
||||
|
||||
struct positionConstraint{btRigidBody* body; float strength; btVector3 position;};
|
||||
|
||||
@ -98,6 +102,8 @@ class Physics {
|
||||
int counter = 0;
|
||||
std::string geometryPath;
|
||||
float cameraDistance = 5; //distance of the camera to the player.
|
||||
bool playerTerrainCol = false;
|
||||
bool playerObjectColision = false;
|
||||
};
|
||||
|
||||
enum collisionTypes{
|
||||
|
Loading…
Reference in New Issue
Block a user