jancoow 9 роки тому
батько
коміт
27dfaf74c4
7 змінених файлів з 36 додано та 28 видалено
  1. 3 6
      CrystalPoint.cpp
  2. 1 1
      Main.cpp
  3. 11 2
      Player.cpp
  4. 13 13
      Weapon.cpp
  5. 1 1
      World.cpp
  6. 6 4
      weapons.json
  7. 1 1
      worlds/small.json

+ 3 - 6
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

+ 1 - 1
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();

+ 11 - 2
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);
 }

+ 13 - 13
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();
     }

+ 1 - 1
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();

+ 6 - 4
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 ]
       }
     }
   ]

+ 1 - 1
worlds/small.json

@@ -12,7 +12,7 @@
 	"music": "WAVE/world1.wav"
   },
   "player": {
-    "startposition": [ 20, 0, 20 ]
+    "startposition": [ -10, -10, -10 ]
   },
   "objects": [ ],
   "portal": {