Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/bezierTrack: Location→r ,→w to →pos →dir. (otherwise noone gets the sense of them again.)

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