[Orxonox-commit 333] r2954 - branches/gametypes/src/orxonox/objects/worldentities
Aurelian at orxonox.net
Aurelian at orxonox.net
Mon May 4 17:28:59 CEST 2009
Author: Aurelian
Date: 2009-05-04 17:28:59 +0200 (Mon, 04 May 2009)
New Revision: 2954
Added:
branches/gametypes/src/orxonox/objects/worldentities/ForceField.cc
branches/gametypes/src/orxonox/objects/worldentities/ForceField.h
Modified:
branches/gametypes/src/orxonox/objects/worldentities/CMakeLists.txt
branches/gametypes/src/orxonox/objects/worldentities/MobileEntity.cc
branches/gametypes/src/orxonox/objects/worldentities/MobileEntity.h
Log:
ForceField not working jet, but no errors...
Modified: branches/gametypes/src/orxonox/objects/worldentities/CMakeLists.txt
===================================================================
--- branches/gametypes/src/orxonox/objects/worldentities/CMakeLists.txt 2009-05-04 15:04:58 UTC (rev 2953)
+++ branches/gametypes/src/orxonox/objects/worldentities/CMakeLists.txt 2009-05-04 15:28:59 UTC (rev 2954)
@@ -22,6 +22,7 @@
PongCenterpoint.cc
PongBall.cc
PongBat.cc
+ ForceField.cc
)
ADD_SUBDIRECTORY(pawns)
Added: branches/gametypes/src/orxonox/objects/worldentities/ForceField.cc
===================================================================
--- branches/gametypes/src/orxonox/objects/worldentities/ForceField.cc (rev 0)
+++ branches/gametypes/src/orxonox/objects/worldentities/ForceField.cc 2009-05-04 15:28:59 UTC (rev 2954)
@@ -0,0 +1,90 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Aurelian Jaggi
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "ForceField.h"
+#include "core/XMLPort.h"
+
+#include "core/CoreIncludes.h"
+#include "objects/worldentities/MobileEntity.h"
+
+namespace orxonox
+{
+ CreateFactory(ForceField);
+
+ ForceField::ForceField(BaseObject* creator) : StaticEntity(creator)
+ {
+ RegisterObject(ForceField);
+
+ //Standard Values
+ this->setDirection(Vector3::ZERO);
+ velocity_ = 1000;
+ diameter_ = 500;
+ length_ = 1000;
+ }
+
+ ForceField::~ForceField() {}
+
+ void ForceField::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(ForceField, XMLPort, xmlelement, mode);
+
+ //For correct xml import use: position, direction, velocity, scale
+
+ XMLPortParam(ForceField, "velocity", setVelocity, getVelocity, xmlelement, mode).defaultValues(100);
+ XMLPortParam(ForceField, "diameter", setDiameter, getDiameter, xmlelement, mode).defaultValues(20);
+ XMLPortParam(ForceField, "length" , setLength , getLength , xmlelement, mode).defaultValues(500);
+ }
+
+ void ForceField::tick(float dt)
+ {
+ for (ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it)
+ {
+ //calculate from
+ Vector3 directionVec = this->getOrientation() * WorldEntity::FRONT;
+ directionVec.normalise();
+
+ Vector3 distanceVec = it->getWorldPosition() - (this->getWorldPosition() + (this->length_ / 2 * directionVec));
+
+ //distance from centervector of the field (
+ float distFromCenterVec = ((it->getWorldPosition() - this->getWorldPosition()).crossProduct(directionVec)).length();
+
+ if (distanceVec.length() < this->length_ / 2 && distFromCenterVec < diameter_ / 2)
+ {
+ //normalize distance from center
+ it->applyCentralForce(((diameter_ / 2 - distFromCenterVec) / diameter_) * directionVec * velocity_);
+ COUT(0) << "Forfce aplied" << std::endl;
+ }
+
+ }
+ }
+}
+
+
+
+
+
Added: branches/gametypes/src/orxonox/objects/worldentities/ForceField.h
===================================================================
--- branches/gametypes/src/orxonox/objects/worldentities/ForceField.h (rev 0)
+++ branches/gametypes/src/orxonox/objects/worldentities/ForceField.h 2009-05-04 15:28:59 UTC (rev 2954)
@@ -0,0 +1,72 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Aurelian Jaggi
+ * Co-authors:
+ * ...
+ *
+ */
+
+
+#ifndef _ForceField_H__
+#define _ForceField_H__
+
+#include "StaticEntity.h"
+#include "objects/Tickable.h"
+
+namespace orxonox
+{
+ class _OrxonoxExport ForceField : public StaticEntity, public Tickable
+ {
+ public:
+ ForceField(BaseObject* creator);
+ virtual ~ForceField();
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a CheckPoint object through XML.
+ virtual void tick(float dt);
+
+ inline void setVelocity(float vel)
+ { this->velocity_ = vel; }
+
+ inline float getVelocity()
+ { return velocity_; }
+
+ inline void setDiameter(float diam)
+ { this->diameter_ = diam; }
+
+ inline float getDiameter()
+ { return diameter_; }
+
+ inline void setLength(float l)
+ { this->length_ = l; }
+
+ inline float getLength()
+ { return length_; }
+
+ private:
+ float velocity_;
+ float diameter_;
+ float length_;
+ };
+}
+
+#endif
+
Modified: branches/gametypes/src/orxonox/objects/worldentities/MobileEntity.cc
===================================================================
--- branches/gametypes/src/orxonox/objects/worldentities/MobileEntity.cc 2009-05-04 15:04:58 UTC (rev 2953)
+++ branches/gametypes/src/orxonox/objects/worldentities/MobileEntity.cc 2009-05-04 15:28:59 UTC (rev 2954)
@@ -165,6 +165,12 @@
this->angularAcceleration_ = acceleration;
}
+ void MobileEntity::applyCentralForce(const Vector3& force)
+ {
+ if (this->isDynamic())
+ this->physicalBody_->applyCentralForce(btVector3(force.x * this->getMass(), force.y * this->getMass(), force.z * this->getMass()));
+ }
+
bool MobileEntity::isCollisionTypeLegal(WorldEntity::CollisionType type) const
{
if (type == WorldEntity::Static)
Modified: branches/gametypes/src/orxonox/objects/worldentities/MobileEntity.h
===================================================================
--- branches/gametypes/src/orxonox/objects/worldentities/MobileEntity.h 2009-05-04 15:04:58 UTC (rev 2953)
+++ branches/gametypes/src/orxonox/objects/worldentities/MobileEntity.h 2009-05-04 15:28:59 UTC (rev 2954)
@@ -74,6 +74,10 @@
inline const Vector3& getAngularAcceleration() const
{ return this->angularAcceleration_; }
+ void applyCentralForce(const Vector3& force);
+ inline void applyCentralForce(float x, float y, float z)
+ { this->applyCentralForce(Vector3(x, y, z)); }
+
inline void setRotationRate(Degree rate)
{ this->setAngularVelocity(this->getAngularVelocity().normalisedCopy() * rate.valueRadians()); }
inline Degree getRotationRate() const
More information about the Orxonox-commit
mailing list