Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3015 was 3015, checked in by bensch, 19 years ago

orxonox/branches/bezierCurve: better algorithm

File size: 4.3 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  t+=.0001;
86  if (t> 1) t =0;
87  //  Line trace(*offset, *end - *offset);
88  //  float l = trace.len ();
89 
90  //  float r = (lookat->dist)*PI / l;
91  // camplc->r = trace.r + (trace.a * ((lookat->dist-10.0) / l)) + Vector(0,0,5.0);
92  camplc->pos = curve.calcPos(t) + (curve.calcDir(t)* ((lookat->dist-10.0)/t)) + Vector(-5,0,5);
93                                 
94  Vector w(0.0,0.0,0.0);
95  //  w=Vector(0,0,0) - ((trace.r + (trace.a * ((lookat->dist) / l)) - camplc->r));
96  w = Vector(0,0,0) - (((curve.calcPos(t)) + ((curve.calcDir(t)) * ((lookat->dist) / t)) - camplc->pos));
97  //Vector up(0.0,sin(r),cos(r)); // corrupt...
98  Vector up(0.0, 0.0, 1.0);
99
100  camplc->rot = Quaternion(w, up);
101
102  //printf("\n------\nup vector: [%f, %f, %f]\n", up.x, up.y, up.z);
103  //printf("direction: [%f, %f, %f]\n", w.x, w.y, w.z);
104  //printf("quaternion: w[ %f ], v[ %f, %f, %f ]\n", camplc->w.w, camplc->w.v.x, camplc->w.v.y, camplc->w.v.z);
105}
106
107/**
108   \brief calculate a Placement from a given Location
109   \param loc: the Location the entity is in
110   \param plc: a pointer to a buffer where the corresponding Placement should be put
111   into
112   \return: true if track changes - false if track stays
113   
114   There are no limitations to how you transform a Location into a Placement, but for
115   the sake of placement compatibility between track parts you should make sure that
116   the resulting Placement at dist == 0 is equal to the offset Vector and the Placement
117   at dist == len() is equal to the end Vector. Elseway there will be ugly artifacts
118   when transfering between track parts.
119*/
120bool Track::map_coords (Location* loc, Placement* plc)
121{
122  //Line trace(*offset, *end - *offset);
123  //    float l = trace.len ();
124       
125        /* change to the next track? */
126        //      if( loc->dist > l)
127        //{
128        //      loc->dist -= l;
129        //      loc->part = nextID;
130                //FIXME: loc->track = this;
131                //return true;
132                //}
133       
134        /* this quaternion represents the rotation from start-vector (0,0,1) to the direction of
135         * the track */
136        Quaternion dir(curve.calcDir(t), Vector(0,0,1)); 
137
138        plc->pos = curve.calcPos(t) + (curve.calcDir(t) * ((loc->dist) / t)) + /*dir.apply*/(loc->pos);
139        plc->rot = dir * loc->rot;
140       
141        return false;
142}
143
144/**
145        \brief this is called when a WorldEntity enters 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*/
151void Track::post_enter (WorldEntity* entity)
152{
153}
154
155/**
156        \brief this is called when a WorldEntity leaves a Track part
157        \param entity: pointer to the WorldEntity in question
158       
159        You can do stuff like add or remove effects, do some coordinate finetuning
160        or whatever in here.
161*/
162void Track::post_leave (WorldEntity* entity)
163{
164}
165
166/**
167        \brief this is called every frame
168        \param deltaT: amount of time passed since the last frame in seconds
169       
170        Do time based or polling scripts here.
171*/
172void Track::tick (float deltaT)
173{
174}
175
176
177
178
179
Note: See TracBrowser for help on using the repository browser.