From 4249e3565313430656033fcc83ec6acf6dfaef6a Mon Sep 17 00:00:00 2001 From: jancoow Date: Tue, 21 Jun 2016 17:00:36 +0200 Subject: [PATCH 1/4] Check if weapon collision point is inside enemy and do weapon damage --- CrystalPoint.cpp | 3 +++ Enemy.cpp | 20 +++++++++++++++++++- Enemy.h | 3 +++ Player.cpp | 4 ++-- Weapon.cpp | 5 +++-- Weapon.h | 4 ++-- World.cpp | 1 + 7 files changed, 33 insertions(+), 7 deletions(-) diff --git a/CrystalPoint.cpp b/CrystalPoint.cpp index 8e9c54b..a37683f 100644 --- a/CrystalPoint.cpp +++ b/CrystalPoint.cpp @@ -151,6 +151,9 @@ void CrystalPoint::update() } else { + if (keyboardState.keys[27]){ + glutExit(); + } menu->update(); cursor->update(cursor->mousePosition + mouseOffset); } diff --git a/Enemy.cpp b/Enemy.cpp index 42e5019..0368ba9 100644 --- a/Enemy.cpp +++ b/Enemy.cpp @@ -2,6 +2,7 @@ #include #include "Enemy.h" #include "Model.h" +#include "Player.h" #include Enemy::Enemy(const std::string &fileName, @@ -75,6 +76,10 @@ void Enemy::collide(const Entity * entity) position.z = difference.z + entity->position.z; } +void Enemy::hit(int damage){ + +} + void Enemy::update(float delta) { music->SetPos(position, Vec3f()); @@ -117,5 +122,18 @@ void Enemy::update(float delta) rotation.y = atan2f(dx, dz) * 180 / M_PI; } - + Player *player = Player::getInstance(); + if(inObject(player->leftWeapon->collisionPoint)){ + if(!isHit){ + isHit = true; + hit(player->leftWeapon->damage); + } + }else if(inObject(player->rightWeapon->collisionPoint)){ + if(!isHit){ + isHit = true; + hit(player->rightWeapon->damage); + } + }else{ + isHit = false; + } } \ No newline at end of file diff --git a/Enemy.h b/Enemy.h index 61ab4f4..cf9d301 100644 --- a/Enemy.h +++ b/Enemy.h @@ -19,11 +19,14 @@ public: int xp; bool attack; + bool isHit; + void update(float); void draw(); void inEyeSight(Vec3f &); void collide(const Entity *entity); + void hit(int damage); private: int hit_sound_id; }; diff --git a/Player.cpp b/Player.cpp index 303a9d4..9948c14 100644 --- a/Player.cpp +++ b/Player.cpp @@ -15,10 +15,10 @@ Player::Player() level = 1; 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 = new Weapon("models/weapons/ZwaardMetTextures/TextureZwaard.obj", 1, position, rotation, Vec3f(4.5, -8, -1), Vec3f(-2.0f, 6.0f, -2.1f), Vec3f(-2.0f, 0.5f, -2.1f), Vec2f(170, 70), Vec2f(20, -80)); leftWeapon->rotateWeapon(Vec3f(150, 0, 60)); - rightWeapon = new Weapon("models/weapons/ZwaardMetTextures/TextureZwaard.obj", 1, position, rotation, Vec3f(0.5, -8, -1), Vec3f(-2.0f, 6.0f, -2.1f), Vec2f(170, 70), Vec2f(20, -80)); + rightWeapon = new Weapon("models/weapons/ZwaardMetTextures/TextureZwaard.obj", 1, position, rotation, Vec3f(0.5, -8, -1), Vec3f(-2.0f, 6.0f, -2.1f), Vec3f(-2.0f, 0.5f, -2.1f), Vec2f(170, 70), Vec2f(20, -80)); rightWeapon->rotateWeapon(Vec3f(150, 0, 60)); } diff --git a/Weapon.cpp b/Weapon.cpp index 7a26355..55e1514 100644 --- a/Weapon.cpp +++ b/Weapon.cpp @@ -10,7 +10,7 @@ Weapon::Weapon(std::string modelFilename, float scale, Vec3f location, Vec2f rotation, - Vec3f offsetPlayer, Vec3f ankerPoint, + Vec3f offsetPlayer, Vec3f ankerPoint, Vec3f collisionPoint, Vec2f maxRotation, Vec2f minRotation){ weaponmodel = Model::load(modelFilename); rotate(rotation); @@ -21,6 +21,7 @@ Weapon::Weapon(std::string modelFilename, float scale, Vec3f location, Vec2f rot this->ankerPoint = ankerPoint; this->maxRotation = maxRotation; this->minRotation = minRotation; + this->collisionPoint = collisionPoint; }; Weapon::~Weapon(){ @@ -72,7 +73,7 @@ void Weapon::draw(){ //Test code for finding anker point glColor3ub(255, 255, 0); - glTranslatef(ankerPoint.x, ankerPoint.y, ankerPoint.z); + glTranslatef(collisionPoint.x, collisionPoint.y, collisionPoint.z); glBegin(GL_LINES); glVertex2f(0, 4); glVertex2f(0, -4); diff --git a/Weapon.h b/Weapon.h index 8d5e672..b31f5e9 100644 --- a/Weapon.h +++ b/Weapon.h @@ -12,7 +12,7 @@ class Weapon { public: Weapon(std::string modelFilename, float scale, Vec3f location, Vec2f rotation, - Vec3f offsetPlayer, Vec3f ankerPoint, + Vec3f offsetPlayer, Vec3f ankerPoint, Vec3f collisionPoint, Vec2f maxRotation, Vec2f minXRotation); ~Weapon(); @@ -26,7 +26,7 @@ public: float scale; Vec3f position, rotation, rotationWeapon; - Vec3f offsetPlayer, ankerPoint; + Vec3f offsetPlayer, ankerPoint, collisionPoint; Vec2f maxRotation, minRotation; }; diff --git a/World.cpp b/World.cpp index ebf2d52..adbd7f2 100644 --- a/World.cpp +++ b/World.cpp @@ -351,3 +351,4 @@ bool World::isPlayerPositionValid() } return true; } + From d14f045708649517f967a44439f012465b621c9f Mon Sep 17 00:00:00 2001 From: jancoow Date: Tue, 21 Jun 2016 17:07:19 +0200 Subject: [PATCH 2/4] Added dead check --- Enemy.cpp | 4 ++++ Enemy.h | 1 + 2 files changed, 5 insertions(+) diff --git a/Enemy.cpp b/Enemy.cpp index e8bc92c..efe6147 100644 --- a/Enemy.cpp +++ b/Enemy.cpp @@ -83,7 +83,11 @@ void Enemy::collide(const Entity * entity) } void Enemy::hit(int damage){ + health -= damage; +} +bool Enemy::isDead(){ + return health < 0; } void Enemy::update(float delta) diff --git a/Enemy.h b/Enemy.h index 3ba5cb1..0be19e1 100644 --- a/Enemy.h +++ b/Enemy.h @@ -29,6 +29,7 @@ public: void inEyeSight(Vec3f &); void collide(const Entity *entity); void hit(int damage); + bool isDead(void); private: int hit_sound_id; }; From e7163fc07c1e7e8508dbdabd3b7b594a044e7009 Mon Sep 17 00:00:00 2001 From: jancoow Date: Tue, 21 Jun 2016 22:12:08 +0200 Subject: [PATCH 3/4] Added controller cursor in menu --- ControllerHandler.cpp | 2 +- CrystalPoint.cpp | 61 ++++++++++++++++++----------- Enemy.cpp | 5 ++- Main.cpp | 1 + Matrix.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++ Matrix.h | 26 +++++++++++++ Vector.cpp | 1 + Weapon.cpp | 42 ++++++++++++++++++-- Weapon.h | 1 + World.cpp | 4 +- 10 files changed, 202 insertions(+), 30 deletions(-) create mode 100644 Matrix.cpp create mode 100644 Matrix.h diff --git a/ControllerHandler.cpp b/ControllerHandler.cpp index 5e12a15..300d253 100644 --- a/ControllerHandler.cpp +++ b/ControllerHandler.cpp @@ -121,7 +121,7 @@ void ControllerHandler::commandControllerData(std::vector data) { c->joystick.x = std::stoi(data[2])/2000.0f; c->joystick.y = std::stoi(data[3])/2000.0f; c->joystickButton = !(data[4] == "0"); - + c->button = !(data[8] == "0"); c->magnetSwitch = !(data[9] == "0"); } } diff --git a/CrystalPoint.cpp b/CrystalPoint.cpp index a37683f..915532d 100644 --- a/CrystalPoint.cpp +++ b/CrystalPoint.cpp @@ -65,7 +65,10 @@ void CrystalPoint::update() if (keyboardState.keys[27] && !prevKeyboardState.keys[27]) state = !state; - + + Controller *rightcontroller = controller.getRightController(); + Controller *leftcontroller = controller.getLeftController(); + if (state) { if (keyboardState.special[GLUT_KEY_LEFT] && !prevKeyboardState.special[GLUT_KEY_LEFT]) @@ -100,42 +103,43 @@ 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 || leftControllerJoystick->y < -0.3) { + player->rotation.x += leftControllerJoystick->y/4; + } - if (leftControllerJoystick->y > 0.3) { - player->setPosition(270, leftControllerJoystick->y * deltaTime * 2.0f, false); - } - else if (leftControllerJoystick->y < -0.3) { - player->setPosition(90, leftControllerJoystick->y * -1 * deltaTime * 2.0f, false); - } - if (leftControllerJoystick->x > 0.3) { - player->setPosition(180, leftControllerJoystick->x * deltaTime * 2.0f, false); - } - else if (leftControllerJoystick->x < -0.3) { - player->setPosition(0, leftControllerJoystick->x * -1 * deltaTime * 2.0f, false); + if (leftControllerJoystick->x > 0.3 || leftControllerJoystick->x < -0.3) { + player->rotation.y += leftControllerJoystick->x/4; } player->leftWeapon->rotateWeapon(Vec3f(leftcontroller->ypr.y + 140, 0, -leftcontroller->ypr.z)); + if(leftcontroller->button && leftcontroller->joystickButton){ + state = !state; + } } - Controller *rightcontroller = controller.getRightController(); if(rightcontroller != nullptr){ Vec2f *rightControllerJoystick = &rightcontroller->joystick; - if (rightControllerJoystick->y > 0.3 || rightControllerJoystick->y < -0.3) { - player->rotation.x += rightcontroller->joystick.y/4; + + if (rightControllerJoystick->y > 0.3) { + player->setPosition(270, rightControllerJoystick->y * deltaTime * 2.0f, false); + } + else if (rightControllerJoystick->y < -0.3) { + player->setPosition(90, rightControllerJoystick->y * -1 * deltaTime * 2.0f, false); + } + if (rightControllerJoystick->x > 0.3) { + player->setPosition(180, rightControllerJoystick->x * deltaTime * 2.0f, false); + } + else if (rightControllerJoystick->x < -0.3) { + player->setPosition(0, rightControllerJoystick->x * -1 * deltaTime * 2.0f, false); } - if (rightControllerJoystick->x > 0.3 || rightControllerJoystick->x < -0.3) { - player->rotation.y += rightcontroller->joystick.x/4; - } player->rightWeapon->rotateWeapon(Vec3f(rightcontroller->ypr.y + 140, 0, -rightcontroller->ypr.z)); } @@ -151,10 +155,21 @@ void CrystalPoint::update() } else { - if (keyboardState.keys[27]){ - glutExit(); - } menu->update(); + if (leftcontroller != nullptr) { + Vec2f *leftControllerJoystick = &leftcontroller->joystick; + if (leftControllerJoystick->y > 0.3 || leftControllerJoystick->y < -0.3) { + cursor->update(Vec2f(cursor->mousePosition.x,cursor->mousePosition.y+leftControllerJoystick->y )); + } + if (leftControllerJoystick->x > 0.3 || leftControllerJoystick->x < -0.3) { + cursor->update(Vec2f(cursor->mousePosition.x+leftControllerJoystick->x ,cursor->mousePosition.y)); + } + if(leftcontroller->button){ + cursor->state = 137; + }else if(cursor->state == 137){ + cursor->state = GLUT_UP; + } + } cursor->update(cursor->mousePosition + mouseOffset); } diff --git a/Enemy.cpp b/Enemy.cpp index efe6147..f602596 100644 --- a/Enemy.cpp +++ b/Enemy.cpp @@ -133,16 +133,19 @@ void Enemy::update(float delta) rotation.y = atan2f(dx, dz) * 180 / M_PI; } Player *player = Player::getInstance(); - if(inObject(player->leftWeapon->collisionPoint)){ + + if(inObject(player->position + player->leftWeapon->collisionPoint)){ if(!isHit){ isHit = true; hit(player->leftWeapon->damage); } + std::cout << "HIT1"; }else if(inObject(player->rightWeapon->collisionPoint)){ if(!isHit){ isHit = true; hit(player->rightWeapon->damage); } + std::cout << "HIT2"; }else{ isHit = false; } diff --git a/Main.cpp b/Main.cpp index c119e64..4ac85b1 100644 --- a/Main.cpp +++ b/Main.cpp @@ -61,6 +61,7 @@ int main(int argc, char* argv[]) if (button == GLUT_LEFT_BUTTON) Cursor::getInstance()->state = state; + //std::cout << "Left button is down" << std::endl; }; diff --git a/Matrix.cpp b/Matrix.cpp new file mode 100644 index 0000000..97d91c3 --- /dev/null +++ b/Matrix.cpp @@ -0,0 +1,89 @@ +// +// Created by janco on 6/21/16. +// + +#include "Matrix.h" + + Matrix::Matrix(int size = 4) + { + data = new float[size][size]; + } + + Matrix Matrix::identity() + { + Matrix m = new Matrix(4); + m.data[0,0] = 1; + m.data[1,1] = 1; + m.data[2,2] = 1; + m.data[3,3] = 1; + return m; + } + + Matrix Matrix::rotation(float angle, Vector3 axis) + { + Matrix m = Matrix.identity(); + + float c = (float) Math.Cos((double) angle); + float s = (float) Math.Sin((double) angle); + + m.data[0, 0] = (float) Math.Pow(axis.x, 2) * (1 - c) + c; + m.data[0, 1] = axis.x * axis.y * (1 - c) - axis.z * s; + m.data[0, 2] = axis.x * axis.z * (1 - c) - axis.y * s; + m.data[1, 0] = axis.x * axis.y * (1 - c) + axis.z * s; + m.data[1, 1] = (float)Math.Pow(axis.y, 2) * (1 - c) + c; + m.data[1, 2] = axis.y * axis.z * (1 - c) + axis.x * s; + m.data[2, 0] = axis.x * axis.z * (1 - c) + axis.y * s; + m.data[2, 1] = axis.y * axis.z * (1 - c) - axis.x * s; + m.data[2, 2] = (float)Math.Pow(axis.z, 2) * (1 - c) + c; + + return m; + } + Matrix Matrix::translate(Vector3 offset) + { + Matrix m = Matrix.identity(); + + for(int i = 0; i < 3; i++) + { + m.data[i, 3] = offset.data[i]; + } + + return m; + } + + Vec3f Matrix::operator * (Matrix mat, Vec3f vec) + { + Vec3f v = Vec3f(0,0,0); + + for(int i = 0; i < 4; i++) + { + v.data[i] = 0; + + for(int p = 0; p < 4; p++) + { + v.data[i] += mat.data[i, p] * vec.data[p]; + } + } + + return v; + } + + Matrix Matrix::operator * (Matrix mat1, Matrix mat2) + { + Matrix m = Matrix.identity(); + + for (int i = 0; i < 4; i++) + { + for (int p = 0; p < 4; p++) + { + m.data[i, p] = 0; + + for (int q = 0; q < 4; q++) + { + m.data[i, p] += mat1.data[i, q] * mat2.data[q, p]; + } + } + } + + return m; + } +}; \ No newline at end of file diff --git a/Matrix.h b/Matrix.h new file mode 100644 index 0000000..9e631ea --- /dev/null +++ b/Matrix.h @@ -0,0 +1,26 @@ +// +// Created by janco on 6/21/16. +// + +#ifndef CRYSTALPOINT_MATRIX_H +#define CRYSTALPOINT_MATRIX_H + + +class Matrix { +private: +public: + float *data; + + Matrix(int i = 4); + ~Matrix(); + + static Matrix rotation(int angle, Vec3f axis); + static Matrix identity(void); + static Matrix translate(Vec3f offset); + + Matrix operator * (Matrix m1, Matrix m2); + Vec3f operator * (Matrix m, Vec3f v); +} + + +#endif //CRYSTALPOINT_MATRIX_H diff --git a/Vector.cpp b/Vector.cpp index 35a6d41..c7ea763 100644 --- a/Vector.cpp +++ b/Vector.cpp @@ -2,6 +2,7 @@ #include #include "Vector.h" + Vec3f::Vec3f(float x, float y, float z) { this->x = x; diff --git a/Weapon.cpp b/Weapon.cpp index 55e1514..83f7349 100644 --- a/Weapon.cpp +++ b/Weapon.cpp @@ -22,6 +22,8 @@ Weapon::Weapon(std::string modelFilename, float scale, Vec3f location, Vec2f rot this->maxRotation = maxRotation; this->minRotation = minRotation; this->collisionPoint = collisionPoint; + + this->damage = 1; }; Weapon::~Weapon(){ @@ -46,6 +48,22 @@ void Weapon::move(Vec3f location){ position = location; } +Vec3f multiply(float matrix[16], Vec3f vec) +{ + Vec3f result; + + for(int i = 0; i < 4; i++) + { + for(int p = 0; p < 4; p++) + { + result[i] += matrix[i * p] * vec[p]; + } + } + + return result; +} + + void Weapon::draw(){ if (weaponmodel != nullptr) { @@ -67,13 +85,27 @@ void Weapon::draw(){ 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); + //Test code for finding anchor point glTranslatef(collisionPoint.x, collisionPoint.y, collisionPoint.z); + + float matrix[16]; + glGetFloatv(GL_MODELVIEW_MATRIX, matrix); + + Vec3f point = multiply(matrix, Vec3f(1,1,1)); + + + glScalef(scale, scale, scale); + + + glPopMatrix(); + + glPushMatrix(); + + glTranslatef(point.x, point.y, point.z); + glColor3ub(255, 255, 0); glBegin(GL_LINES); glVertex2f(0, 4); glVertex2f(0, -4); @@ -82,6 +114,8 @@ void Weapon::draw(){ glEnd(); glPopMatrix(); - } } + + + diff --git a/Weapon.h b/Weapon.h index b31f5e9..4176806 100644 --- a/Weapon.h +++ b/Weapon.h @@ -28,6 +28,7 @@ public: Vec3f position, rotation, rotationWeapon; Vec3f offsetPlayer, ankerPoint, collisionPoint; Vec2f maxRotation, minRotation; + }; diff --git a/World.cpp b/World.cpp index b3321ac..97562a7 100644 --- a/World.cpp +++ b/World.cpp @@ -320,7 +320,9 @@ void World::update(float elapsedTime) } } enemy->position.y = getHeight(enemy->position.x, enemy->position.z) + 2.0f; - + if(enemy->isDead()){ + remove = true; + } if(!remove) count++; } From 27dfaf74c470961470f138993f4637db2341513d Mon Sep 17 00:00:00 2001 From: jancoow Date: Wed, 22 Jun 2016 00:32:19 +0200 Subject: [PATCH 4/4] Better weapon alignment --- CrystalPoint.cpp | 9 +++------ Main.cpp | 2 +- Player.cpp | 13 +++++++++++-- Weapon.cpp | 26 +++++++++++++------------- World.cpp | 2 +- weapons.json | 10 ++++++---- worlds/small.json | 2 +- 7 files changed, 36 insertions(+), 28 deletions(-) diff --git a/CrystalPoint.cpp b/CrystalPoint.cpp index 6758fe8..65f7e41 100644 --- a/CrystalPoint.cpp +++ b/CrystalPoint.cpp @@ -64,7 +64,7 @@ void CrystalPoint::update() lastFrameTime = frameTime; if (keyboardState.keys[27] && !prevKeyboardState.keys[27]) - state = !state; + state = !state; Controller *rightcontroller = controller.getRightController(); Controller *leftcontroller = controller.getLeftController(); @@ -78,7 +78,7 @@ void CrystalPoint::update() if (keyboardState.special[GLUT_KEY_RIGHT] && !prevKeyboardState.special[GLUT_KEY_RIGHT]) worldhandler->NextWorld(); if (keyboardState.special[GLUT_KEY_UP] && !prevKeyboardState.special[GLUT_KEY_UP]) - player->NextLeftWeapon(); + player->NextRightWeapon(); if (keyboardState.special[GLUT_KEY_DOWN] && !prevKeyboardState.special[GLUT_KEY_DOWN]) player->PreviousLeftWeapon(); if (keyboardState.keys[27]) @@ -149,7 +149,7 @@ void CrystalPoint::update() controller.rumble(rightcontroller->controllerId, 100, 200); player->NextRightWeapon(); } - + player->rightWeapon->rotateWeapon(Vec3f(rightcontroller->ypr.y + 140, 0, -rightcontroller->ypr.z)); } @@ -162,9 +162,6 @@ void CrystalPoint::update() if (!worldhandler->isPlayerPositionValid()) player->position = oldPosition; - /*else if (player->position.y > oldPosition.y + 1.2) - player->position = oldPosition; - */ worldhandler->update(deltaTime); } else diff --git a/Main.cpp b/Main.cpp index 4ac85b1..e9abf25 100644 --- a/Main.cpp +++ b/Main.cpp @@ -80,7 +80,7 @@ void configureOpenGL() { //Init window and glut display mode glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); - glutInitWindowSize(800, 600); + glutInitWindowSize(1440, 900); //glutInitWindowPosition(glutGet(GLUT_WINDOW_WIDTH) / 2 - 800/2, glutGet(GLUT_WINDOW_HEIGHT) / 2 - 600/2); glutCreateWindow("Crystal Point"); //glutFullScreen(); diff --git a/Player.cpp b/Player.cpp index 54888ad..83559ed 100644 --- a/Player.cpp +++ b/Player.cpp @@ -150,6 +150,7 @@ void Player::loadWeapons() std::string name = w["name"].asString(); std::string fileN = w["file"].asString(); float damage = w["damage"].asFloat(); + float scale = w["scale"].asFloat(); Weapon::Element e = Weapon::FIRE; @@ -174,8 +175,8 @@ void Player::loadWeapons() Vec2f maxRot = Vec2f(w["maxRotation"][0].asFloat(), w["maxRotation"][1].asFloat()); Vec2f minRot = Vec2f(w["minRotation"][0].asFloat(), w["minRotation"][1].asFloat()); - lweapon = new Weapon(name, damage, e, fileN, 1, position, rotation, leftoffset, anchor, maxRot, minRot, collision); - rweapon = new Weapon(name, damage, e, fileN, 1, position, rotation, rightoffset, anchor, maxRot, minRot, collision); + lweapon = new Weapon(name, damage, e, fileN, scale, position, rotation, leftoffset, anchor, maxRot, minRot, collision); + rweapon = new Weapon(name, damage, e, fileN, scale, position, rotation, rightoffset, anchor, maxRot, minRot, collision); leftweapons.push_back(lweapon); rightweapons.push_back(rweapon); @@ -191,6 +192,8 @@ void Player::PreviousRightWeapon() currentrightweapon = (rightweapons.size() > level ? level - 1 : rightweapons.size() - 1); rightWeapon = rightweapons[currentrightweapon]; + rightWeapon->move(position); + rightWeapon->rotate(rotation); } void Player::NextRightWeapon(void) { @@ -200,6 +203,8 @@ void Player::NextRightWeapon(void) currentrightweapon = 0; rightWeapon = rightweapons[currentrightweapon]; + rightWeapon->move(position); + rightWeapon->rotate(rotation); } void Player::PreviousLeftWeapon(void) { @@ -209,6 +214,8 @@ void Player::PreviousLeftWeapon(void) currentleftweapon = (leftweapons.size() > level ? level - 1 : leftweapons.size() - 1); leftWeapon = leftweapons[currentleftweapon]; + leftWeapon->move(position); + leftWeapon->rotate(rotation); } void Player::NextLeftWeapon(void) { @@ -218,4 +225,6 @@ void Player::NextLeftWeapon(void) currentleftweapon = 0; leftWeapon = leftweapons[currentleftweapon]; + leftWeapon->move(position); + leftWeapon->rotate(rotation); } \ No newline at end of file diff --git a/Weapon.cpp b/Weapon.cpp index 76882a0..5c78e92 100644 --- a/Weapon.cpp +++ b/Weapon.cpp @@ -29,7 +29,6 @@ Weapon::Weapon(std::string name, int damage, Element e, std::string modelFilenam this->minRotation = minRotation; this->collisionPoint = collisionPoint; - this->damage = 1; }; Weapon::~Weapon(){ @@ -75,6 +74,7 @@ void Weapon::draw(){ { glPushMatrix(); + //Player position and rotation glTranslatef(position.x, position.y, position.z); glRotatef(rotation.x, 1, 0, 0); @@ -84,13 +84,23 @@ void Weapon::draw(){ //offset from player glTranslatef(offsetPlayer.x, offsetPlayer.y, offsetPlayer.z); + glScalef(scale, scale, scale); + //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); +/* + glColor3ub(255, 255, 0); + glBegin(GL_LINES); + glVertex2f(0, 4); + glVertex2f(0, -4); + glVertex2f(4, 0); + glVertex2f(-4, 0); + glEnd();*/ + glTranslatef(-ankerPoint.x, -ankerPoint.y, -ankerPoint.z); weaponmodel->draw(); @@ -103,21 +113,11 @@ void Weapon::draw(){ Vec3f point = multiply(matrix, Vec3f(1,1,1)); - glScalef(scale, scale, scale); - - glPopMatrix(); glPushMatrix(); - glTranslatef(point.x, point.y, point.z); - glColor3ub(255, 255, 0); - glBegin(GL_LINES); - glVertex2f(0, 4); - glVertex2f(0, -4); - glVertex2f(4, 0); - glVertex2f(-4, 0); - glEnd(); + glPopMatrix(); } diff --git a/World.cpp b/World.cpp index d992820..172ed4d 100644 --- a/World.cpp +++ b/World.cpp @@ -249,6 +249,7 @@ float World::getHeight(float x, float y) void World::draw() { + player->setCamera(); float lightPosition[4] = { 0, 2, 1, 0 }; glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); @@ -260,7 +261,6 @@ void World::draw() skybox->draw(); - player->setCamera(); player->draw(); heightmap->Draw(); diff --git a/weapons.json b/weapons.json index 77177a9..264dd33 100644 --- a/weapons.json +++ b/weapons.json @@ -10,12 +10,13 @@ "collision": [ 0, 0, 0 ], "maxRotation": [ 170, 70 ], "minRotation": [ 20, -80 ], + "scale": 0.3, "left": { - "offset": [ 4.5, -8, -1 ] + "offset": [ 1.5, -2.6, 0 ] }, "right": { - "offset": [ 0.5, -8, -1 ] + "offset": [ -0.1, -2.6, 0 ] } }, { @@ -28,12 +29,13 @@ "collision": [ 0, 0, 0 ], "maxRotation": [ 170, 70 ], "minRotation": [ 20, -80 ], + "scale": 0.3, "left": { - "offset": [ 4.5, -8, -1 ] + "offset": [ 1.5, -2.6, 0 ] }, "right": { - "offset": [ 0.5, -8, -1 ] + "offset": [ -0.1, -2.6, 0 ] } } ] diff --git a/worlds/small.json b/worlds/small.json index 3bcbb48..62d5ddf 100644 --- a/worlds/small.json +++ b/worlds/small.json @@ -12,7 +12,7 @@ "music": "WAVE/world1.wav" }, "player": { - "startposition": [ 20, 0, 20 ] + "startposition": [ -10, -10, -10 ] }, "objects": [ ], "portal": {