Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/bezierTrack/src/track.cc @ 3017

Last change on this file since 3017 was 3017, checked in by bensch, 20 years ago

orxonox/branches/bezierTrack: fixed small error with k++, ++k.

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