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->ID = 0; |
---|
28 | this->offset = NULL; |
---|
29 | this->end = NULL; |
---|
30 | this->nextID = 0; |
---|
31 | this->setClassName ("Track"); |
---|
32 | } |
---|
33 | |
---|
34 | /** |
---|
35 | \brief creates a functional base Track part |
---|
36 | \param number: the ID if this Track part |
---|
37 | \param next: the ID of the next Track part |
---|
38 | \param start: pointer to an anchor point (Vector) representing the offset of this part |
---|
39 | \param finish: pointer to an anchor point (Vector) representing the end of this part |
---|
40 | */ |
---|
41 | Track::Track (Uint32 number, Uint32 next, Vector* start, Vector* finish) |
---|
42 | { |
---|
43 | this->ID = number; |
---|
44 | this->offset = start; |
---|
45 | this->end = finish; |
---|
46 | this->nextID = next; |
---|
47 | this->setClassName ("Track"); |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | \brief removes the Track part from memory |
---|
52 | */ |
---|
53 | Track::~Track () |
---|
54 | { |
---|
55 | } |
---|
56 | |
---|
57 | void Track::init() |
---|
58 | { |
---|
59 | |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | /** |
---|
64 | \brief calculate a camera Placement from a "look at"-Location |
---|
65 | \param lookat: the Location the camera should be centered on |
---|
66 | \param camplc: pointer to a buffer where the new camera Placement should be put into |
---|
67 | |
---|
68 | Theoretically you can place the camera wherever you want, but for the sake of |
---|
69 | common sense I suggest that you at least try to keep the thing that should be looked |
---|
70 | at inside camera boundaries. |
---|
71 | */ |
---|
72 | void Track::mapCamera (Location* lookat, Placement* camplc) |
---|
73 | { |
---|
74 | Line trace(*offset, *end - *offset); |
---|
75 | float l = trace.len (); |
---|
76 | |
---|
77 | // camplc->r = *offset + Vector(0,0,0.5); |
---|
78 | // camplc->w = Quaternion (trace.a, Vector(0,0,1)); |
---|
79 | float r = (lookat->dist)*PI / l; |
---|
80 | camplc->r = trace.r + (trace.a * ((lookat->dist-10.0) / l)) + Vector(0,0,5.0); |
---|
81 | |
---|
82 | Vector w(0.0,0.0,0.0); |
---|
83 | w=Vector(0,0,0) - ((trace.r + (trace.a * ((lookat->dist) / l)) - camplc->r)); |
---|
84 | //Vector up(0.0,sin(r),cos(r)); // corrupt... |
---|
85 | Vector up(0.0, 0.0, 1.0); |
---|
86 | |
---|
87 | camplc->w = Quaternion(w, up); |
---|
88 | |
---|
89 | //printf("\n------\nup vector: [%f, %f, %f]\n", up.x, up.y, up.z); |
---|
90 | //printf("direction: [%f, %f, %f]\n", w.x, w.y, w.z); |
---|
91 | //printf("quaternion: w[ %f ], v[ %f, %f, %f ]\n", camplc->w.w, camplc->w.v.x, camplc->w.v.y, camplc->w.v.z); |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | \brief calculate a Placement from a given Location |
---|
96 | \param loc: the Location the entity is in |
---|
97 | \param plc: a pointer to a buffer where the corresponding Placement should be put |
---|
98 | into |
---|
99 | \return: true if track changes - false if track stays |
---|
100 | |
---|
101 | There are no limitations to how you transform a Location into a Placement, but for |
---|
102 | the sake of placement compatibility between track parts you should make sure that |
---|
103 | the resulting Placement at dist == 0 is equal to the offset Vector and the Placement |
---|
104 | at dist == len() is equal to the end Vector. Elseway there will be ugly artifacts |
---|
105 | when transfering between track parts. |
---|
106 | */ |
---|
107 | bool Track::mapCoords (Location* loc, Placement* plc) |
---|
108 | { |
---|
109 | Line trace(*offset, *end - *offset); |
---|
110 | float l = trace.len (); |
---|
111 | |
---|
112 | /* change to the next track? */ |
---|
113 | if( loc->dist > l) |
---|
114 | { |
---|
115 | loc->dist -= l; |
---|
116 | loc->part = nextID; |
---|
117 | //FIXME: loc->track = this; |
---|
118 | return true; |
---|
119 | } |
---|
120 | |
---|
121 | /* this quaternion represents the rotation from start-vector (0,0,1) to the direction of |
---|
122 | * the track */ |
---|
123 | Quaternion dir(trace.a, Vector(0,0,1)); |
---|
124 | |
---|
125 | plc->r = trace.r + (trace.a * ((loc->dist) / l)) + /*dir.apply*/(loc->pos); |
---|
126 | plc->w = dir * loc->rot; |
---|
127 | |
---|
128 | return false; |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | /** |
---|
133 | \brief this is called when a WorldEntity enters a Track part |
---|
134 | \param entity: pointer to the WorldEntity in question |
---|
135 | |
---|
136 | You can do stuff like add or remove effects, do some coordinate finetuning |
---|
137 | or whatever in here. |
---|
138 | */ |
---|
139 | void Track::postEnter (WorldEntity* entity) |
---|
140 | { |
---|
141 | } |
---|
142 | |
---|
143 | |
---|
144 | /** |
---|
145 | \brief this is called when a WorldEntity leaves a Track part |
---|
146 | \param entity: pointer to the WorldEntity in question |
---|
147 | |
---|
148 | You can do stuff like add or remove effects, do some coordinate finetuning |
---|
149 | or whatever in here. |
---|
150 | */ |
---|
151 | void Track::postLeave (WorldEntity* entity) |
---|
152 | { |
---|
153 | } |
---|
154 | |
---|
155 | |
---|
156 | /** |
---|
157 | \brief this is called every frame |
---|
158 | \param deltaT: amount of time passed since the last frame in seconds |
---|
159 | |
---|
160 | Do time based or polling scripts here. |
---|
161 | */ |
---|
162 | void Track::tick (float deltaT) |
---|
163 | { |
---|
164 | } |
---|
165 | |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | |
---|