Merged physics.cc.

This commit is contained in:
Steffen Fündgens 2015-02-06 18:04:20 +01:00
commit ff5bd0dae1
8 changed files with 4640 additions and 388 deletions

File diff suppressed because it is too large Load Diff

View File

@ -221,6 +221,25 @@
</object>
</composition>
<!-- Rotated Bridge Block -->
<composition>
<typeID>141</typeID>
<ignoreHeightmap>true</ignoreHeightmap>
<object>
<modelPath>block.obj</modelPath>
<xOffset>0.0</xOffset>
<yOffset>20.0</yOffset>
<zOffset>0.0</zOffset>
<xRot>0.0</xRot>
<yRot>90.0</yRot>
<zRot>0.0</zRot>
<scale>1.5</scale>
<mass>0.0</mass>
</object>
</composition>
<!-- Bridge Block on Pillar-->
<composition>
<typeID>160</typeID>
@ -271,6 +290,56 @@
</object>
</composition>
<!-- Rotated Bridge Block on Pillar-->
<composition>
<typeID>161</typeID>
<ignoreHeightmap>true</ignoreHeightmap>
<object>
<modelPath>block.obj</modelPath>
<xOffset>0.0</xOffset>
<yOffset>20.0</yOffset>
<zOffset>0.0</zOffset>
<xRot>0.0</xRot>
<yRot>90.0</yRot>
<zRot>0.0</zRot>
<scale>1.5</scale>
<mass>0.0</mass>
</object>
<object>
<modelPath>column.obj</modelPath>
<xOffset>0.0</xOffset>
<yOffset>18.0</yOffset>
<zOffset>0.0</zOffset>
<xRot>0.0</xRot>
<yRot>90.0</yRot>
<zRot>0.0</zRot>
<scale>1.5</scale>
<mass>0.0</mass>
</object>
<object>
<modelPath>column.obj</modelPath>
<xOffset>0.0</xOffset>
<yOffset>15.0</yOffset>
<zOffset>0.0</zOffset>
<xRot>0.0</xRot>
<yRot>90.0</yRot>
<zRot>0.0</zRot>
<scale>1.5</scale>
<mass>0.0</mass>
</object>
<object>
<modelPath>column.obj</modelPath>
<xOffset>0.0</xOffset>
<yOffset>12.0</yOffset>
<zOffset>0.0</zOffset>
<xRot>0.0</xRot>
<yRot>90.0</yRot>
<zRot>0.0</zRot>
<scale>1.5</scale>
<mass>0.0</mass>
</object>
</composition>
<!-- Wall -->
<composition>
<typeID>180</typeID>
@ -283,7 +352,7 @@
<xRot>0.0</xRot>
<yRot>0.0</yRot>
<zRot>0.0</zRot>
<scale>1.49</scale>
<scale>1.48</scale>
<mass>0.0</mass>
</object>
</composition>
@ -300,7 +369,7 @@
<xRot>0.0</xRot>
<yRot>90.0</yRot>
<zRot>0.0</zRot>
<scale>1.49</scale>
<scale>1.48</scale>
<mass>0.0</mass>
</object>
</composition>
@ -339,6 +408,23 @@
</object>
</composition>
<!-- Rotated Gate -->
<composition>
<typeID>221</typeID>
<ignoreHeightmap>true</ignoreHeightmap>
<object>
<modelPath>gate.obj</modelPath>
<xOffset>0.0</xOffset>
<yOffset>25.0</yOffset>
<zOffset>0.0</zOffset>
<xRot>0.0</xRot>
<yRot>90.0</yRot>
<zRot>0.0</zRot>
<scale>1.5</scale>
<mass>0.0</mass>
</object>
</composition>
<!-- Block for Switch -->
<composition>
<typeID>240</typeID>
@ -449,7 +535,7 @@
<dampningA>0.5</dampningA>
</objectData>
<!-- Width height and length are not exact, Wall should be a TriangleMesh but that does not work... -->
<!-- lengh may not be exact -->
<objectData>
<modelPath>simpleWall.obj</modelPath>
<texturePath>simpleWallTexture.png</texturePath>
@ -457,9 +543,9 @@
<diffuseFactor>0.6</diffuseFactor>
<specularFactor>0.4</specularFactor>
<shininess>2.0</shininess>
<physicType>TriangleMesh</physicType>
<width>1.5</width>
<height>10</height>
<physicType>Box</physicType>
<width>1.2</width>
<height>6</height>
<length>6</length>
<dampningL>0.555</dampningL>
<dampningA>0.5</dampningA>
@ -472,7 +558,10 @@
<diffuseFactor>0.6</diffuseFactor>
<specularFactor>0.4</specularFactor>
<shininess>2.0</shininess>
<physicType>TriangleMesh</physicType>
<physicType>Box</physicType>
<width>1.2</width>
<height>6</height>
<length>6</length>
<dampningL>0.555</dampningL>
<dampningA>0.5</dampningA>
</objectData>
@ -484,7 +573,10 @@
<diffuseFactor>0.6</diffuseFactor>
<specularFactor>0.4</specularFactor>
<shininess>2.0</shininess>
<physicType>TriangleMesh</physicType>
<physicType>Box</physicType>
<width>2</width>
<height>1.88</height>
<length>1.99</length>
<dampningL>0.555</dampningL>
<dampningA>0.5</dampningA>
</objectData>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

