2 CDTestFramework http://codercorner.com
3 Copyright (c) 2007-2008 Pierre Terdiman, pierre@codercorner.com
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
18 #include "IceHelpers.h"
19 #include "RenderingHelpers.h"
21 #include "CapsuleMeshQuery.h"
23 #include "GLFontRenderer.h"
25 CapsuleMeshQuery::CapsuleMeshQuery() :
32 CapsuleMeshQuery::~CapsuleMeshQuery()
36 void CapsuleMeshQuery::Init()
38 mP0 = Point(0.0f, -4.0f, 0.0f);
39 mP1 = Point(0.0f, 4.0f, 0.0f);
46 mWorld.SetTrans(0.0f, 4.0f, 0.0f);
49 void CapsuleMeshQuery::Release()
53 void CapsuleMeshQuery::PerformTest()
57 mCapsule.mP0 = mP0 * mWorld;
58 mCapsule.mP1 = mP1 * mWorld;
59 mCapsule.mRadius = 1.0f;
60 DrawCapsule(mWorld, mP0, mP1, 1.0f);
62 const Model* TM = GetTerrainModel();
68 bool Status = Collider.Collide(mCache, mCapsule, *TM, null, null);
74 if(Collider.GetContactStatus())
76 udword NbTris = Collider.GetNbTouchedPrimitives();
77 const udword* Indices = Collider.GetTouchedPrimitives();
79 RenderTerrainTriangles(NbTris, Indices);
87 Point wp = mLocalHit + (Point)mWorld.GetTrans();
88 DrawLine(wp, wp + Point(1.0f, 0.0f, 0.0f), Point(1,0,0), 1.0f);
89 DrawLine(wp, wp + Point(0.0f, 1.0f, 0.0f), Point(0,1,0), 1.0f);
90 DrawLine(wp, wp + Point(0.0f, 0.0f, 1.0f), Point(0,0,1), 1.0f);
94 sprintf(Buffer, "Capsule-mesh query = %5.1f us (%d cycles)\n", mProfiler.mMsTime, mProfiler.mCycles);
95 GLFontRenderer::print(10.0f, 10.0f, 0.02f, Buffer);
98 void CapsuleMeshQuery::KeyboardCallback(unsigned char key, int x, int y)
102 void CapsuleMeshQuery::MouseCallback(int button, int state, int x, int y)
105 if(!button && !state)
107 Point Dir = ComputeWorldRay(x, y);
110 if(RayCapsuleOverlap(GetCameraPos(), Dir, mCapsule, s))
114 Point hit = GetCameraPos() + Dir * mDist;
115 mLocalHit = hit - (Point)mWorld.GetTrans();
120 void CapsuleMeshQuery::MotionCallback(int x, int y)
124 Point Dir = ComputeWorldRay(x, y);
125 mWorld.SetTrans(GetCameraPos() + Dir*mDist - mLocalHit);