1 | |
---|
2 | |
---|
3 | /* |
---|
4 | orxonox - the future of 3D-vertical-scrollers |
---|
5 | |
---|
6 | Copyright (C) 2004 orx |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2, or (at your option) |
---|
11 | any later version. |
---|
12 | |
---|
13 | ### File Specific: |
---|
14 | main-programmer: Christian Meyer |
---|
15 | co-programmer: ... |
---|
16 | */ |
---|
17 | |
---|
18 | #include "track.h" |
---|
19 | |
---|
20 | using namespace std; |
---|
21 | |
---|
22 | /** |
---|
23 | \brief creates a null Track part |
---|
24 | */ |
---|
25 | Track::Track () |
---|
26 | { |
---|
27 | this->next = NULL; |
---|
28 | this->previous = NULL; |
---|
29 | mainTime = .0; |
---|
30 | |
---|
31 | |
---|
32 | curve = BezierCurve(); |
---|
33 | } |
---|
34 | |
---|
35 | /** |
---|
36 | \brief removes the Track part from memory |
---|
37 | */ |
---|
38 | Track::~Track () |
---|
39 | { |
---|
40 | if (next != NULL) |
---|
41 | delete next; |
---|
42 | if (previous != NULL) |
---|
43 | delete previous; |
---|
44 | } |
---|
45 | |
---|
46 | void Track::init() |
---|
47 | { |
---|
48 | |
---|
49 | } |
---|
50 | |
---|
51 | void Track::addPoint (Vector point) |
---|
52 | { |
---|
53 | curve.addNode(point); |
---|
54 | |
---|
55 | return; |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | void Track::addHotPoint (Vector hotPoint) |
---|
60 | { |
---|
61 | |
---|
62 | return; |
---|
63 | } |
---|
64 | |
---|
65 | Vector Track::getPos (void) |
---|
66 | { |
---|
67 | return curve.calcPos (mainTime); |
---|
68 | } |
---|
69 | |
---|
70 | Vector Track::getPos (float t) |
---|
71 | { |
---|
72 | return curve.calcPos (t); |
---|
73 | } |
---|
74 | |
---|
75 | Vector Track::getDir (void) |
---|
76 | { |
---|
77 | return curve.calcDir (mainTime); |
---|
78 | } |
---|
79 | |
---|
80 | Vector Track::getDir (float t) |
---|
81 | { |
---|
82 | return curve.calcDir (t); |
---|
83 | } |
---|
84 | |
---|
85 | Quaternion Track::getQuat (void) |
---|
86 | { |
---|
87 | return curve.calcQuat (mainTime); |
---|
88 | } |
---|
89 | Quaternion Track::getQuat (float t) |
---|
90 | { |
---|
91 | return curve.calcQuat (t); |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | \brief calculate a camera Placement from a "look at"-Location |
---|
96 | \param lookat: the Location the camera should be centered on |
---|
97 | \param camplc: pointer to a buffer where the new camera Placement should be put into |
---|
98 | |
---|
99 | Theoretically you can place the camera wherever you want, but for the sake of |
---|
100 | common sense I suggest that you at least try to keep the thing that should be looked |
---|
101 | at inside camera boundaries. |
---|
102 | */ |
---|
103 | void Track::map_camera (Location* lookat, Placement* camplc) |
---|
104 | { |
---|
105 | // Line trace(*offset, *end - *offset); |
---|
106 | // float l = trace.len (); |
---|
107 | |
---|
108 | // float r = (lookat->dist)*PI / l; |
---|
109 | // camplc->r = trace.r + (trace.a * ((lookat->dist-10.0) / l)) + Vector(0,0,5.0); |
---|
110 | |
---|
111 | // camplc->pos = curve.calcPos(t) + (curve.calcDir(t)* ((lookat->dist-10.0)/t)) + Vector(-5,0,5); |
---|
112 | camplc->pos = curve.calcPos(mainTime) + (curve.calcDir(mainTime) * 5) + Vector (0,0,5); |
---|
113 | |
---|
114 | Vector w(0.0,0.0,0.0); |
---|
115 | // w=Vector(0,0,0) - ((trace.r + (trace.a * ((lookat->dist) / l)) - camplc->r)); |
---|
116 | w = Vector(0,0,0) - (((curve.calcPos(mainTime)) + ((curve.calcDir(mainTime)) * ((lookat->dist) / mainTime)) - camplc->pos)); |
---|
117 | //Vector up(0.0,sin(r),cos(r)); // corrupt... |
---|
118 | Vector up(0.0, 0.0, 1.0); |
---|
119 | |
---|
120 | camplc->rot = Quaternion(w, up); |
---|
121 | |
---|
122 | //printf("\n------\nup vector: [%f, %f, %f]\n", up.x, up.y, up.z); |
---|
123 | //printf("direction: [%f, %f, %f]\n", w.x, w.y, w.z); |
---|
124 | //printf("quaternion: w[ %f ], v[ %f, %f, %f ]\n", camplc->w.w, camplc->w.v.x, camplc->w.v.y, camplc->w.v.z); |
---|
125 | } |
---|
126 | |
---|
127 | /** |
---|
128 | \brief calculate a Placement from a given Location |
---|
129 | \param loc: the Location the entity is in |
---|
130 | \param plc: a pointer to a buffer where the corresponding Placement should be put |
---|
131 | into |
---|
132 | \return: true if track changes - false if track stays |
---|
133 | |
---|
134 | There are no limitations to how you transform a Location into a Placement, but for |
---|
135 | the sake of placement compatibility between track parts you should make sure that |
---|
136 | the resulting Placement at dist == 0 is equal to the offset Vector and the Placement |
---|
137 | at dist == len() is equal to the end Vector. Elseway there will be ugly artifacts |
---|
138 | when transfering between track parts. |
---|
139 | */ |
---|
140 | bool Track::map_coords (Location* loc, Placement* plc) |
---|
141 | { |
---|
142 | this->setPosition (curve.calcPos (mainTime), WORLD); |
---|
143 | this->setRotation (curve.calcQuat (mainTime), WORLD); |
---|
144 | // printf ("x: %f; y:%f; z:%f\n", getRotation(WORLD).v.x, getRotation(WORLD).v.y, getRotation(WORLD).v.z); |
---|
145 | |
---|
146 | /* this quaternion represents the rotation from start-vector (0,0,1) to the direction of |
---|
147 | * the track */ |
---|
148 | Quaternion dir(curve.calcDir(mainTime), Vector(0,0,1)); |
---|
149 | |
---|
150 | plc->pos = this->getPosition(WORLD);// curve.calcPos(t) + (curve.calcDir(t) * ((loc->dist) / t)) + /*dir.apply*/(loc->pos); |
---|
151 | plc->rot = this->getRotation(WORLD);dir * loc->rot; |
---|
152 | |
---|
153 | return false; |
---|
154 | } |
---|
155 | |
---|
156 | /** |
---|
157 | \brief this is called when a WorldEntity enters a Track part |
---|
158 | \param entity: pointer to the WorldEntity in question |
---|
159 | |
---|
160 | You can do stuff like add or remove effects, do some coordinate finetuning |
---|
161 | or whatever in here. |
---|
162 | */ |
---|
163 | void Track::post_enter (WorldEntity* entity) |
---|
164 | { |
---|
165 | } |
---|
166 | |
---|
167 | /** |
---|
168 | \brief this is called when a WorldEntity leaves a Track part |
---|
169 | \param entity: pointer to the WorldEntity in question |
---|
170 | |
---|
171 | You can do stuff like add or remove effects, do some coordinate finetuning |
---|
172 | or whatever in here. |
---|
173 | */ |
---|
174 | void Track::post_leave (WorldEntity* entity) |
---|
175 | { |
---|
176 | } |
---|
177 | |
---|
178 | /** |
---|
179 | \brief this is called every frame |
---|
180 | \param deltaT: amount of time passed since the last frame in seconds |
---|
181 | |
---|
182 | Do time based or polling scripts here. |
---|
183 | */ |
---|
184 | void Track::tick (float deltaT) |
---|
185 | { |
---|
186 | mainTime += deltaT/10; |
---|
187 | } |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | |
---|
192 | |
---|