Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

StaticSphereCollision.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * 静的球コリジョン実装
00022  * @author Junpee
00023  */
00024 
00025 #include "LampBasic.h"
00026 #include "Collision/Leaf/StaticSphereCollision.h"
00027 #include "Collision/System/CollisionScene.h"
00028 #include "Geometry/System/IntersectionResult.h"
00029 
00030 namespace Lamp{
00031 
00032 //------------------------------------------------------------------------------
00033 // 生成、破棄
00034 //------------------------------------------------------------------------------
00035 // コンストラクタ
00036 StaticSphereCollision::StaticSphereCollision(
00037     const String& name, CollisionScene* scene) :
00038     StaticCollisionLeaf(name, scene),
00039     sphere_(Sphere::zero), worldSphere_(Sphere::zero){
00040 }
00041 //------------------------------------------------------------------------------
00042 // デストラクタ
00043 StaticSphereCollision::~StaticSphereCollision(){
00044 }
00045 //------------------------------------------------------------------------------
00046 // コピー
00047 //------------------------------------------------------------------------------
00048 // 静的球コリジョンのコピー
00049 StaticSphereCollision*
00050     StaticSphereCollision::copyStaticSphereCollision() const{
00051     StaticSphereCollision* destination =
00052         getScene()->createStaticSphereCollision(
00053         getScene()->renameLeaf(getName()));
00054     // 静的コリジョンリーフの値をコピー
00055     copyStaticCollisionLeafValue(destination);
00056     // メンバのコピー
00057     destination->sphere_ = sphere_;
00058     destination->worldSphere_ = worldSphere_;
00059     return destination;
00060 }
00061 //------------------------------------------------------------------------------
00062 // 交差
00063 //------------------------------------------------------------------------------
00064 // 球交差
00065 void StaticSphereCollision::intersection(
00066     IntersectionResult* result, const Sphere& sphere, u_int collisionMask){
00067     // グローバルでの有効、無効判定
00068     if(!isGlobalEnabled()){ return; }
00069     // コリジョンマスク判定
00070     if((getCollisionMask() & collisionMask) == 0){ return; }
00071     // 球判定
00072     Intersection intersection;
00073     if(worldSphere_.intersect(&intersection, sphere)){
00074         result->add(intersection);
00075     }
00076 }
00077 //------------------------------------------------------------------------------
00078 // 球コリジョン交差
00079 void StaticSphereCollision::intersection(IntersectionResult* result,
00080     StaticSphereCollision* sphere, u_int collisionMask){
00081     // 自分自身なら交差しない
00082     if(sphere == this){ return; }
00083     // グローバルでの有効、無効判定
00084     if(!isGlobalEnabled()){ return; }
00085     // コリジョンマスク判定
00086     if((getCollisionMask() & collisionMask) == 0){ return; }
00087     // 球判定
00088     Intersection intersection;
00089     if(worldSphere_.intersect(&intersection, sphere->getWorldSphere())){
00090         result->add(intersection);
00091     }
00092 }
00093 //------------------------------------------------------------------------------
00094 // 走査
00095 //------------------------------------------------------------------------------
00096 // 走査
00097 void StaticSphereCollision::traverseImplement(
00098     const Matrix34& parentMatrix, bool parentEnabled, bool parentScaled,
00099     bool parentChanged){
00100     // 走査のセットアップ
00101     if(!traverseSetup(parentEnabled, parentChanged)){ return; }
00102 
00103     // 球の変換
00104     if(parentScaled){
00105         // スケール入り
00106         worldSphere_ = sphere_.scaledTransform(parentMatrix);
00107     }else{
00108         // スケール無し
00109         worldSphere_ = sphere_.transform(parentMatrix);
00110     }
00111 
00112     // ツリーへの挿入、またはツリー内の移動
00113 }
00114 //------------------------------------------------------------------------------
00115 } // End of namespace Lamp
00116 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:36 2005 for Lamp by doxygen 1.3.2