Sfoglia il codice sorgente

weapons are facing next to the camera

Remco 9 anni fa
parent
commit
e5664e207d
5 ha cambiato i file con 101 aggiunte e 29 eliminazioni
  1. 33 25
      Main.cpp
  2. 29 0
      Player.cpp
  3. 13 2
      Player.h
  4. 19 1
      Weapon.cpp
  5. 7 1
      Weapon.h

+ 33 - 25
Main.cpp

@@ -1,5 +1,6 @@
 #include "Header.h"
 #include "Model.h"
+#include "Player.h"
 
 //Prototypes
 void bindFuncOpenGL(void);
@@ -12,17 +13,10 @@ static int Height;
 float lastFrameTime = 0;
 bool keys[255];
 
-vector<Model*> models;
-int currentModel = 0;
+//vector<Model*> models;
+//int currentModel = 0;
 
-struct Camera
-{
-	float posX = 0;
-	float posY = -10;
-	float posZ = 0;
-	float rotX = 0;
-	float rotY = 0;
-} camera;
+Player *player;
 
 void display()
 {
@@ -35,12 +29,22 @@ void display()
 
 	glMatrixMode(GL_MODELVIEW);
 	glLoadIdentity();
-	glRotatef(camera.rotX, 1, 0, 0);
-	glRotatef(camera.rotY, 0, 1, 0);
-	glTranslatef(camera.posX, camera.posY, camera.posZ);
-
-	//Draw here
+	/*glRotatef(player.eyes.rotX, 1, 0, 0);
+	glRotatef(player.eyes.rotY, 0, 1, 0);
+	glTranslatef(player.eyes.posX, player.eyes.posY, player.eyes.posZ);
+
+	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();
+	glPopMatrix();*/
+
+	//Draw here	
+	player->Draw_Player();
+	
+	glutSolidCube(10.0);
 
 	glDisable(GL_TEXTURE_2D);
 	glutSwapBuffers();
@@ -49,11 +53,11 @@ void display()
 void move(float angle, float fac, bool heigth)
 {
 	if (heigth)
-		camera.posY += angle*fac;
+		player->eyes.posY += angle*fac;
 	else
 	{
-		camera.posX += (float)cos((camera.rotY + angle) / 180 * M_PI) * fac;
-		camera.posZ += (float)sin((camera.rotY + angle) / 180 * M_PI) * fac;
+		player->eyes.posX += (float)cos((player->eyes.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['s']) move(270, deltaTime*speed, false);
 	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();
 }
 
@@ -80,8 +85,8 @@ void mousemotion(int x, int y)
 	int dy = y - Height / 2;
 	if ((dx != 0 || dy != 0) && abs(dx) < 400 && abs(dy) < 400)
 	{
-		camera.rotY += dx / 10.0f;
-		camera.rotX += dy / 10.0f;
+		player->eyes.rotY += dx / 10.0f;
+		player->eyes.rotX += dy / 10.0f;
 		glutWarpPointer(Width / 2, Height / 2);
 	}
 }
@@ -89,8 +94,8 @@ void mousemotion(int x, int y)
 void keyboard(unsigned char key, int, int)
 {
 	if (key == 27)
-		exit(0);
-
+		exit(0);	
+	//std::cout << key << std::endl;
 	keys[key] = true;
 }
 
@@ -127,6 +132,7 @@ void bindFuncOpenGL()
 	//Keyboard
 	glutKeyboardFunc(keyboard);
 	glutKeyboardUpFunc(keyboardup);
+	//glutMouseFunc(mousefunc);
 
 	//Mouse
 	//glutMouseFunc(mouse);
@@ -141,6 +147,7 @@ void configureOpenGL()
 	glutInitWindowSize(800, 600);
 	glutCreateWindow("Crystal Point");
 	glutFullScreen();
+	//glutPositionWindow((glutGet(GLUT_SCREEN_WIDTH) / 2) - (glutGet(GLUT_WINDOW_WIDTH) / 2), (glutGet(GLUT_SCREEN_HEIGHT) / 2) - (glutGet(GLUT_WINDOW_HEIGHT) / 2));
 
 	//Depth testing
 	glEnable(GL_DEPTH_TEST);
@@ -153,7 +160,7 @@ void configureOpenGL()
 	glEnable(GL_ALPHA_TEST);
 	glAlphaFunc(GL_GREATER, 0.01f);
 
-	//Lighting
+	Lighting
 	GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
 	GLfloat mat_shininess[] = { 50.0 };
 	GLfloat light_position[] = { 30.0, 30.0, 30.0, 0.0 };
@@ -174,5 +181,6 @@ void configureOpenGL()
 
 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 - 0
Player.cpp

@@ -4,9 +4,38 @@
 
 Player::Player()
 {
+	right = new Weapon("models/weapons/ZwaardMetTextures/TextureZwaard.obj");
+	left = new Weapon("models/weapons/ZwaardMetTextures/TextureZwaard.obj");
 }
 
 
 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
Player.h

@@ -7,11 +7,22 @@ class Player
 public:
 	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:
 	int level;
 	int xp;
-	Weapon rigth;
-	Weapon left;
+	Weapon* right = nullptr;
+	Weapon* left = nullptr;
 	vector<Weapon> weapons;
 };
 

+ 19 - 1
Weapon.cpp

@@ -1,10 +1,28 @@
 #include "Weapon.h"
 
-Weapon::Weapon()
+Weapon::Weapon(const string &filename)
 {
+	weaponModel = new Model(filename);
 }
 
+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
Weapon.h

@@ -1,10 +1,16 @@
 #pragma once
 #include "Header.h"
+#include "Model.h"
 
 class Weapon
 {
-public:
+public:	
+	Weapon(const string &filename);
 	Weapon();
 	~Weapon();
+	void draw_weapon(void);
+private:
+	Model *weaponModel = nullptr;
+	float scale = 0.5f;	
 };