weapons are facing next to the camera

This commit is contained in:
Remco
2016-05-17 10:34:11 +02:00
parent 1693c74a6a
commit e5664e207d
5 changed files with 100 additions and 28 deletions
+32 -24
View File
@@ -1,5 +1,6 @@
#include "Header.h" #include "Header.h"
#include "Model.h" #include "Model.h"
#include "Player.h"
//Prototypes //Prototypes
void bindFuncOpenGL(void); void bindFuncOpenGL(void);
@@ -12,17 +13,10 @@ static int Height;
float lastFrameTime = 0; float lastFrameTime = 0;
bool keys[255]; bool keys[255];
vector<Model*> models; //vector<Model*> models;
int currentModel = 0; //int currentModel = 0;
struct Camera Player *player;
{
float posX = 0;
float posY = -10;
float posZ = 0;
float rotX = 0;
float rotY = 0;
} camera;
void display() void display()
{ {
@@ -35,12 +29,22 @@ void display()
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glRotatef(camera.rotX, 1, 0, 0); /*glRotatef(player.eyes.rotX, 1, 0, 0);
glRotatef(camera.rotY, 0, 1, 0); glRotatef(player.eyes.rotY, 0, 1, 0);
glTranslatef(camera.posX, camera.posY, camera.posZ); glTranslatef(player.eyes.posX, player.eyes.posY, player.eyes.posZ);
//Draw here glPushMatrix();
glScalef(0.5f, 0.5f, 0.5f);
glRotatef(180, 1, 0, 0);
glRotatef(45, 0, 0, 1);
glRotatef(90, 0, 1, 0);
models[currentModel]->draw(); models[currentModel]->draw();
glPopMatrix();*/
//Draw here
player->Draw_Player();
glutSolidCube(10.0);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glutSwapBuffers(); glutSwapBuffers();
@@ -49,11 +53,11 @@ void display()
void move(float angle, float fac, bool heigth) void move(float angle, float fac, bool heigth)
{ {
if (heigth) if (heigth)
camera.posY += angle*fac; player->eyes.posY += angle*fac;
else else
{ {
camera.posX += (float)cos((camera.rotY + angle) / 180 * M_PI) * fac; player->eyes.posX += (float)cos((player->eyes.rotY + angle) / 180 * M_PI) * fac;
camera.posZ += (float)sin((camera.rotY + angle) / 180 * M_PI) * fac; player->eyes.posZ += (float)sin((player->eyes.rotY + angle) / 180 * M_PI) * fac;
} }
} }
@@ -70,7 +74,8 @@ void idle()
if (keys['w']) move(90, deltaTime*speed, false); if (keys['w']) move(90, deltaTime*speed, false);
if (keys['s']) move(270, deltaTime*speed, false); if (keys['s']) move(270, deltaTime*speed, false);
if (keys['q']) move(1, deltaTime*speed, true); if (keys['q']) move(1, deltaTime*speed, true);
if (keys['e']) move(-1, deltaTime*speed, true); if (keys['e']) move(-1, deltaTime*speed, true);
glutPostRedisplay(); glutPostRedisplay();
} }
@@ -80,8 +85,8 @@ void mousemotion(int x, int y)
int dy = y - Height / 2; int dy = y - Height / 2;
if ((dx != 0 || dy != 0) && abs(dx) < 400 && abs(dy) < 400) if ((dx != 0 || dy != 0) && abs(dx) < 400 && abs(dy) < 400)
{ {
camera.rotY += dx / 10.0f; player->eyes.rotY += dx / 10.0f;
camera.rotX += dy / 10.0f; player->eyes.rotX += dy / 10.0f;
glutWarpPointer(Width / 2, Height / 2); glutWarpPointer(Width / 2, Height / 2);
} }
} }
@@ -89,8 +94,8 @@ void mousemotion(int x, int y)
void keyboard(unsigned char key, int, int) void keyboard(unsigned char key, int, int)
{ {
if (key == 27) if (key == 27)
exit(0); exit(0);
//std::cout << key << std::endl;
keys[key] = true; keys[key] = true;
} }
@@ -127,6 +132,7 @@ void bindFuncOpenGL()
//Keyboard //Keyboard
glutKeyboardFunc(keyboard); glutKeyboardFunc(keyboard);
glutKeyboardUpFunc(keyboardup); glutKeyboardUpFunc(keyboardup);
//glutMouseFunc(mousefunc);
//Mouse //Mouse
//glutMouseFunc(mouse); //glutMouseFunc(mouse);
@@ -141,6 +147,7 @@ void configureOpenGL()
glutInitWindowSize(800, 600); glutInitWindowSize(800, 600);
glutCreateWindow("Crystal Point"); glutCreateWindow("Crystal Point");
glutFullScreen(); glutFullScreen();
//glutPositionWindow((glutGet(GLUT_SCREEN_WIDTH) / 2) - (glutGet(GLUT_WINDOW_WIDTH) / 2), (glutGet(GLUT_SCREEN_HEIGHT) / 2) - (glutGet(GLUT_WINDOW_HEIGHT) / 2));
//Depth testing //Depth testing
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@@ -153,7 +160,7 @@ void configureOpenGL()
glEnable(GL_ALPHA_TEST); glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.01f); glAlphaFunc(GL_GREATER, 0.01f);
//Lighting Lighting
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess[] = { 50.0 }; GLfloat mat_shininess[] = { 50.0 };
GLfloat light_position[] = { 30.0, 30.0, 30.0, 0.0 }; GLfloat light_position[] = { 30.0, 30.0, 30.0, 0.0 };
@@ -174,5 +181,6 @@ void configureOpenGL()
void loadModels() void loadModels()
{ {
models.push_back(new Model("models/weapons/ZwaardMetTextures/TextureZwaard.obj")); player = new Player();
//models.push_back(new Model("models/weapons/ZwaardMetTextures/TextureZwaard.obj"));
} }
+29
View File
@@ -4,9 +4,38 @@
Player::Player() Player::Player()
{ {
right = new Weapon("models/weapons/ZwaardMetTextures/TextureZwaard.obj");
left = new Weapon("models/weapons/ZwaardMetTextures/TextureZwaard.obj");
} }
Player::~Player() Player::~Player()
{ {
delete right;
delete left;
} }
void Player::Draw_Player(void)
{
if (right != nullptr)
{
glPushMatrix();
glTranslatef(2.5f,0,-4.5f);
right->draw_weapon();
glPopMatrix();
}
if (left != nullptr)
{
glPushMatrix();
glTranslatef(-0.5f,0,-4.5f);
left->draw_weapon();
glPopMatrix();
}
glRotatef(eyes.rotX, 1, 0, 0);
glRotatef(eyes.rotY, 0, 1, 0);
glTranslatef(eyes.posX, eyes.posY, eyes.posZ);
}
+13 -2
View File
@@ -7,11 +7,22 @@ class Player
public: public:
Player(); Player();
~Player(); ~Player();
struct Eyes
{
float posX = 0;
float posY = 0;
float posZ = 0;
float rotX = 0;
float rotY = 0;
} eyes;
void Draw_Player(void);
private: private:
int level; int level;
int xp; int xp;
Weapon rigth; Weapon* right = nullptr;
Weapon left; Weapon* left = nullptr;
vector<Weapon> weapons; vector<Weapon> weapons;
}; };
+19 -1
View File
@@ -1,10 +1,28 @@
#include "Weapon.h" #include "Weapon.h"
Weapon::Weapon(const string &filename)
{
weaponModel = new Model(filename);
}
Weapon::Weapon() Weapon::Weapon()
{ {
}
}
Weapon::~Weapon() Weapon::~Weapon()
{ {
} }
void Weapon::draw_weapon(void)
{
if (weaponModel != nullptr)
{
glScalef(scale,scale,scale);
glRotatef(rotX, 1, 0, 0);
weaponModel->draw();
}
}
+7 -1
View File
@@ -1,10 +1,16 @@
#pragma once #pragma once
#include "Header.h" #include "Header.h"
#include "Model.h"
class Weapon class Weapon
{ {
public: public:
Weapon(const string &filename);
Weapon(); Weapon();
~Weapon(); ~Weapon();
void draw_weapon(void);
private:
Model *weaponModel = nullptr;
float scale = 0.5f;
}; };