View File

@ -25,12 +25,13 @@ void Physics::init(std::string geometryPath) //prepares bullet by creating all i
void Physics::takeUpdateStep(float timeDiff)
{
world->stepSimulation(timeDiff); //allows the world to be simmulated correctly indipendant of the timedifferences between frames
counter++;
if(counter<10)
if(counter<1)
{
world->stepSimulation(timeDiff);//allows the world to be simmulated correctly indipendant of the timedifferences between frames
return;
}
for(unsigned i = 0; i < allPositionConstraints.size();i++) //this handles the spring constraints
{
if(allPositionConstraints[i].position != allPositionConstraints[i].body->getCenterOfMassPosition()) //if constraint != position of the body because otherwise dir = 0
@ -46,15 +47,25 @@ void Physics::takeUpdateStep(float timeDiff)
position.normalize();
position *= 5;
position += playerBall->getCenterOfMassPosition(); //is the position 5 units away from the player in the direction of the camera
position.setY(playerBall->getCenterOfMassPosition().getY() + 1);
btVector3 dir = cameraBody->getCenterOfMassPosition() - position;
float str = cameraBody->getInvMass()*30 * dir.length();
float str = cameraBody->getInvMass()*50 * dir.length();
cameraBody->applyCentralForce(-dir*str);//scale the force by camera mass
cameraBody->applyCentralForce(btVector3(0,96,0)); //we leave gravity in because by contrasting gravity to this force we force the camera slightly higher than the ball when still, but it follows more closer to the level of the ball (though still slightly higher) when it is moving.
counter=0;
float speed = cameraBody->getLinearVelocity().length();
if(speed>20.0f)
{
printf("%f , %f \n", speed, position.length());
position = cameraBody->getLinearVelocity();
position.normalize();
cameraBody->setLinearVelocity(position*20);
}
world->stepSimulation(timeDiff);
}
//
void Physics::removePositionConstraint(int bodyIndice) //remover function for deleting all pos constraints on one body
{
for(unsigned i = 0; i < allPositionConstraints.size(); i++)
@ -95,7 +106,7 @@ void Physics::addPlayer(float friction, float rad, Entity entity, float mass, fl
btRigidBody::btRigidBodyConstructionInfo info(mass,motion,sphere,inertia); //next we process all data for the rigid body into info
info.m_friction = friction*2; //here we modify the friction and restitution (bounciness) of the object
info.m_restitution = 0;
info.m_restitution = 0.1f;
playerBall = new btRigidBody(info); //finally we create the rigid body using the info
@ -130,8 +141,8 @@ void Physics::addTerrain(int width, int length, float** heightData) //The terrai
highest++;
btHeightfieldTerrainShape* terrainShape = new btHeightfieldTerrainShape(length,width,heightfield,highest,1,true,false);
btRigidBody::btRigidBodyConstructionInfo info(0,new btDefaultMotionState(),terrainShape,btVector3(0,0,0)); //next we process all data for the rigid body into info
info.m_friction = 1;
info.m_restitution = 0;
btRigidBody* tBody = new btRigidBody(info);
@ -278,7 +289,7 @@ void Physics::addBox(float width, float height, float length, Entity entity, flo
void Physics::addSphere(float rad, Entity entity, float mass, float dampningL, float dampningA, unsigned indice,bool rotate)
{
if(bodies.size() == indice)
if(bodies.size() == indice) //(user's initial) height, not the actual height. More...
throw std::invalid_argument( "Bodies out of Sync" );
btSphereShape* sphere = new btSphereShape(rad);
@ -328,6 +339,8 @@ void Physics::addCamera() //Camera Creator automatically called when player is c
cameraBody->setDamping(0.9,0.5); //this damping factor leaves a relativly smoothe system
world->addRigidBody(cameraBody,COL_OBJECTS, objectsPhysicsCollision);
cameraBody->setGravity(btVector3(0,0,0));
cameraBody->setSleepingThresholds(0,0); //very important, otherwise camera may go to sleep, aka not move until next collision