60 m_weapon = parentScene()->createGameObjectWithNode(
"AK-47",
false);
62 m_weapon->setRotation(0, -90.0f, 0);
64 m_weapon->setScale(0.5f);
81 float left_joystick_y =
INPUTMANAGER->getLeftJoystick()->getY();
82 float left_joystick_x =
INPUTMANAGER->getLeftJoystick()->getX();
84 float right_joystick_y =
INPUTMANAGER->getRightJoystick()->getY();
85 float right_joystick_x =
INPUTMANAGER->getRightJoystick()->getX();
87 float rot_factor = 2.5f;
89 left_joystick_y -= (
INPUTMANAGER->getKeyDown(
'W') ? 1.0f : 0.0f);
90 left_joystick_y += (
INPUTMANAGER->getKeyDown(
'S') ? 1.0f : 0.0f);
91 left_joystick_x -= (
INPUTMANAGER->getKeyDown(
'A') ? 1.0f : 0.0f);
92 left_joystick_x += (
INPUTMANAGER->getKeyDown(
'D') ? 1.0f : 0.0f);
95 float dx = (float)(current_mouse_position->
x - m_previousMousePosition->
x) * k_InputManager_MouseSensitivity;
96 float dy = (float)(current_mouse_position->
y - m_previousMousePosition->
y) * k_InputManager_MouseSensitivity;
100 right_joystick_x += dx;
101 right_joystick_y += dy * 0.7f;
104 if (right_joystick_x != 0) {
106 camera_transform->
rotateY(right_joystick_x* rot_factor);
109 if (right_joystick_y != 0) {
111 camera_transform->
rotateX(right_joystick_y* rot_factor);
114 if (left_joystick_y != 0) {
118 if (left_joystick_x != 0) {
128 m_previousMousePosition->
x = current_mouse_position->
x;
129 m_previousMousePosition->
y = current_mouse_position->
y;
148 return (recoil_action == NULL);
163 m_weapon->runAction(recoil_action);
167 CGameObject* bullet = parentScene()->createGameObjectWithNode(
"bullet",
true,
"CBullet");
171 bullet->bulletProperties.
setMass(0.1f);
172 bullet->deployIntoDynamicsWorld();
174 bullet->bulletProperties.
rigidBody()->activate(
true);
175 bullet->setPosition(bullet->position());
176 bullet->
transform().
moveZ(-6.0f, Transform::TransformMode::LOCAL);
180 btVector3
forward = btMatrix3x3(
transform().localRotation()) * btVector3(0,0,-100.0f);
181 btVector3
start = position(Transform::UnitType::PHYSICSWORLD);
182 btVector3 end = start +
forward;
184 btCollisionWorld::ClosestRayResultCallback RayCallback( start, end );
185 parentScene()->dynamicsWorld()->rayTest(start, end, RayCallback);
187 if(RayCallback.hasHit()) {
189 LOG(
"Bullet hit object named: %s", qPrintable(game_obj->objectName()));
192 bool is_enemy = enemy != NULL;
199 btVector3 centerOfMass = bullet->bulletProperties.
rigidBody()->getCenterOfMassPosition();
200 btVector3 force = btMatrix3x3(
transform().localRotation()) * btVector3(0,0,-5.0f);
201 btVector3 hitPoint = RayCallback.m_hitPointWorld;
202 bullet->bulletProperties.
rigidBody()->applyImpulse(force * 4.0f, hitPoint - centerOfMass);
208 recoil_action = NULL;
std::string getCameraId() const
virtual void damageReceived(int damage)
static float clampf(float value, float min, float max)
CSequence * initHavingActions(CFiniteTimeAction *firstAction, CFiniteTimeAction *secondAction)
CameraTransform & transform()
virtual bool nextShotReady()
btRigidBody * rigidBody() const
virtual CActionInterval * reverse()
void onActionDone(CAction *action)
virtual void postWorldUpdate()
static const std::string k_PlayerCameraId
void updatePositionAndOrientation()