-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
133 lines (98 loc) · 3.02 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include "Supernova.h"
using namespace Supernova;
Scene scene;
Scene uiscene;
Camera camera(&scene);
Shape terrain(&scene);
Model car(&scene);
Model house(&scene);
SkyBox sky(&scene);
Audio carengine(&scene);
Fog fog(&scene);
Light* carlight = NULL;
Light* sun = NULL;
Text text(&uiscene);
float curve = 0;
float speed = 0;
float rotation = 0;
bool up, down, left, right;
void onUpdate();
void init(){
scene.setAmbientLight(0.5);
scene.setBackgroundColor(0.8, 0.8, 0.8);
scene.setCamera(camera.getEntity());
fog.setType(FogType::LINEAR);
fog.setLinearStart(30);
fog.setLinearEnd(100);
camera.setPosition(0, 5, 20);
house.loadModel("old-house/old-house.obj");
house.setRotation(-1,2,0);
house.setRotation(-90,180,0);
house.setPosition(6,0,6);
terrain.createPlane(200, 200);
terrain.setTexture("road.png");
car.loadModel("jeep/Jeep.obj");
car.setScale(0.5);
car.addChild(&carengine);
carengine.loadAudio("engine.wav");
carengine.setSound3D(true);
carengine.setLopping(true);
carengine.setDopplerFactor(10.0);
carengine.setMinMaxDistance(1, 100);
carengine.setAttenuationModel(AudioAttenuation::LINEAR_DISTANCE);
carengine.play();
sky.setTextureFront("ely_hills/hills_lf.tga");
sky.setTextureBack("ely_hills/hills_rt.tga");
sky.setTextureLeft("ely_hills/hills_bk.tga");
sky.setTextureRight("ely_hills/hills_ft.tga");
sky.setTextureUp("ely_hills/hills_up.tga");
sky.setTextureDown("ely_hills/hills_dn.tga");
sky.setAlpha(0.2);
if (!carlight)
carlight = new Light(&scene);
carlight->setType(LightType::SPOT);
carlight->setConeAngle(80, 100);
carlight->setPosition(0, 5, 8);
carlight->setDirection(0, 0, 30);
carlight->setIntensity(50);
carlight->setShadows(true);
car.addChild(carlight);
if (!sun)
sun = new Light(&scene);
sun->setType(LightType::DIRECTIONAL);
sun->setDirection(0, -0.4, 0.6);
sun->setShadows(true);
text.setPosition(100, 100, 0);
Engine::setScene(&scene);
Engine::addSceneLayer(&uiscene);
Engine::onUpdate = onUpdate;
}
void onUpdate(){
text.setText(std::to_string(Engine::getFramerate()).c_str());
if (Input::isKeyPressed(S_KEY_UP)){
speed += 0.1;
}else if (Input::isKeyPressed(S_KEY_DOWN)){
speed -= 0.1;
}
speed *= 0.95;
carengine.setVolume(1.0 + (abs(speed) * 0.5));
carengine.setSpeed(1.0 + (abs(speed) * 0.5));
if (Input::isKeyPressed(S_KEY_LEFT)){
if (curve < 3)
curve += 0.4;
}else if (Input::isKeyPressed(S_KEY_RIGHT)){
if (curve > -3)
curve -= 0.4;
}else{
curve = 0;
}
rotation += curve;
if (rotation > 360)
rotation = rotation - 360;
if (rotation < 0)
rotation = 360 + rotation;
Vector3 vDir(cos(Angle::degToRad(rotation-90)), 0, -sin(Angle::degToRad(rotation-90)));
car.setRotation(0,rotation,0);
car.setPosition(car.getPosition() + (vDir*speed));
camera.setView(car.getPosition());
}