| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- //
- // Created by janco on 25-5-16.
- //
- #include "Weapon.h"
- #include "Model.h"
- #include <iostream>
- #include <string>
- #include <cmath>
- Weapon::Weapon(std::string name, int damage, Element e, std::string modelFilename, float scale, Vec3f location, Vec2f rotation,
- Vec3f offsetPlayer, Vec3f ankerPoint,
- Vec2f maxRotation, Vec2f minRotation,
- Vec3f collision){
- weaponmodel = Model::load(modelFilename);
- rotate(rotation);
- move(location);
- this->scale = scale;
- this->name = name;
- this->damage = damage;
- this->element = e;
- this->offsetPlayer = offsetPlayer;
- this->ankerPoint = ankerPoint;
- this->maxRotation = maxRotation;
- this->minRotation = minRotation;
- this->collisionPoint = collisionPoint;
- };
- 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;
- }
- 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)
- {
- 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);
- 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);
- weaponmodel->draw();
- glPopMatrix();
- glPushMatrix();
- glPopMatrix();
- }
- }
|