[Super-tux-commit] supertux/lib/math physic.cpp,1.4,1.5 physic.h,1.5,1.6 vector.cpp,1.3,1.4 vector.h
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-11-20 22:15:15
|
Update of /cvsroot/super-tux/supertux/lib/math In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5941/lib/math Modified Files: physic.cpp physic.h vector.cpp vector.h Log Message: The BIG COMMIT(tm) This is it, expect a broken supertux I only fixed the most annoying issues so far, lots more are still waiting in the TODO list, but I had to bring this stuff to cvs sometime. Changes: - Completely new collision detection scheme, which collides all objects with each other once per frame, instead of single objects manually testing for collisions - New collision detection routines which support slopes and provide additional info on collisions: penetration depth, hit normal vector - Lots of general cleanup/refactoring - Splitted the monolithic badguy class and reimplemented most of them as single classes with a badguy base class. - Splitted the monolithic Special class into several classes - Rewrote the timer and all timing related stuff to work on float and seconds (not like the mixup before where you had frame_ratio, msecs and secs in different parts of the app) - Support for unisolid tiles - Created a flying platform prototype (doesn't work completely yet) - rename InteractiveObjects to triggers and implemented a new sequence trigger, (only supported sequence is endsequence at the moment) - transformed the bonusblocks and bricks into objects Index: vector.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/math/vector.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- vector.cpp 22 Jul 2004 19:07:50 -0000 1.3 +++ vector.cpp 20 Nov 2004 22:14:35 -0000 1.4 @@ -17,6 +17,8 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include <config.h> + #include <cmath> #include "../math/vector.h" Index: vector.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/math/vector.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- vector.h 6 Oct 2004 21:36:51 -0000 1.6 +++ vector.h 20 Nov 2004 22:14:35 -0000 1.7 @@ -1,7 +1,7 @@ // $Id$ // // SuperTux - A Jump'n Run -// Copyright (C) 2004 Matthias Braun <ma...@br... +// Copyright (C) 2004 Matthias Braun <ma...@br...> // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -20,8 +20,6 @@ #ifndef SUPERTUX_VECTOR_H #define SUPERTUX_VECTOR_H -#include "../special/base.h" - namespace SuperTux { @@ -36,9 +34,6 @@ Vector(const Vector& other) : x(other.x), y(other.y) { } - Vector(const base_type& base) - : x(base.x), y(base.y) - { } Vector() : x(0), y(0) { } @@ -92,6 +87,20 @@ return *this; } + const Vector& operator *=(float val) + { + x *= val; + y *= val; + return *this; + } + + const Vector& operator /=(float val) + { + x /= val; + y /= val; + return *this; + } + /// Scalar product of 2 vectors float operator*(const Vector& other) const { Index: physic.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/math/physic.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- physic.cpp 22 Jul 2004 19:07:50 -0000 1.4 +++ physic.cpp 20 Nov 2004 22:14:35 -0000 1.5 @@ -18,6 +18,8 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. +#include <config.h> + #include <cstdio> #include "../math/physic.h" @@ -119,24 +121,18 @@ gravity_enabled = enable_gravity; } -void -Physic::apply(float elapsed_time, float &x, float &y, float gravity) +Vector +Physic::get_movement(float elapsed_time) { - float grav; - if(gravity_enabled) - grav = gravity / 100.0; - else - grav = 0; - - x += vx * elapsed_time + ax * elapsed_time * elapsed_time; - y += vy * elapsed_time + (ay + grav) * elapsed_time * elapsed_time; + float grav = gravity_enabled ? 1000 : 0; + + Vector result( + vx * elapsed_time + ax * elapsed_time * elapsed_time, + vy * elapsed_time + (ay + grav) * elapsed_time * elapsed_time + ); vx += ax * elapsed_time; - vy += (ay + grav) * elapsed_time; -} + vy += (ay + grav) * elapsed_time; -void -Physic::apply(Vector& vector, float elapsed_time, float gravity) -{ - apply(elapsed_time, vector.x, vector.y, gravity); + return result; } Index: physic.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/math/physic.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- physic.h 22 Jul 2004 19:07:50 -0000 1.5 +++ physic.h 20 Nov 2004 22:14:35 -0000 1.6 @@ -21,7 +21,7 @@ #ifndef SUPERTUX_PHYSIC_H #define SUPERTUX_PHYSIC_H -#include "../math/vector.h" +#include "math/vector.h" namespace SuperTux { @@ -67,11 +67,7 @@ /// Enables or disables handling of gravity. void enable_gravity(bool gravity_enabled); - /// Applies the physical simulation to given x and y coordinates. - void apply(float frame_ratio, float &x, float &y, float gravity = 10.0f); - - /// applies the physical simulation to given x and y coordinates. - void apply(Vector& vector, float frame_ratio, float gravity = 10.0f); + Vector get_movement(float elapsed_time); private: /// horizontal and vertical acceleration |