/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Christian Meyer co-programmer: ... */ #include "track.h" using namespace std; /** \brief creates a null Track part */ Track::Track () { this->ID = 0; this->offset = NULL; this->end = NULL; this->nextID = 0; } /** \brief creates a functional base Track part \param number: the ID if this Track part \param next: the ID of the next Track part \param start: pointer to an anchor point (Vector) representing the offset of this part \param finish: pointer to an anchor point (Vector) representing the end of this part */ Track::Track (Uint32 number, Uint32 next, Vector* start, Vector* finish) { this->ID = number; this->offset = start; this->end = finish; this->nextID = next; } /** \brief removes the Track part from memory */ Track::~Track () { } void Track::init() { } /** \brief calculate a camera Placement from a "look at"-Location \param lookat: the Location the camera should be centered on \param camplc: pointer to a buffer where the new camera Placement should be put into Theoretically you can place the camera wherever you want, but for the sake of common sense I suggest that you at least try to keep the thing that should be looked at inside camera boundaries. */ void Track::mapCamera (Location* lookat, Placement* camplc) { Line trace(*offset, *end - *offset); float l = trace.len (); // camplc->r = *offset + Vector(0,0,0.5); // camplc->w = Quaternion (trace.a, Vector(0,0,1)); float r = (lookat->dist)*PI / l; camplc->r = trace.r + (trace.a * ((lookat->dist-10.0) / l)) + Vector(0,0,5.0); Vector w(0.0,0.0,0.0); w=Vector(0,0,0) - ((trace.r + (trace.a * ((lookat->dist) / l)) - camplc->r)); //Vector up(0.0,sin(r),cos(r)); // corrupt... Vector up(0.0, 0.0, 1.0); camplc->w = Quaternion(w, up); //printf("\n------\nup vector: [%f, %f, %f]\n", up.x, up.y, up.z); //printf("direction: [%f, %f, %f]\n", w.x, w.y, w.z); //printf("quaternion: w[ %f ], v[ %f, %f, %f ]\n", camplc->w.w, camplc->w.v.x, camplc->w.v.y, camplc->w.v.z); } /** \brief calculate a Placement from a given Location \param loc: the Location the entity is in \param plc: a pointer to a buffer where the corresponding Placement should be put into \return: true if track changes - false if track stays There are no limitations to how you transform a Location into a Placement, but for the sake of placement compatibility between track parts you should make sure that the resulting Placement at dist == 0 is equal to the offset Vector and the Placement at dist == len() is equal to the end Vector. Elseway there will be ugly artifacts when transfering between track parts. */ bool Track::mapCoords (Location* loc, Placement* plc) { Line trace(*offset, *end - *offset); float l = trace.len (); /* change to the next track? */ if( loc->dist > l) { loc->dist -= l; loc->part = nextID; //FIXME: loc->track = this; return true; } /* this quaternion represents the rotation from start-vector (0,0,1) to the direction of * the track */ Quaternion dir(trace.a, Vector(0,0,1)); plc->r = trace.r + (trace.a * ((loc->dist) / l)) + /*dir.apply*/(loc->pos); plc->w = dir * loc->rot; return false; } /** \brief this is called when a WorldEntity enters a Track part \param entity: pointer to the WorldEntity in question You can do stuff like add or remove effects, do some coordinate finetuning or whatever in here. */ void Track::postEnter (WorldEntity* entity) { } /** \brief this is called when a WorldEntity leaves a Track part \param entity: pointer to the WorldEntity in question You can do stuff like add or remove effects, do some coordinate finetuning or whatever in here. */ void Track::postLeave (WorldEntity* entity) { } /** \brief this is called every frame \param deltaT: amount of time passed since the last frame in seconds Do time based or polling scripts here. */ void Track::tick (float deltaT) { }