git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / common / engine / PhysicsParticle.cpp
blob732ab272f00f3fc48d166b48f43b9c8807fb9b3e
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <engine/PhysicsParticle.h>
22 #include <engine/ScorchedContext.h>
24 PhysicsParticle::PhysicsParticle() :
25 Action("PhysicsParticle"),
26 collision_(false), totalActionTime_(0)
31 PhysicsParticle::~PhysicsParticle()
36 void PhysicsParticle::setPhysics(
37 PhysicsParticleInfo info,
38 FixedVector &position, FixedVector &velocity,
39 fixed sphereSize, fixed sphereDensity, fixed windFactor,
40 bool underGroundCollision, bool rotateOnCollision,
41 bool wallCollision)
43 physicsObject_.setPhysics(
44 info,
45 *context_,
46 position, velocity,
47 sphereSize, sphereDensity, windFactor,
48 underGroundCollision,
49 rotateOnCollision,
50 wallCollision);
51 physicsObject_.setHandler(this);
54 void PhysicsParticle::applyForce(FixedVector &force)
56 physicsObject_.applyForce(force);
59 void PhysicsParticle::collision(PhysicsParticleObject &position,
60 ScorchedCollisionId collisionId)
62 collision_ = true;
65 void PhysicsParticle::setCurrentPosition(FixedVector &position)
67 physicsObject_.setPosition(position);
70 FixedVector &PhysicsParticle::getCurrentPosition()
72 return physicsObject_.getPosition();
75 FixedVector &PhysicsParticle::getCurrentVelocity()
77 return physicsObject_.getVelocity();
80 FixedVector4 &PhysicsParticle::getRotationQuat()
82 return physicsObject_.getRotationQuat();
85 void PhysicsParticle::simulate(fixed frameTime, bool &remove)
87 physicsObject_.simulate(frameTime);
88 Action::simulate(frameTime, remove);
89 if (collision_) remove = true;
90 totalActionTime_ += frameTime;
91 if (totalActionTime_ > 30) remove = true;
94 PhysicsParticleReferenced::PhysicsParticleReferenced()
98 PhysicsParticleReferenced::~PhysicsParticleReferenced()