Skip to content
Permalink
Browse files

Add more functionality to the rigid body

  • Loading branch information...
godlikepanos committed Jun 18, 2018
1 parent 0b2523b commit 8c0d0f1e3d69d9fd69dbbb9d8cfee497eb4ea062
@@ -13,5 +13,6 @@
!*.glslp
!*.anki*
!*.blend
!*.lua
!CMakeLists.txt
build*/*
@@ -46,6 +46,9 @@ Error MyApp::userMainLoop(Bool& quit)
StringAuto(getAllocator()).sprintf("bmonkey%u", instance++).toCString(), body, "assets/Suzanne.ankicl"));
body->getComponent<BodyComponent>().setTransform(camTrf);

PhysicsBodyPtr pbody = body->getComponent<BodyComponent>().getPhysicsBody();
pbody->applyForce(camTrf.getRotation().getZAxis().xyz() * -1500.0f, Vec3(0.0f, 0.0f, 0.0f));

body->addChild(monkey);
}

Binary file not shown.
@@ -0,0 +1,68 @@
local scene = getSceneGraph()
local events = getEventManager()
local rot
local node
local inst
local lcomp

node = scene:newReflectionProbeNode("reflprobe0", Vec4.new(-12.6741, -12.6741, -12.6741, 0), Vec4.new(12.6741, 12.6741, 12.6741, 0))
trf = Transform.new()
trf:setOrigin(Vec4.new(0, 9.1132, 0, 0))
rot = Mat3x4.new()
rot:setAll(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0)
trf:setRotation(rot)
trf:setScale(1)
node:getSceneNodeBase():getMoveComponent():setLocalTransform(trf)

node = scene:newModelNode("floorMaterial-materialnone0", "assets/floorMaterial-material.ankimdl")
trf = Transform.new()
trf:setOrigin(Vec4.new(0, 0, 0, 0))
rot = Mat3x4.new()
rot:setAll(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0)
trf:setRotation(rot)
trf:setScale(1)
node:getSceneNodeBase():getMoveComponent():setLocalTransform(trf)
node = scene:newStaticCollisionNode("floorMaterial-materialnone0_cl", "assets/floor.ankicl", trf)

node = scene:newModelNode("wallsMaterial_001-materialnone1", "assets/wallsMaterial_001-material.ankimdl")
trf = Transform.new()
trf:setOrigin(Vec4.new(0, 9.10935, 0, 0))
rot = Mat3x4.new()
rot:setAll(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0)
trf:setRotation(rot)
trf:setScale(1)
node:getSceneNodeBase():getMoveComponent():setLocalTransform(trf)

node = scene:newModelNode("SuzanneMaterial-materialnone2", "assets/SuzanneMaterial-material.ankimdl")
trf = Transform.new()
trf:setOrigin(Vec4.new(-23.0149, 9.70113, 0, 0))
rot = Mat3x4.new()
rot:setAll(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0)
trf:setRotation(rot)
trf:setScale(1)
node:getSceneNodeBase():getMoveComponent():setLocalTransform(trf)
node = scene:newStaticCollisionNode("SuzanneMaterial-materialnone2_cl", "assets/Suzanne.ankicl", trf)

node = scene:newPointLightNode("Lamp")
lcomp = node:getSceneNodeBase():getLightComponent()
lcomp:setDiffuseColor(Vec4.new(100, 100, 100, 1))
lcomp:setRadius(30.0003)
trf = Transform.new()
trf:setOrigin(Vec4.new(4.07624, 5.90386, -1.00545, 0))
rot = Mat3x4.new()
rot:setAll(-0.290865, -0.771075, 0.566429, 0, -0.0551891, 0.604562, 0.794644, 0, -0.955171, 0.199873, -0.2184, 0)
trf:setRotation(rot)
trf:setScale(1)
node:getSceneNodeBase():getMoveComponent():setLocalTransform(trf)
lcomp:setShadowEnabled(1)

node = scene:newPerspectiveCameraNode("Camera")
scene:setActiveCameraNode(node:getSceneNodeBase())
node:setAll(1.22173, 1.0 / getMainRenderer():getAspectRatio() * 1.22173, 0.1, 100)
trf = Transform.new()
trf:setOrigin(Vec4.new(7.48113, 5.34367, 6.50764, 0))
rot = Mat3x4.new()
rot:setAll(0.685921, -0.323983, 0.651573, 0, 0, 0.895416, 0.44523, 0, -0.727676, -0.305392, 0.614184, 0)
trf:setRotation(rot)
trf:setScale(1)
node:getSceneNodeBase():getMoveComponent():setLocalTransform(trf)
@@ -42,6 +42,7 @@ class PhysicsBody : public PhysicsObject
void setTransform(const Transform& trf)
{
m_trf = trf;
m_body->setWorldTransform(toBt(trf));
}

F32 getFriction() const
@@ -69,6 +70,11 @@ class PhysicsBody : public PhysicsObject
m_materialBits = bits;
}

void applyForce(const Vec3& force, const Vec3& relPos)
{
m_body->applyForce(toBt(force), toBt(relPos));
}

private:
class MotionState;

@@ -19,12 +19,14 @@ PhysicsSphere::PhysicsSphere(PhysicsWorld* world, F32 radius)
: PhysicsCollisionShape(world)
{
m_shape = getAllocator().newInstance<btSphereShape>(radius);
m_shape->setMargin(getWorld().getCollisionMargin());
}

PhysicsBox::PhysicsBox(PhysicsWorld* world, const Vec3& extend)
: PhysicsCollisionShape(world)
{
m_shape = getAllocator().newInstance<btBoxShape>(toBt(extend));
m_shape->setMargin(getWorld().getCollisionMargin());
}

PhysicsTriangleSoup::PhysicsTriangleSoup(
@@ -42,12 +44,14 @@ PhysicsTriangleSoup::PhysicsTriangleSoup(

// Create the dynamic shape
btGImpactMeshShape* shape = getAllocator().newInstance<btGImpactMeshShape>(m_mesh);
shape->setMargin(getWorld().getCollisionMargin());
shape->updateBound();
m_shape = shape;

// And the static one
btBvhTriangleMeshShape* triShape = getAllocator().newInstance<btBvhTriangleMeshShape>(m_mesh, true);
m_staticShape = triShape;
m_staticShape->setMargin(getWorld().getCollisionMargin());
}

PhysicsTriangleSoup::~PhysicsTriangleSoup()
@@ -53,6 +53,11 @@ class PhysicsWorld
m_forDeletion.pushBack(m_alloc, obj);
}

F32 getCollisionMargin() const
{
return 0.04;
}

private:
HeapAllocator<U8> m_alloc;

0 comments on commit 8c0d0f1

Please sign in to comment.
You can’t perform that action at this time.