Back to index

supertuxkart  0.5+dfsg1
terrain_info.cpp
Go to the documentation of this file.
00001 //  $Id: terrain_info.cpp 1284 2007-11-08 12:31:54Z hikerstk $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2007 Joerg Henrichs
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #include <math.h>
00021 
00022 #include "terrain_info.hpp"
00023 #include "world.hpp"
00024 #include "constants.hpp"
00025 
00026 TerrainInfo::TerrainInfo(const btVector3 &pos, int frequency)
00027 {
00028     m_HoT_frequency = frequency;
00029     m_HoT_counter   = frequency;
00030     // initialise HoT
00031     update(pos);
00032 }
00033 //-----------------------------------------------------------------------------
00034 void TerrainInfo::update(const btVector3& pos)
00035 {
00036     m_HoT_counter++;
00037     if(m_HoT_counter>=m_HoT_frequency)
00038     {
00039         world->getTrack()->getTerrainInfo(pos, &m_HoT, 
00040                                           &m_normal, &m_material);
00041         m_normal.normalize();
00042         m_HoT_counter = 0;
00043     }
00044 }   // update
00045 
00046 // -----------------------------------------------------------------------------
00049 float TerrainInfo::getTerrainPitch(float heading) const {
00050     if(m_HoT==Track::NOHIT) return 0.0f;
00051 
00052     const float X =-sin(heading);
00053     const float Y = cos(heading);
00054     // Compute the angle between the normal of the plane and the line to
00055     // (x,y,0).  (x,y,0) is normalised, so are the coordinates of the plane,
00056     // simplifying the computation of the scalar product.
00057     float pitch = ( m_normal.getX()*X + m_normal.getY()*Y );  // use ( x,y,0)
00058         
00059     // The actual angle computed above is between the normal and the (x,y,0)
00060     // line, so to compute the actual angles 90 degrees must be subtracted.
00061     pitch = acosf(pitch) - NINETY_DEGREE_RAD;
00062     return pitch;
00063 }   // getTerrainPitch
00064 
00065 // -----------------------------------------------------------------------------
00066 
00067 /* EOF */