Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/ogrebullet/Collisions/OgreBulletCollisionsRay.cpp @ 2274

Last change on this file since 2274 was 2192, checked in by rgrieder, 16 years ago

Reverted all changes of attempt to update physics branch.

  • Property svn:eol-style set to native
File size: 4.2 KB
RevLine 
[1985]1/***************************************************************************
2
3This source file is part of OGREBULLET
4(Object-oriented Graphics Rendering Engine Bullet Wrapper)
5For the latest info, see http://www.ogre3d.org/phpBB2addons/viewforum.php?f=10
6
7Copyright (c) 2007 tuan.kuranes@gmail.com (Use it Freely, even Statically, but have to contribute any changes)
8
9
10
11This program is free software; you can redistribute it and/or modify it under
12the terms of the GPL General Public License with runtime exception as published by the Free Software
13Foundation; either version 2 of the License, or (at your option) any later
14version.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GPL General Public License with runtime exception for more details.
19
20You should have received a copy of the GPL General Public License with runtime exception along with
21this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22Place - Suite 330, Boston, MA 02111-1307, USA, or go to
23http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24-----------------------------------------------------------------------------
25*/
26
27#include "OgreBulletCollisions.h"
28
29#include "OgreBulletCollisionsWorld.h"
30#include "OgreBulletCollisionsRay.h"
31#include "Utils/OgreBulletConverter.h"
32
33#include "OgreBulletCollisionsObject.h"
34#include "Debug/OgreBulletCollisionsDebugShape.h"
35
36using namespace Ogre;
37using namespace OgreBulletCollisions;
38
39namespace OgreBulletCollisions
40{
41    // -------------------------------------------------------------------------
42        CollisionRayResultCallback::CollisionRayResultCallback(const Ogre::Ray &ray, 
43                                                        CollisionsWorld *world, Ogre::Real max_distance,
44                                                        bool init):
45        mRayResultCallback(0),
46        mWorld(world),
47        mRay (ray),
48                mMaxDistance(max_distance)
49    {
50        if (init)
51        {
52            //mRay = new btCollisionWorld::RayResultCallback (
53            //    OgreBtConverter::to(ray.getOrigin ()),
54            //   OgreBtConverter::to(ray.getDirection ()));
55        }
56        }
57    // -------------------------------------------------------------------------
58    CollisionRayResultCallback::~CollisionRayResultCallback()
59    {
60        if (mRayResultCallback)
61        {
62            delete mRayResultCallback;
63            mRayResultCallback = 0;
64        }
65    }
66    Ogre::Vector3 CollisionRayResultCallback::getRayStartPoint() const
67    {
68      return mRay.getOrigin();
69    }
70    // -------------------------------------------------------------------------
71    Ogre::Vector3 CollisionRayResultCallback::getRayEndPoint() const
72    {
73      return mRay.getPoint(mMaxDistance);
74    }
75    // -------------------------------------------------------------------------
76    bool  CollisionRayResultCallback::doesCollide() const
77    {
78        return mRayResultCallback->hasHit();
79    }
80    // -------------------------------------------------------------------------
81    Object  *CollisionClosestRayResultCallback::getCollidedObject () const
82    {       
83        return mWorld->findObject(static_cast<btCollisionWorld::ClosestRayResultCallback *> (mRayResultCallback)->m_collisionObject);
84        }
85    // -------------------------------------------------------------------------
86        CollisionClosestRayResultCallback::CollisionClosestRayResultCallback(const Ogre::Ray &ray, CollisionsWorld *world, Ogre::Real max_distance) :
87        CollisionRayResultCallback(ray, world, max_distance, false)
88    {
89        mRayResultCallback = new btCollisionWorld::ClosestRayResultCallback (
90            OgreBtConverter::to(getRayStartPoint ()), 
91            OgreBtConverter::to(getRayEndPoint ()));
92    } 
93    // -------------------------------------------------------------------------
94    Vector3 CollisionClosestRayResultCallback::getCollisionPoint() const
95    {
96        return BtOgreConverter::to(getBulletClosestRayResultCallback()->m_hitPointWorld);
97        }
98        // -------------------------------------------------------------------------
99        Vector3 CollisionClosestRayResultCallback::getCollisionNormal() const
100        {
101                return BtOgreConverter::to(getBulletClosestRayResultCallback()->m_hitNormalWorld);
102        }
103}
104
Note: See TracBrowser for help on using the repository browser.