Skip to content

Commit

Permalink
Merge branch 'hotfix/#391_add_missing_docs'
Browse files Browse the repository at this point in the history
  • Loading branch information
tanzfisch committed Dec 22, 2023
2 parents 5c77543 + 80f97e9 commit c2869a8
Show file tree
Hide file tree
Showing 5 changed files with 287 additions and 11 deletions.
8 changes: 4 additions & 4 deletions examples/12_CharacterController/src/CharacterController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <igor/system/iApplication.h>
using namespace igor;

CharacterController::CharacterController(iNodePtr node, int64 materiaID, const iaMatrixd &startMatrix)
CharacterController::CharacterController(iNodePtr node, int64 materiaID, const iaMatrixd &matrix)
{
// setup character and attach camera to it
iaMatrixd transformCollision;
Expand All @@ -31,7 +31,7 @@ CharacterController::CharacterController(iNodePtr node, int64 materiaID, const i
_collisionCast = iPhysics::getInstance().createCapsule(_characterRadius, _characterRadius, _characterHeight - _stepHeight, transformCollision);

iNodeTransform *physicsTransform = iNodeManager::getInstance().createNode<iNodeTransform>();
physicsTransform->setMatrix(startMatrix);
physicsTransform->setMatrix(matrix);
_physicsTransformNodeID = physicsTransform->getID();
node->insertNode(physicsTransform);

Expand Down Expand Up @@ -96,12 +96,12 @@ iNodeTransform *CharacterController::getHeadTransform() const
return static_cast<iNodeTransform *>(iNodeManager::getInstance().getNode(_headTransformNodeID));
}

iNodeTransform *CharacterController::getLeftSholderTransform() const
iNodeTransform *CharacterController::getLeftShoulderTransform() const
{
return static_cast<iNodeTransform *>(iNodeManager::getInstance().getNode(_leftShoulderTransformNodeID));
}

iNodeTransform *CharacterController::getRightSholderTransform() const
iNodeTransform *CharacterController::getRightShoulderTransform() const
{
return static_cast<iNodeTransform *>(iNodeManager::getInstance().getNode(_rightShoulderTransformNodeID));
}
Expand Down
99 changes: 95 additions & 4 deletions examples/12_CharacterController/src/CharacterController.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <igor/igor.h>
using namespace igor;

/*! character controller
*/
class CharacterController
{

Expand All @@ -45,60 +47,149 @@ class CharacterController
Floor
};

CharacterController(iNodePtr parent, int64 materiaID, const iaMatrixd &startMatrix);
/*! init character controller
\param parent the parenting node in the scene
\param materialID physics material of character body
\param matrix initial position/orientation of character
*/
CharacterController(iNodePtr parent, int64 materiaID, const iaMatrixd &matrix);

/*! cleanup
*/
virtual ~CharacterController();

/*! sets a force to be applied next tick
\param force the force to apply
*/
void setForce(const iaVector3d &force);

/*! \returns the force to be applied next tick
*/
iaVector3d getForce() const;

/*! \returns root transform node of character
*/
iNodeTransform *getRootNode() const;

/*! \returns heading transform node of character
*/
iNodeTransform *getHeadingTransform() const;

/*! \returns pitch transform node of character
*/
iNodeTransform *getPitchTransform() const;

/*! \returns head transform node of character
*/
iNodeTransform *getHeadTransform() const;

iNodeTransform *getLeftSholderTransform() const;
iNodeTransform *getRightSholderTransform() const;
/*! \returns left shoulder transform node of character
*/
iNodeTransform *getLeftShoulderTransform() const;

/*! \returns right shoulder transform node of character
*/
iNodeTransform *getRightShoulderTransform() const;

/*! \returns current state od character
*/
State getState() const;

private:
/*! the height of the character
*/
float64 _characterHeight = 1.8;

/*! the radius of the character
*/
float64 _characterRadius = 0.3;

/// the height of a step that carachter can walk without jumping
/*! the height of a step that character can walk without jumping
*/
float64 _stepHeight = 0.3;

/*! target height
*/
float64 _targetHeight = _stepHeight + 0.1;

/*! head height
*/
float64 _headHeight = 1.8;

/*! mass of body
*/
float64 _mass = 100;

/*! state of character
*/
State _state = State::Air;

/*! force to be applied next tick
*/
iaVector3d _navigationForce;

/*! physics body handle
*/
uint64 _bodyID = iPhysicsBody::INVALID_PHYSICSBODY_ID;

/*! collision caster
*/
iPhysicsCollision *_collisionCast = nullptr;

/*! root transform node physics handle
*/
uint32 _physicsTransformNodeID = iNode::INVALID_NODE_ID;

/*! upper body physics handle
*/
uint32 _upperBodyTransformNodeID = iNode::INVALID_NODE_ID;

/*! heading transform node physics handle
*/
uint32 _headingTransformNodeID = iNode::INVALID_NODE_ID;

/*! pitch transform node physics handle
*/
uint32 _pitchTransformNodeID = iNode::INVALID_NODE_ID;

/*! head transform node physics handle
*/
uint32 _headTransformNodeID = iNode::INVALID_NODE_ID;

/*! left shoulder transform node physics handle
*/
uint32 _leftShoulderTransformNodeID = iNode::INVALID_NODE_ID;

/*! right shoulder transform node physics handle
*/
uint32 _rightShoulderTransformNodeID = iNode::INVALID_NODE_ID;

/*! gets floor contact point
\returns height above ground
\param[out] point contact point
\param[out] normal contact normal
*/
float64 getFloorContactPoint(iaVector3d &point, iaVector3d &normal);

/*! helper to filter out bodies
*/
unsigned onRayPreFilter(iPhysicsBody *body, iPhysicsCollision *collision, const void *userData);

/*! apply force and torque per tick
\param body the body that is affected
\param timestep the time step
*/
void onApplyForceAndTorque(iPhysicsBody *body, float64 timestep);

/*! apply/submit constraints to the characters body
\param joint the affected joint
\param timestep the time step
*/
void onSubmitConstraints(iPhysicsJoint *joint, float64 timestep);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void ExampleCharacterController::onInit()
gunTransform->scale(0.04, 0.04, 0.04);
iNodeModel *gun = iNodeManager::getInstance().createNode<iNodeModel>();
gun->setModel("example_model_M4A1-S");
_characterController->getRightSholderTransform()->insertNode(gunTransform);
_characterController->getRightShoulderTransform()->insertNode(gunTransform);
gunTransform->insertNode(gun);

// create a skybox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
#include <ExampleBase.h>

#include "CharacterController.h"


/*! character controller example
*/
class ExampleCharacterController : public ExampleBase
{

Expand Down
Loading

0 comments on commit c2869a8

Please sign in to comment.