diff --git a/CrystalPoint.cpp b/CrystalPoint.cpp
index 867a0b6..0d3bd76 100644
--- a/CrystalPoint.cpp
+++ b/CrystalPoint.cpp
@@ -40,6 +40,7 @@ void CrystalPoint::draw()
glLoadIdentity();
worldhandler->draw();
+ player->draw();
//cursor->draw();
@@ -79,6 +80,32 @@ void CrystalPoint::update()
if (keyboardState.keys['q']) player->setPosition(1, deltaTime*speed, true);
if (keyboardState.keys['e']) player->setPosition(-1, deltaTime*speed, true);
+ Controller *leftcontroller = controller.getLeftController();
+ if (leftcontroller != nullptr) {
+ Vec2f *leftControllerJoystick = &leftcontroller->joystick;
+
+ if (leftcontroller->joystickButton) {
+ controller.rumble(leftcontroller->controllerId, 100, 100);
+ }
+
+ if (leftControllerJoystick->y > 0.3) {
+ player->setPosition(270, leftControllerJoystick->y*deltaTime, false);
+ }
+ else if (leftControllerJoystick->y < -0.3) {
+ player->setPosition(90, leftControllerJoystick->y*-1 * deltaTime, false);
+ }
+ if (leftControllerJoystick->x > 0.3) {
+ player->setPosition(180, leftControllerJoystick->x*deltaTime, false);
+ }
+ else if (leftControllerJoystick->x < -0.3) {
+ player->setPosition(0, leftControllerJoystick->x*-1 * deltaTime, false);
+ }
+
+ player->leftWeapon->rotateWeapon(Vec3f(leftcontroller->ypr.y + 140, 0, -leftcontroller->ypr.z));
+
+ }
+
+
if (!worldhandler->isPlayerPositionValid())
player->position = oldPosition;
diff --git a/CrystalPoint.h b/CrystalPoint.h
index 5437d5c..1e36bea 100644
--- a/CrystalPoint.h
+++ b/CrystalPoint.h
@@ -5,6 +5,7 @@ class SoundSystem;
class Player;
#include "Vector.h"
#include "SoundSystem.h"
+#include "ControllerHandler.h"
class KeyboardState
{
@@ -25,6 +26,7 @@ public:
WorldHandler* worldhandler;
Player* player;
+ ControllerHandler controller;
static int width, height;
KeyboardState keyboardState;
diff --git a/CrystalPoint.vcxproj b/CrystalPoint.vcxproj
index 3c1aa17..28dc29f 100644
--- a/CrystalPoint.vcxproj
+++ b/CrystalPoint.vcxproj
@@ -178,6 +178,7 @@
+
@@ -206,6 +207,7 @@
+
diff --git a/CrystalPoint.vcxproj.filters b/CrystalPoint.vcxproj.filters
index 0c64c07..2811cbc 100644
--- a/CrystalPoint.vcxproj.filters
+++ b/CrystalPoint.vcxproj.filters
@@ -105,6 +105,9 @@
Source Files\Serial
+
+ Source Files
+
@@ -185,6 +188,9 @@
Header Files
+
+ Header Files
+
diff --git a/Player.cpp b/Player.cpp
index f6de1c3..10f1b2d 100644
--- a/Player.cpp
+++ b/Player.cpp
@@ -12,6 +12,9 @@ Player::Player()
xp = 75;
level = 10;
crystals = 0;
+
+ leftWeapon = new Weapon("models/weapons/ZwaardMetTextures/TextureZwaard.obj", 1, position, rotation, Vec3f(4.5, -8, -1), Vec3f(-2.0f, 6.0f, -2.1f), Vec2f(170, 70), Vec2f(20, -80));
+ leftWeapon->rotateWeapon(Vec3f(150, 0, 60));
}
Player* Player::getInstance()
@@ -42,6 +45,8 @@ void Player::setCamera()
glRotatef(rotation.y, 0, 1, 0);
glTranslatef(-position.x, -position.y, -position.z);
+ leftWeapon->rotate(rotation);
+
}
void Player::setPosition(float angle, float fac, bool height)
@@ -53,4 +58,10 @@ void Player::setPosition(float angle, float fac, bool height)
position.x -= (float)cos((rotation.y + angle) / 180 * M_PI) * fac;
position.z -= (float)sin((rotation.y + angle) / 180 * M_PI) * fac;
}
+
+ leftWeapon->move(position);
+}
+
+void Player::draw() {
+ leftWeapon->draw();
}
\ No newline at end of file
diff --git a/Player.h b/Player.h
index 374d1dd..f2b24f6 100644
--- a/Player.h
+++ b/Player.h
@@ -1,7 +1,6 @@
#pragma once
#include "Vector.h"
-
-class Model;
+#include "Weapon.h"
class Player
{
@@ -13,6 +12,7 @@ public:
void setCamera();
void setPosition(float angle, float fac, bool height);
+ void draw(void);
static Player* getInstance(void);
static void init(void);
@@ -20,8 +20,8 @@ public:
Vec3f position;
Vec2f rotation;
- Model* leftWeapon;
- Model* rightWeapon;
+ Weapon* leftWeapon;
+ Weapon* rightWeapon;
float health;
float xp;
diff --git a/Weapon.cpp b/Weapon.cpp
new file mode 100644
index 0000000..5413758
--- /dev/null
+++ b/Weapon.cpp
@@ -0,0 +1,86 @@
+//
+// Created by janco on 25-5-16.
+//
+
+#include "Weapon.h"
+#include "Model.h"
+#include
+#include
+#include
+
+
+Weapon::Weapon(std::string modelFilename, float scale, Vec3f location, Vec2f rotation,
+ Vec3f offsetPlayer, Vec3f ankerPoint,
+ Vec2f maxRotation, Vec2f minRotation){
+ weaponmodel = Model::load(modelFilename);
+ rotate(rotation);
+ move(location);
+ this->scale = scale;
+
+ this->offsetPlayer = offsetPlayer;
+ this->ankerPoint = ankerPoint;
+ this->maxRotation = maxRotation;
+ this->minRotation = minRotation;
+};
+
+Weapon::~Weapon(){
+
+}
+
+void Weapon::rotateWeapon(Vec3f rotation){
+ if(rotation.x < maxRotation.x && rotation.x > minRotation.x){
+ rotationWeapon.x = rotation.x;
+ }
+ if(rotation.z < maxRotation.y && rotation.z > minRotation.y){
+ rotationWeapon.z = rotation.z;
+ }
+ rotationWeapon.y = rotation.y;
+}
+
+void Weapon::rotate(Vec2f rotation){
+ this->rotation.y = -rotation.y;
+}
+
+void Weapon::move(Vec3f location){
+ position = location;
+}
+
+void Weapon::draw(){
+ if (weaponmodel != nullptr)
+ {
+ glPushMatrix();
+
+ //Player position and rotation
+ glTranslatef(position.x, position.y, position.z);
+ glRotatef(rotation.x, 1, 0, 0);
+ glRotatef(rotation.y, 0, 1, 0);
+ glRotatef(rotation.z, 0, 0, 1);
+
+ //offset from player
+ glTranslatef(offsetPlayer.x, offsetPlayer.y, offsetPlayer.z);
+
+ //Rotate weapon itself, from specific anker point
+ glTranslatef(ankerPoint.x, ankerPoint.y, ankerPoint.z);
+ glRotatef(rotationWeapon.z, 0, 0, 1);
+ glRotatef(rotationWeapon.y, 0, 1, 0);
+ glRotatef(rotationWeapon.x, 1, 0, 0);
+ glTranslatef(-ankerPoint.x, -ankerPoint.y, -ankerPoint.z);
+
+ glScalef(scale, scale, scale);
+
+ weaponmodel->draw();
+
+ //Test code for finding anker point
+/* glColor3ub(255, 255, 0);
+ glTranslatef(ankerPoint.x, ankerPoint.y, ankerPoint.z);
+ glBegin(GL_LINES);
+ glVertex2f(0, 4);
+ glVertex2f(0, -4);
+ glVertex2f(4, 0);
+ glVertex2f(-4, 0);
+ glEnd();*/
+
+ glPopMatrix();
+
+ }
+}
diff --git a/Weapon.h b/Weapon.h
new file mode 100644
index 0000000..8d5e672
--- /dev/null
+++ b/Weapon.h
@@ -0,0 +1,34 @@
+//
+// Created by janco on 25-5-16.
+//
+
+#ifndef CRYSTALPOINT_WEAPON_H
+#define CRYSTALPOINT_WEAPON_H
+
+#include "Vector.h"
+#include "Model.h"
+#include
+
+class Weapon {
+public:
+ Weapon(std::string modelFilename, float scale, Vec3f location, Vec2f rotation,
+ Vec3f offsetPlayer, Vec3f ankerPoint,
+ Vec2f maxRotation, Vec2f minXRotation);
+ ~Weapon();
+
+ void draw();
+ void rotateWeapon(Vec3f rotation);
+ void rotate(Vec2f rotation);
+ void move(Vec3f location);
+
+ unsigned int damage;
+ Model* weaponmodel;
+
+ float scale;
+ Vec3f position, rotation, rotationWeapon;
+ Vec3f offsetPlayer, ankerPoint;
+ Vec2f maxRotation, minRotation;
+};
+
+
+#endif //CRYSTALPOINT_WEAPON_H