[2068] | 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: |
---|
[2080] | 14 | main-programmer: Christian Meyer |
---|
[3005] | 15 | co-programmer: ... |
---|
[2068] | 16 | */ |
---|
| 17 | |
---|
| 18 | #include "track.h" |
---|
| 19 | |
---|
| 20 | using namespace std; |
---|
| 21 | |
---|
[2141] | 22 | /** |
---|
| 23 | \brief creates a null Track part |
---|
| 24 | */ |
---|
[2101] | 25 | Track::Track () |
---|
| 26 | { |
---|
[3010] | 27 | this->next = NULL; |
---|
| 28 | this->previous = NULL; |
---|
[3028] | 29 | mainTime = .0; |
---|
[2101] | 30 | |
---|
[3028] | 31 | |
---|
[3010] | 32 | curve = BezierCurve(); |
---|
[2068] | 33 | } |
---|
| 34 | |
---|
[2141] | 35 | /** |
---|
| 36 | \brief removes the Track part from memory |
---|
| 37 | */ |
---|
[2068] | 38 | Track::~Track () |
---|
| 39 | { |
---|
[3010] | 40 | if (next != NULL) |
---|
| 41 | delete next; |
---|
| 42 | if (previous != NULL) |
---|
| 43 | delete previous; |
---|
[2068] | 44 | } |
---|
| 45 | |
---|
[2636] | 46 | void Track::init() |
---|
| 47 | { |
---|
| 48 | |
---|
| 49 | } |
---|
| 50 | |
---|
[3013] | 51 | void Track::addPoint (Vector point) |
---|
[3010] | 52 | { |
---|
| 53 | curve.addNode(point); |
---|
[2636] | 54 | |
---|
[3010] | 55 | return; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | |
---|
[3013] | 59 | void Track::addHotPoint (Vector hotPoint) |
---|
[3010] | 60 | { |
---|
| 61 | |
---|
| 62 | return; |
---|
| 63 | } |
---|
| 64 | |
---|
[3028] | 65 | Vector Track::getPos (void) |
---|
| 66 | { |
---|
| 67 | return curve.calcPos (mainTime); |
---|
| 68 | } |
---|
[3010] | 69 | |
---|
[3014] | 70 | Vector Track::getPos (float t) |
---|
| 71 | { |
---|
| 72 | return curve.calcPos (t); |
---|
| 73 | } |
---|
[3028] | 74 | |
---|
| 75 | Vector Track::getDir (void) |
---|
| 76 | { |
---|
| 77 | return curve.calcDir (mainTime); |
---|
| 78 | } |
---|
| 79 | |
---|
[3015] | 80 | Vector Track::getDir (float t) |
---|
| 81 | { |
---|
| 82 | return curve.calcDir (t); |
---|
| 83 | } |
---|
[3014] | 84 | |
---|
[3028] | 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 | |
---|
[2141] | 94 | /** |
---|
[2551] | 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. |
---|
[2141] | 102 | */ |
---|
[2068] | 103 | void Track::map_camera (Location* lookat, Placement* camplc) |
---|
| 104 | { |
---|
[3010] | 105 | // Line trace(*offset, *end - *offset); |
---|
| 106 | // float l = trace.len (); |
---|
[2551] | 107 | |
---|
[3010] | 108 | // float r = (lookat->dist)*PI / l; |
---|
| 109 | // camplc->r = trace.r + (trace.a * ((lookat->dist-10.0) / l)) + Vector(0,0,5.0); |
---|
[3028] | 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 | |
---|
[2551] | 114 | Vector w(0.0,0.0,0.0); |
---|
[3010] | 115 | // w=Vector(0,0,0) - ((trace.r + (trace.a * ((lookat->dist) / l)) - camplc->r)); |
---|
[3028] | 116 | w = Vector(0,0,0) - (((curve.calcPos(mainTime)) + ((curve.calcDir(mainTime)) * ((lookat->dist) / mainTime)) - camplc->pos)); |
---|
[2551] | 117 | //Vector up(0.0,sin(r),cos(r)); // corrupt... |
---|
| 118 | Vector up(0.0, 0.0, 1.0); |
---|
| 119 | |
---|
[3013] | 120 | camplc->rot = Quaternion(w, up); |
---|
[2551] | 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); |
---|
[2068] | 125 | } |
---|
| 126 | |
---|
[2141] | 127 | /** |
---|
[2551] | 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. |
---|
[2141] | 139 | */ |
---|
[2080] | 140 | bool Track::map_coords (Location* loc, Placement* plc) |
---|
[2068] | 141 | { |
---|
[3028] | 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 | |
---|
[2551] | 146 | /* this quaternion represents the rotation from start-vector (0,0,1) to the direction of |
---|
| 147 | * the track */ |
---|
[3028] | 148 | Quaternion dir(curve.calcDir(mainTime), Vector(0,0,1)); |
---|
[2551] | 149 | |
---|
[3028] | 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; |
---|
[2080] | 152 | |
---|
| 153 | return false; |
---|
[2068] | 154 | } |
---|
| 155 | |
---|
[2141] | 156 | /** |
---|
| 157 | \brief this is called when a WorldEntity enters a Track part |
---|
| 158 | \param entity: pointer to the WorldEntity in question |
---|
| 159 | |
---|
[2551] | 160 | You can do stuff like add or remove effects, do some coordinate finetuning |
---|
| 161 | or whatever in here. |
---|
[2141] | 162 | */ |
---|
[2080] | 163 | void Track::post_enter (WorldEntity* entity) |
---|
| 164 | { |
---|
| 165 | } |
---|
[2068] | 166 | |
---|
[2141] | 167 | /** |
---|
| 168 | \brief this is called when a WorldEntity leaves a Track part |
---|
| 169 | \param entity: pointer to the WorldEntity in question |
---|
| 170 | |
---|
[2551] | 171 | You can do stuff like add or remove effects, do some coordinate finetuning |
---|
| 172 | or whatever in here. |
---|
[2141] | 173 | */ |
---|
[2080] | 174 | void Track::post_leave (WorldEntity* entity) |
---|
| 175 | { |
---|
| 176 | } |
---|
[2068] | 177 | |
---|
[2141] | 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 | */ |
---|
[2080] | 184 | void Track::tick (float deltaT) |
---|
| 185 | { |
---|
[3028] | 186 | mainTime += deltaT/10; |
---|
[2080] | 187 | } |
---|
[2068] | 188 | |
---|
| 189 | |
---|
[2080] | 190 | |
---|
| 191 | |
---|
| 192 | |
---|