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