Removed separate controller class
This commit is contained in:
@@ -1,112 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <OgreMath.h>
|
||||
#include "GameData.h"
|
||||
#include "character.h"
|
||||
#include "controller.h"
|
||||
#define CAM_HEIGHT 1.6f // height of camera above character's center of mass
|
||||
#define RUN_SPEED 17 // character running speed in units per second
|
||||
#define TURN_SPEED 500.0f // character turning in degrees per second
|
||||
#define ANIM_FADE_SPEED \
|
||||
7.5f // animation crossfade speed in % of full weight per second
|
||||
CharacterController::CharacterController(Ogre::SceneNode *camNode,
|
||||
Ogre::Camera *cam,
|
||||
Ogre::SceneManager *scnMgr,
|
||||
Ogre::Bullet::DynamicsWorld *world)
|
||||
: mCameraNode(camNode)
|
||||
, mCamera(cam)
|
||||
, mScnMgr(scnMgr)
|
||||
, mPivotPitch(0)
|
||||
, mWorld(world)
|
||||
, mUpdate(false)
|
||||
{
|
||||
setupCamera();
|
||||
Ogre::Root::getSingleton().addFrameListener(this);
|
||||
}
|
||||
CharacterController::~CharacterController()
|
||||
{
|
||||
}
|
||||
void CharacterController::setupCamera()
|
||||
{
|
||||
}
|
||||
static uint32_t control;
|
||||
static ECS::Vector2 mouse{ 0, 0 };
|
||||
static float wheel_y;
|
||||
static bool mouse_moved = false, wheel_moved = false;
|
||||
bool CharacterController::keyPressed(const OgreBites::KeyboardEvent &evt)
|
||||
{
|
||||
OgreBites::Keycode key = evt.keysym.sym;
|
||||
if (key == 'w')
|
||||
control |= 1;
|
||||
else if (key == 'a')
|
||||
control |= 2;
|
||||
else if (key == 's')
|
||||
control |= 4;
|
||||
else if (key == 'd')
|
||||
control |= 8;
|
||||
else if (key == OgreBites::SDLK_LSHIFT)
|
||||
control |= 16;
|
||||
return true;
|
||||
}
|
||||
bool CharacterController::keyReleased(const OgreBites::KeyboardEvent &evt)
|
||||
{
|
||||
OgreBites::Keycode key = evt.keysym.sym;
|
||||
if (key == 'w')
|
||||
control &= ~1;
|
||||
else if (key == 'a')
|
||||
control &= ~2;
|
||||
else if (key == 's')
|
||||
control &= ~4;
|
||||
else if (key == 'd')
|
||||
control &= ~8;
|
||||
else if (key == OgreBites::SDLK_LSHIFT)
|
||||
control &= ~16;
|
||||
return true;
|
||||
}
|
||||
bool CharacterController::mouseMoved(const OgreBites::MouseMotionEvent &evt)
|
||||
{
|
||||
mouse.x = evt.xrel;
|
||||
mouse.y = evt.yrel;
|
||||
mouse_moved = true;
|
||||
return true;
|
||||
}
|
||||
bool CharacterController::mouseWheelRolled(const OgreBites::MouseWheelEvent &evt)
|
||||
{
|
||||
wheel_y = evt.y;
|
||||
wheel_moved = true;
|
||||
return true;
|
||||
}
|
||||
bool CharacterController::mousePressed(const OgreBites::MouseButtonEvent &evt)
|
||||
{
|
||||
std::cout << "Mouse press\n";
|
||||
return false;
|
||||
}
|
||||
void CharacterController::frameRendered(const Ogre::FrameEvent &evt)
|
||||
{
|
||||
if (mUpdate) {
|
||||
updateBody(evt.timeSinceLastFrame);
|
||||
updateCamera(evt.timeSinceLastFrame);
|
||||
}
|
||||
}
|
||||
bool CharacterController::frameStarted(const Ogre::FrameEvent &evt)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void CharacterController::updateBody(Ogre::Real delta)
|
||||
{
|
||||
ECS::Input &input = ECS::get().get_mut<ECS::Input>();
|
||||
input.control = control;
|
||||
input.mouse = mouse;
|
||||
mouse.x = 0;
|
||||
mouse.y = 0;
|
||||
input.wheel_y = wheel_y;
|
||||
wheel_y = 0;
|
||||
input.mouse_moved = mouse_moved;
|
||||
input.wheel_moved = wheel_moved;
|
||||
}
|
||||
struct EntityCollisionListener {
|
||||
const Ogre::MovableObject *entity;
|
||||
Ogre::Bullet::CollisionListener *listener;
|
||||
};
|
||||
void CharacterController::updateCamera(Ogre::Real delta)
|
||||
{
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
#include <flecs.h>
|
||||
#include <Ogre.h>
|
||||
#include <OgreInput.h>
|
||||
#include <OgreFrameListener.h>
|
||||
#include "GameData.h"
|
||||
class CharacterController : public OgreBites::InputListener,
|
||||
Ogre::FrameListener {
|
||||
Ogre::SceneNode *mCameraNode;
|
||||
Ogre::Camera *mCamera;
|
||||
Ogre::SceneManager *mScnMgr;
|
||||
|
||||
Ogre::SceneNode *mCameraPivot;
|
||||
Ogre::SceneNode *mCameraGoal;
|
||||
Ogre::Real mPivotPitch;
|
||||
Ogre::Real
|
||||
mTimer; // general timer to see how long animations have been playing
|
||||
Ogre::Bullet::DynamicsWorld *mWorld;
|
||||
Ogre::Vector3 rootMotion;
|
||||
Ogre::Quaternion rootRotation;
|
||||
// btRigidBody *mRigidBody;
|
||||
#if 0
|
||||
Ogre::Vector3 gvelocity;
|
||||
#endif
|
||||
|
||||
bool mUpdate;
|
||||
|
||||
public:
|
||||
CharacterController(Ogre::SceneNode *camNode, Ogre::Camera *cam,
|
||||
Ogre::SceneManager *scnMgr,
|
||||
Ogre::Bullet::DynamicsWorld *world);
|
||||
~CharacterController();
|
||||
|
||||
private:
|
||||
void setupCamera();
|
||||
|
||||
public:
|
||||
bool keyPressed(const OgreBites::KeyboardEvent &evt) override;
|
||||
bool keyReleased(const OgreBites::KeyboardEvent &evt) override;
|
||||
bool mouseMoved(const OgreBites::MouseMotionEvent &evt) override;
|
||||
bool mouseWheelRolled(const OgreBites::MouseWheelEvent &evt) override;
|
||||
bool mousePressed(const OgreBites::MouseButtonEvent &evt) override;
|
||||
bool frameStarted(const Ogre::FrameEvent &evt) override;
|
||||
void frameRendered(const Ogre::FrameEvent &evt) override;
|
||||
|
||||
private:
|
||||
void updateBody(Ogre::Real deltaTime);
|
||||
void updateCamera(Ogre::Real deltaTime);
|
||||
inline btQuaternion convert(const Ogre::Quaternion &q)
|
||||
{
|
||||
return btQuaternion(q.x, q.y, q.z, q.w);
|
||||
}
|
||||
inline btVector3 convert(const Ogre::Vector3 &v)
|
||||
{
|
||||
return btVector3(v.x, v.y, v.z);
|
||||
}
|
||||
inline btTransform convert(const Ogre::Quaternion &q,
|
||||
const Ogre::Vector3 &v)
|
||||
{
|
||||
btQuaternion mq = convert(q);
|
||||
btVector3 mv = convert(v);
|
||||
return btTransform(mq, mv);
|
||||
}
|
||||
inline Ogre::Quaternion convert(const btQuaternion &q)
|
||||
{
|
||||
return Ogre::Quaternion(q.w(), q.x(), q.y(), q.z());
|
||||
}
|
||||
inline Ogre::Vector3 convert(const btVector3 &v)
|
||||
{
|
||||
return Ogre::Vector3(v.x(), v.y(), v.z());
|
||||
}
|
||||
inline void convert(const btTransform &from, Ogre::Quaternion &q,
|
||||
Ogre::Vector3 &v)
|
||||
{
|
||||
q = convert(from.getRotation());
|
||||
v = convert(from.getOrigin());
|
||||
}
|
||||
|
||||
public:
|
||||
void enableUpdates()
|
||||
{
|
||||
mUpdate = true;
|
||||
}
|
||||
void disableUpdates()
|
||||
{
|
||||
mUpdate = false;
|
||||
}
|
||||
bool getUpdates()
|
||||
{
|
||||
return mUpdate;
|
||||
}
|
||||
Ogre::Vector3 getPosition() const
|
||||
{
|
||||
flecs::entity player =
|
||||
ECS::get().lookup("ECS::CharacterModule::player");
|
||||
return player.get<ECS::CharacterBase>().mBodyNode->getPosition();
|
||||
}
|
||||
Ogre::Quaternion getRotation() const
|
||||
{
|
||||
flecs::entity player =
|
||||
ECS::get().lookup("ECS::CharacterModule::player");
|
||||
return player.get<ECS::CharacterBase>()
|
||||
.mBodyNode->getOrientation();
|
||||
}
|
||||
class ClosestNotMeRayResultCallback
|
||||
: public btCollisionWorld::ClosestRayResultCallback {
|
||||
btCollisionObject *mMe;
|
||||
|
||||
public:
|
||||
ClosestNotMeRayResultCallback(btCollisionObject *me,
|
||||
const btVector3 &from,
|
||||
const btVector3 &to)
|
||||
: btCollisionWorld::ClosestRayResultCallback(from, to)
|
||||
{
|
||||
mMe = me;
|
||||
}
|
||||
virtual btScalar
|
||||
addSingleResult(btCollisionWorld::LocalRayResult &rayResult,
|
||||
bool normalInWorldSpace)
|
||||
{
|
||||
if (rayResult.m_collisionObject == mMe)
|
||||
return 1.0f;
|
||||
return ClosestRayResultCallback::addSingleResult(
|
||||
rayResult, normalInWorldSpace);
|
||||
}
|
||||
};
|
||||
bool checkGround()
|
||||
{
|
||||
flecs::entity player =
|
||||
ECS::get().lookup("ECS::CharacterModule::player");
|
||||
btVector3 from = player.get<ECS::CharacterBody>()
|
||||
.mGhostObject->getWorldTransform()
|
||||
.getOrigin() +
|
||||
btVector3(0, 0.2f, 0);
|
||||
btVector3 to = from + btVector3(0, -3000.0f, 0);
|
||||
ClosestNotMeRayResultCallback resultCallback(
|
||||
player.get<ECS::CharacterBody>().mGhostObject, from,
|
||||
to);
|
||||
player.get<ECS::CharacterBody>().mGhostObject->rayTest(
|
||||
from, to, resultCallback);
|
||||
// std::cout << (resultCallback.hasHit() ? "hit" : "no hit");
|
||||
// if (resultCallback.hasHit())
|
||||
// std::cout << " " << Ogre::Bullet::convert(resultCallback.m_hitPointWorld);
|
||||
// std::cout << "\n";
|
||||
return resultCallback.hasHit();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user