Commit fa1a095c authored by ottona's avatar ottona

gun mechanics working, added sky, added su35

parent e59975ed
......@@ -13,8 +13,14 @@ unix:LIBS += -lIrrlicht
DESTDIR = ../bin
HEADERS += \
../src/FlaSimApp.hpp
../src/FlaSimApp.hpp \
../src/FireUnit.hpp \
../src/Globals.hpp \
../src/TurretCamAnimator.hpp
SOURCES += \
../src/FlaSimApp.cpp \
../src/main.cpp
../src/main.cpp \
../src/FireUnit.cpp \
../src/Globals.cpp \
../src/TurretCamAnimator.cpp
This diff is collapsed.
This diff is collapsed.
# Blender MTL File: 'None'
# Material Count: 1
newmtl None
Ns 0
Ka 0.000000 0.000000 0.000000
Kd 0.8 0.8 0.8
Ks 0.8 0.8 0.8
d 1
illum 2
# Blender v2.79 (sub 0) OBJ File: ''
# www.blender.org
mtllib guns.mtl
o Cylinder.001
v -0.148360 1.567710 -0.766577
v -0.148360 1.533830 2.907069
v -0.138605 1.566750 -0.766577
v -0.145215 1.533520 2.907069
v -0.129226 1.563904 -0.766577
v -0.142191 1.532603 2.907069
v -0.120581 1.559284 -0.766577
v -0.139404 1.531114 2.907069
v -0.113005 1.553066 -0.766577
v -0.136962 1.529109 2.907069
v -0.106786 1.545489 -0.766577
v -0.134957 1.526666 2.907069
v -0.102166 1.536845 -0.766577
v -0.133467 1.523879 2.907069
v -0.099321 1.527465 -0.766577
v -0.132550 1.520855 2.907069
v -0.098360 1.517710 -0.766577
v -0.132240 1.517710 2.907069
v -0.099321 1.507956 -0.766577
v -0.132550 1.514566 2.907069
v -0.102166 1.498576 -0.766577
v -0.133467 1.511542 2.907069
v -0.106786 1.489932 -0.766577
v -0.134957 1.508755 2.907069
v -0.113005 1.482355 -0.766577
v -0.136962 1.506312 2.907069
v -0.120581 1.476137 -0.766577
v -0.139404 1.504307 2.907069
v -0.129226 1.471516 -0.766577
v -0.142191 1.502818 2.907069
v -0.138605 1.468671 -0.766577
v -0.145215 1.501900 2.907069
v -0.148360 1.467710 -0.766577
v -0.148360 1.501591 2.907069
v -0.158114 1.468671 -0.766577
v -0.151505 1.501900 2.907069
v -0.167494 1.471516 -0.766577
v -0.154529 1.502818 2.907069
v -0.176138 1.476137 -0.766577
v -0.157316 1.504307 2.907069
v -0.183715 1.482355 -0.766577
v -0.159758 1.506312 2.907069
v -0.189933 1.489932 -0.766577
v -0.161763 1.508755 2.907069
v -0.194554 1.498576 -0.766577
v -0.163253 1.511542 2.907069
v -0.197399 1.507956 -0.766577
v -0.164170 1.514566 2.907069
v -0.198360 1.517710 -0.766577
v -0.164480 1.517710 2.907069
v -0.197399 1.527465 -0.766577
v -0.164170 1.520855 2.907069
v -0.194554 1.536845 -0.766577
v -0.163253 1.523879 2.907069
v -0.189933 1.545489 -0.766577
v -0.161763 1.526666 2.907069
v -0.183715 1.553066 -0.766577
v -0.159758 1.529109 2.907069
v -0.176138 1.559284 -0.766577
v -0.157316 1.531114 2.907069
v -0.167494 1.563905 -0.766577
v -0.154529 1.532603 2.907069
v -0.158114 1.566750 -0.766577
v -0.151505 1.533520 2.907069
vn 0.0980 0.9951 0.0092
vn 0.2903 0.9569 0.0092
vn 0.4714 0.8819 0.0092
vn 0.6344 0.7730 0.0092
vn 0.7730 0.6344 0.0092
vn 0.8819 0.4714 0.0092
vn 0.9569 0.2903 0.0092
vn 0.9951 0.0980 0.0092
vn 0.9951 -0.0980 0.0092
vn 0.9569 -0.2903 0.0092
vn 0.8819 -0.4714 0.0092
vn 0.7730 -0.6344 0.0092
vn 0.6344 -0.7730 0.0092
vn 0.4714 -0.8819 0.0092
vn 0.2903 -0.9569 0.0092
vn 0.0980 -0.9951 0.0092
vn -0.0980 -0.9951 0.0092
vn -0.2903 -0.9569 0.0092
vn -0.4714 -0.8819 0.0092
vn -0.6344 -0.7730 0.0092
vn -0.7730 -0.6344 0.0092
vn -0.8819 -0.4714 0.0092
vn -0.9569 -0.2903 0.0092
vn -0.9951 -0.0980 0.0092
vn -0.9951 0.0980 0.0092
vn -0.9569 0.2903 0.0092
vn -0.8819 0.4714 0.0092
vn -0.7730 0.6344 0.0092
vn -0.6344 0.7730 0.0092
vn -0.4714 0.8819 0.0092
vn 0.0000 0.0000 1.0000
vn -0.2903 0.9569 0.0092
vn -0.0980 0.9951 0.0092
vn -0.0000 0.0000 -1.0000
usemtl None
s off
f 1//1 2//1 4//1 3//1
f 3//2 4//2 6//2 5//2
f 5//3 6//3 8//3 7//3
f 7//4 8//4 10//4 9//4
f 9//5 10//5 12//5 11//5
f 11//6 12//6 14//6 13//6
f 13//7 14//7 16//7 15//7
f 15//8 16//8 18//8 17//8
f 17//9 18//9 20//9 19//9
f 19//10 20//10 22//10 21//10
f 21//11 22//11 24//11 23//11
f 23//12 24//12 26//12 25//12
f 25//13 26//13 28//13 27//13
f 27//14 28//14 30//14 29//14
f 29//15 30//15 32//15 31//15
f 31//16 32//16 34//16 33//16
f 33//17 34//17 36//17 35//17
f 35//18 36//18 38//18 37//18
f 37//19 38//19 40//19 39//19
f 39//20 40//20 42//20 41//20
f 41//21 42//21 44//21 43//21
f 43//22 44//22 46//22 45//22
f 45//23 46//23 48//23 47//23
f 47//24 48//24 50//24 49//24
f 49//25 50//25 52//25 51//25
f 51//26 52//26 54//26 53//26
f 53//27 54//27 56//27 55//27
f 55//28 56//28 58//28 57//28
f 57//29 58//29 60//29 59//29
f 59//30 60//30 62//30 61//30
f 4//31 2//31 64//31 62//31 60//31 58//31 56//31 54//31 52//31 50//31 48//31 46//31 44//31 42//31 40//31 38//31 36//31 34//31 32//31 30//31 28//31 26//31 24//31 22//31 20//31 18//31 16//31 14//31 12//31 10//31 8//31 6//31
f 61//32 62//32 64//32 63//32
f 63//33 64//33 2//33 1//33
f 1//34 3//34 5//34 7//34 9//34 11//34 13//34 15//34 17//34 19//34 21//34 23//34 25//34 27//34 29//34 31//34 33//34 35//34 37//34 39//34 41//34 43//34 45//34 47//34 49//34 51//34 53//34 55//34 57//34 59//34 61//34 63//34
o Cylinder
v 0.152802 1.567710 -0.766577
v 0.152802 1.533830 2.907069
v 0.162556 1.566750 -0.766577
v 0.155947 1.533520 2.907069
v 0.171936 1.563904 -0.766577
v 0.158971 1.532603 2.907069
v 0.180580 1.559284 -0.766577
v 0.161758 1.531114 2.907069
v 0.188157 1.553066 -0.766577
v 0.164200 1.529109 2.907069
v 0.194375 1.545489 -0.766577
v 0.166205 1.526666 2.907069
v 0.198996 1.536845 -0.766577
v 0.167695 1.523879 2.907069
v 0.201841 1.527465 -0.766577
v 0.168612 1.520855 2.907069
v 0.202802 1.517710 -0.766577
v 0.168922 1.517710 2.907069
v 0.201841 1.507956 -0.766577
v 0.168612 1.514566 2.907069
v 0.198996 1.498576 -0.766577
v 0.167695 1.511542 2.907069
v 0.194375 1.489932 -0.766577
v 0.166205 1.508755 2.907069
v 0.188157 1.482355 -0.766577
v 0.164200 1.506312 2.907069
v 0.180580 1.476137 -0.766577
v 0.161758 1.504307 2.907069
v 0.171936 1.471516 -0.766577
v 0.158971 1.502818 2.907069
v 0.162556 1.468671 -0.766577
v 0.155947 1.501900 2.907069
v 0.152802 1.467710 -0.766577
v 0.152802 1.501591 2.907069
v 0.143047 1.468671 -0.766577
v 0.149657 1.501900 2.907069
v 0.133668 1.471516 -0.766577
v 0.146633 1.502818 2.907069
v 0.125023 1.476137 -0.766577
v 0.143846 1.504307 2.907069
v 0.117447 1.482355 -0.766577
v 0.141404 1.506312 2.907069
v 0.111228 1.489932 -0.766577
v 0.139399 1.508755 2.907069
v 0.106608 1.498576 -0.766577
v 0.137909 1.511542 2.907069
v 0.103763 1.507956 -0.766577
v 0.136992 1.514566 2.907069
v 0.102802 1.517710 -0.766577
v 0.136682 1.517710 2.907069
v 0.103763 1.527465 -0.766577
v 0.136992 1.520855 2.907069
v 0.106608 1.536845 -0.766577
v 0.137909 1.523879 2.907069
v 0.111229 1.545489 -0.766577
v 0.139399 1.526666 2.907069
v 0.117447 1.553066 -0.766577
v 0.141404 1.529109 2.907069
v 0.125023 1.559284 -0.766577
v 0.143846 1.531114 2.907069
v 0.133668 1.563905 -0.766577
v 0.146633 1.532603 2.907069
v 0.143048 1.566750 -0.766577
v 0.149657 1.533520 2.907069
vn 0.0980 0.9951 0.0092
vn 0.2903 0.9569 0.0092
vn 0.4714 0.8819 0.0092
vn 0.6344 0.7730 0.0092
vn 0.7730 0.6344 0.0092
vn 0.8819 0.4714 0.0092
vn 0.9569 0.2903 0.0092
vn 0.9951 0.0980 0.0092
vn 0.9951 -0.0980 0.0092
vn 0.9569 -0.2903 0.0092
vn 0.8819 -0.4714 0.0092
vn 0.7730 -0.6344 0.0092
vn 0.6344 -0.7730 0.0092
vn 0.4714 -0.8819 0.0092
vn 0.2903 -0.9569 0.0092
vn 0.0980 -0.9951 0.0092
vn -0.0980 -0.9951 0.0092
vn -0.2903 -0.9569 0.0092
vn -0.4714 -0.8819 0.0092
vn -0.6344 -0.7730 0.0092
vn -0.7730 -0.6344 0.0092
vn -0.8819 -0.4714 0.0092
vn -0.9569 -0.2903 0.0092
vn -0.9951 -0.0980 0.0092
vn -0.9951 0.0980 0.0092
vn -0.9569 0.2903 0.0092
vn -0.8819 0.4714 0.0092
vn -0.7730 0.6344 0.0092
vn -0.6344 0.7730 0.0092
vn -0.4714 0.8819 0.0092
vn 0.0000 0.0000 1.0000
vn -0.2903 0.9569 0.0092
vn -0.0980 0.9951 0.0092
vn -0.0000 0.0000 -1.0000
usemtl None
s off
f 65//35 66//35 68//35 67//35
f 67//36 68//36 70//36 69//36
f 69//37 70//37 72//37 71//37
f 71//38 72//38 74//38 73//38
f 73//39 74//39 76//39 75//39
f 75//40 76//40 78//40 77//40
f 77//41 78//41 80//41 79//41
f 79//42 80//42 82//42 81//42
f 81//43 82//43 84//43 83//43
f 83//44 84//44 86//44 85//44
f 85//45 86//45 88//45 87//45
f 87//46 88//46 90//46 89//46
f 89//47 90//47 92//47 91//47
f 91//48 92//48 94//48 93//48
f 93//49 94//49 96//49 95//49
f 95//50 96//50 98//50 97//50
f 97//51 98//51 100//51 99//51
f 99//52 100//52 102//52 101//52
f 101//53 102//53 104//53 103//53
f 103//54 104//54 106//54 105//54
f 105//55 106//55 108//55 107//55
f 107//56 108//56 110//56 109//56
f 109//57 110//57 112//57 111//57
f 111//58 112//58 114//58 113//58
f 113//59 114//59 116//59 115//59
f 115//60 116//60 118//60 117//60
f 117//61 118//61 120//61 119//61
f 119//62 120//62 122//62 121//62
f 121//63 122//63 124//63 123//63
f 123//64 124//64 126//64 125//64
f 68//65 66//65 128//65 126//65 124//65 122//65 120//65 118//65 116//65 114//65 112//65 110//65 108//65 106//65 104//65 102//65 100//65 98//65 96//65 94//65 92//65 90//65 88//65 86//65 84//65 82//65 80//65 78//65 76//65 74//65 72//65 70//65
f 125//66 126//66 128//66 127//66
f 127//67 128//67 66//67 65//67
f 65//68 67//68 69//68 71//68 73//68 75//68 77//68 79//68 81//68 83//68 85//68 87//68 89//68 91//68 93//68 95//68 97//68 99//68 101//68 103//68 105//68 107//68 109//68 111//68 113//68 115//68 117//68 119//68 121//68 123//68 125//68 127//68
#include "FireUnit.hpp"
#include "Globals.hpp"
#include "TurretCamAnimator.hpp"
using namespace irr;
using namespace irr::core;
FireUnit::FireUnit()
{
turretAzimuth = Globals::getSceneManager()->addEmptySceneNode();
turretElevation = Globals::getSceneManager()->addMeshSceneNode(Globals::getSceneManager()->getMesh("../res/guns.obj"), turretAzimuth);
cam = Globals::getSceneManager()->addCameraSceneNode(turretElevation);
turretCamAnimator = new TurretCamAnimator(turretElevation);
cam->setNearValue(0.01f);
cam->setFarValue(4000.f);
cam->addAnimator(turretCamAnimator);
auto jet = Globals::getSceneManager()->addMeshSceneNode(Globals::getSceneManager()->getMesh("../res/SU35S.obj"));
jet->setPosition(vector3df(25.f, 0.f, 0.f));
auto a = Globals::getSceneManager()->createFlyStraightAnimator(vector3df(100.f, 100.f, -1000.f),
vector3df(100.f, 100.f, 1000.f),
16000,
true,
false);
jet->addAnimator(a);
a->drop();
}
FireUnit::~FireUnit()
{
cam->removeAnimator(turretCamAnimator);
delete turretCamAnimator;
}
bool FireUnit::OnEvent(const SEvent& e)
{
if (e.EventType == irr::EET_JOYSTICK_INPUT_EVENT)
{
f32 aziTurnCoeff = 0.f, elevTurnCoeff = 0.f;
const f32 DEAD_ZONE = 0.0100000f;
elevTurnCoeff =
(f32)e.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_Y] / -32767.f;
if (fabs(elevTurnCoeff) < DEAD_ZONE)
elevTurnCoeff = 0.f;
aziTurnCoeff =
(f32)e.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_X] / -32767.f;
if (fabs(aziTurnCoeff) < DEAD_ZONE)
aziTurnCoeff = 0.f;
if (e.JoystickEvent.IsButtonPressed(1))
{
// fire trigger pressed
}
else
{
// fire trigger released
}
if (e.JoystickEvent.IsButtonPressed(2))
{
// sec trigger pressed
}
else
{
// sec trigger released
}
vector3df rot = turretAzimuth->getRotation();
rot.Y -= 1.f * aziTurnCoeff;
if (rot.Y > 360.f)
rot.Y -= 360.f;
if (rot.Y < 0.f)
rot.Y += 360.f;
turretAzimuth->setRotation(rot);
rot = turretElevation->getRotation();
rot.X += 1.f * elevTurnCoeff;
if (rot.X > 5.f)
rot.X = 5.f;
if (rot.X < -85.f)
rot.X = -85.f;
turretElevation->setRotation(rot);
return true;
}
return false;
}
#ifndef FIREUNIT_HPP
#define FIREUNIT_HPP
#include <irrlicht.h>
class FireUnit : public irr::IEventReceiver
{
public:
FireUnit();
~FireUnit();
bool OnEvent(const irr::SEvent&);
private:
irr::scene::ICameraSceneNode *cam;
irr::scene::ISceneNode *turretElevation, *turretAzimuth;
irr::scene::ISceneNodeAnimator *turretCamAnimator;
};
#endif // FIREUNIT_HPP
#include "FlaSimApp.hpp"
#include <iostream>
#include "Globals.hpp"
using namespace std;
using namespace irr;
using namespace irr::core;
using namespace irr::video;
FlaSimApp::FlaSimApp()
: fireUnit()
{
dev = Globals::getDevice();
drv = Globals::getVideoDriver();
sman = Globals::getSceneManager();
sman->addSkyBoxSceneNode(drv->getTexture("../res/skytop.jpg"),
drv->getTexture("../res/skybottom.jpg"),
drv->getTexture("../res/sky3.jpg"),
drv->getTexture("../res/sky1.jpg"),
drv->getTexture("../res/sky0.jpg"),
drv->getTexture("../res/sky2.jpg")
);
scene::ILightSceneNode *sun = sman->addLightSceneNode();
sun->setLightType(ELT_DIRECTIONAL);
sun->setRotation(vector3df(45.f, 0.f, 0.f));
dev->setEventReceiver(this);
core::array<SJoystickInfo> joystickInfo;
if (dev->activateJoysticks(joystickInfo))
{
cout << "Joystick support is enabled and " << joystickInfo.size() << " joystick(s) are present." << endl;
}
}
FlaSimApp::~FlaSimApp()
{
}
void FlaSimApp::execute()
{
while (dev->run())
{
drv->beginScene(true, true, SColor(255, 128, 128, 128));
sman->drawAll();
drawScreenSpace();
drv->endScene();
}
}
bool FlaSimApp::OnEvent(const irr::SEvent &e)
{
return fireUnit.OnEvent(e);
}
void FlaSimApp::drawScreenSpace()
{
video::SMaterial matA;
matA.AmbientColor = video::SColor(255, 255, 0, 0);
matA.DiffuseColor = video::SColor(255, 255, 0, 0);
matA.ColorMaterial = video::ECM_NONE;
matA.AntiAliasing = video::EAAM_FULL_BASIC;
matA.Lighting = false;
matA.Thickness = 1.5f;
matA.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
drv->setMaterial(matA);
drv->setTransform(video::ETS_WORLD, core::IdentityMatrix);
drv->draw3DLine(vector3df(0.f, 0.f, 0.f), vector3df(1.f, 0.f, 0.f), video::SColor(255, 255, 0, 0));
drv->draw3DLine(vector3df(0.f, 0.f, 0.f), vector3df(0.f, 1.f, 0.f), video::SColor(255, 0, 255, 0));
drv->draw3DLine(vector3df(0.f, 0.f, 0.f), vector3df(0.f, 0.f, 1.f), video::SColor(255, 0, 0, 255));
}
#include <irrlicht.h>
#include "FireUnit.hpp"
class FlaSimApp : public irr::IEventReceiver
{
......@@ -11,8 +11,14 @@ public:
bool OnEvent(const irr::SEvent& e);
private:
void drawScreenSpace();
irr::IrrlichtDevice *dev;
irr::scene::ISceneManager *sman;
irr::video::IVideoDriver *drv;
irr::gui::IGUIEnvironment *gui;
FireUnit fireUnit;
};
#include "Globals.hpp"
#include <irrlicht.h>
using namespace irr;
Globals* Globals::instance = nullptr;
Globals::Globals()
{
dev = createDevice(video::EDT_OPENGL, core::dimension2du(1280, 800), 32, false, false, true);
drv = dev->getVideoDriver();
sman = dev->getSceneManager();
}
Globals::~Globals()
{
dev->drop();
instance = nullptr;
}
void Globals::shutdown()
{
if (instance)
delete instance;
}
IrrlichtDevice* Globals::getDevice()
{
if (!instance)
instance = new Globals();
return instance->dev;
}
video::IVideoDriver* Globals::getVideoDriver()
{
if (!instance)
instance = new Globals();
return instance->drv;
}
scene::ISceneManager* Globals::getSceneManager()
{
if (!instance)
instance = new Globals();
return instance->sman;
}
#ifndef GLOBALS_HPP
#define GLOBALS_HPP
namespace irr
{
class IrrlichtDevice;
namespace scene
{
class ISceneManager;
}
namespace video
{
class IVideoDriver;
}
}
class Globals
{
public:
static class irr::IrrlichtDevice* getDevice();
static class irr::scene::ISceneManager* getSceneManager();
static class irr::video::IVideoDriver* getVideoDriver();
static void shutdown();
private:
Globals();
~Globals();
static Globals* instance;
class irr::IrrlichtDevice* dev;
class irr::scene::ISceneManager* sman;
class irr::video::IVideoDriver* drv;
};
#endif // GLOBALS_HPP
#include "TurretCamAnimator.hpp"
using namespace irr;
TurretCamAnimator::TurretCamAnimator(scene::ISceneNode *_parent)
: ISceneNodeAnimator()
, parent(_parent)
{
}
TurretCamAnimator::~TurretCamAnimator()
{
}
void TurretCamAnimator::animateNode(scene::ISceneNode* node, u32)
{
if (!parent || !node)
return;
parent->updateAbsolutePosition();
core::vector3df nodeUpVector, nodeTarget;
const core::matrix4& absTrans = parent->getAbsoluteTransformation();
absTrans.rotateVect(nodeUpVector, core::vector3df(0.f, 1.f, 0.f));
absTrans.transformVect(nodeTarget, core::vector3df(0.f, 0.f, 100.f));
node->setPosition(parent->getAbsolutePosition() + core::vector3df(0.f, 1.65f, 0.f));
if (node->getType() == scene::ESNT_CAMERA)
{
static_cast<scene::ICameraSceneNode*>(node)->setUpVector(nodeUpVector);
static_cast<scene::ICameraSceneNode*>(node)->setTarget(nodeTarget);
}
}
#include <irrlicht.h>
class TurretCamAnimator : public irr::scene::ISceneNodeAnimator
{
public:
TurretCamAnimator(irr::scene::ISceneNode* _parent);
~TurretCamAnimator();
void animateNode(irr::scene::ISceneNode* node, irr::u32 timeMs);
irr::scene::ISceneNodeAnimator* createClone(irr::scene::ISceneNode* , irr::scene::ISceneManager* ){return nullptr;}
private:
TurretCamAnimator();
irr::scene::ISceneNode *parent;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment