Initialize libbullet git in 2.0_beta.
[platform/upstream/libbullet.git] / Extras / PhysicsEffects / src / base_level / collision / pfx_intersect_ray_box.cpp
1 /*\r
2 Physics Effects Copyright(C) 2010 Sony Computer Entertainment Inc.\r
3 All rights reserved.\r
4 \r
5 Physics Effects is open software; you can redistribute it and/or\r
6 modify it under the terms of the BSD License.\r
7 \r
8 Physics Effects is distributed in the hope that it will be useful,\r
9 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
11 See the BSD License for more details.\r
12 \r
13 A copy of the BSD License is distributed with\r
14 Physics Effects under the filename: physics_effects_license.txt\r
15 */\r
16 \r
17 #include "pfx_intersect_common.h"\r
18 #include "pfx_intersect_ray_box.h"\r
19 \r
20 namespace sce {\r
21 namespace PhysicsEffects {\r
22 \r
23 PfxBool pfxIntersectRayBox(const PfxRayInput &ray,PfxRayOutput &out,const PfxBox &box,const PfxTransform3 &transform)\r
24 {\r
25         // レイをBoxのローカル座標へ変換\r
26         PfxTransform3 transformBox = orthoInverse(transform);\r
27         PfxVector3 rayStartPosition = transformBox.getUpper3x3() * ray.m_startPosition + transformBox.getTranslation();\r
28         PfxVector3 rayDirection = transformBox.getUpper3x3() * ray.m_direction;\r
29         \r
30         // 交差判定\r
31         PfxFloat tmpVariable=0.0f;\r
32         PfxVector3 tmpNormal(0.0f);\r
33         if(pfxIntersectRayAABB(rayStartPosition,rayDirection,PfxVector3(0.0f),box.m_half,tmpVariable,tmpNormal)) {\r
34                 if(tmpVariable > 0.0f && tmpVariable < out.m_variable) {\r
35                         out.m_contactFlag = true;\r
36                         out.m_variable = tmpVariable;\r
37                         out.m_contactPoint = ray.m_startPosition + tmpVariable * ray.m_direction;\r
38                         out.m_contactNormal = transform.getUpper3x3() * tmpNormal;\r
39                         out.m_subData.m_type = PfxSubData::NONE;\r
40                         return true;\r
41                 }\r
42         }\r
43         \r
44         return false;\r
45 }\r
46 } //namespace PhysicsEffects\r
47 } //namespace sce\r