Added KRCollider class
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40182
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
104A335E1672D31C001C8BA6 /* KRCollider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 104A335C1672D31B001C8BA6 /* KRCollider.cpp */; };
|
||||
104A335F1672D31C001C8BA6 /* KRCollider.h in Headers */ = {isa = PBXBuildFile; fileRef = 104A335D1672D31C001C8BA6 /* KRCollider.h */; };
|
||||
E4030E4C160A3CF000592648 /* KRStockGeometry.h in Headers */ = {isa = PBXBuildFile; fileRef = E4030E4B160A3CF000592648 /* KRStockGeometry.h */; };
|
||||
E4030E4D160A3CF000592648 /* KRStockGeometry.h in Headers */ = {isa = PBXBuildFile; fileRef = E4030E4B160A3CF000592648 /* KRStockGeometry.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
E40BA45415EFF79500D7C3DD /* KRAABB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E40BA45215EFF79500D7C3DD /* KRAABB.cpp */; };
|
||||
@@ -233,6 +235,8 @@
|
||||
/* End PBXBuildRule section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
104A335C1672D31B001C8BA6 /* KRCollider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRCollider.cpp; path = Classes/KRCollider.cpp; sourceTree = "<group>"; };
|
||||
104A335D1672D31C001C8BA6 /* KRCollider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRCollider.h; path = Classes/KRCollider.h; sourceTree = "<group>"; };
|
||||
E4030E4B160A3CF000592648 /* KRStockGeometry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRStockGeometry.h; path = Classes/KRStockGeometry.h; sourceTree = "<group>"; };
|
||||
E40BA45215EFF79500D7C3DD /* KRAABB.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRAABB.cpp; path = Classes/KRAABB.cpp; sourceTree = "<group>"; };
|
||||
E40BA45315EFF79500D7C3DD /* KRAABB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRAABB.h; path = Classes/KRAABB.h; sourceTree = "<group>"; };
|
||||
@@ -646,6 +650,8 @@
|
||||
E4324BA916444DCB0043185B /* Particle Systems */,
|
||||
E414BAE11435557300A668C4 /* KRInstance.h */,
|
||||
E414BAE41435558800A668C4 /* KRInstance.cpp */,
|
||||
104A335D1672D31C001C8BA6 /* KRCollider.h */,
|
||||
104A335C1672D31B001C8BA6 /* KRCollider.cpp */,
|
||||
E461A171152E599E00F2044A /* Lights */,
|
||||
E4F975311536220900FD60B2 /* KRNode.h */,
|
||||
E4F975351536221C00FD60B2 /* KRNode.cpp */,
|
||||
@@ -841,6 +847,7 @@
|
||||
E428C3161669A24B00A16EDF /* KRAnimationAttribute.h in Headers */,
|
||||
E416AA9916713749000F6786 /* KRAnimationCurveManager.h in Headers */,
|
||||
E480BE681671C641004EC8AD /* KRBone.h in Headers */,
|
||||
104A335F1672D31C001C8BA6 /* KRCollider.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -1035,6 +1042,7 @@
|
||||
E428C3191669A25D00A16EDF /* KRAnimationAttribute.cpp in Sources */,
|
||||
E416AA9C1671375C000F6786 /* KRAnimationCurveManager.cpp in Sources */,
|
||||
E480BE6C1671C653004EC8AD /* KRBone.cpp in Sources */,
|
||||
104A335E1672D31C001C8BA6 /* KRCollider.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
75
KREngine/KREngine/Classes/KRCollider.cpp
Normal file
75
KREngine/KREngine/Classes/KRCollider.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// KRCollider.cpp
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "KRCollider.h"
|
||||
#import "KRContext.h"
|
||||
#import "KRModel.h"
|
||||
#import "KRQuaternion.h"
|
||||
#include <assert.h>
|
||||
|
||||
KRCollider::KRCollider(KRScene &scene, std::string collider_name, std::string model_name) : KRNode(scene, collider_name) {
|
||||
m_model_name = model_name;
|
||||
}
|
||||
|
||||
KRCollider::~KRCollider() {
|
||||
|
||||
}
|
||||
|
||||
std::string KRCollider::getElementName() {
|
||||
return "collider";
|
||||
}
|
||||
|
||||
tinyxml2::XMLElement *KRCollider::saveXML( tinyxml2::XMLNode *parent)
|
||||
{
|
||||
tinyxml2::XMLElement *e = KRNode::saveXML(parent);
|
||||
e->SetAttribute("collider_name", m_model_name.c_str());
|
||||
return e;
|
||||
}
|
||||
|
||||
void KRCollider::loadModel() {
|
||||
if(m_models.size() == 0) {
|
||||
m_models = m_pContext->getModelManager()->getModel(m_model_name.c_str()); // The model manager returns the LOD levels in sorted order, with the highest detail first
|
||||
if(m_models.size() > 0) {
|
||||
getScene().notify_sceneGraphModify(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KRAABB KRCollider::getBounds() {
|
||||
loadModel();
|
||||
if(m_models.size() > 0) {
|
||||
return KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
|
||||
} else {
|
||||
return KRAABB::Infinite();
|
||||
}
|
||||
}
|
||||
|
||||
65
KREngine/KREngine/Classes/KRCollider.h
Normal file
65
KREngine/KREngine/Classes/KRCollider.h
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// KRCollider.h
|
||||
// KREngine
|
||||
//
|
||||
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The views and conclusions contained in the software and documentation are those of the
|
||||
// authors and should not be interpreted as representing official policies, either expressed
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#import "KREngine-common.h"
|
||||
|
||||
#ifndef __KREngine__KRCollider__
|
||||
#define __KREngine__KRCollider__
|
||||
|
||||
#import "KRModel.h"
|
||||
#import "KRMat4.h"
|
||||
#import "KRVector3.h"
|
||||
#import "KRInstance.h"
|
||||
#import "KRCamera.h"
|
||||
#import "KRModelManager.h"
|
||||
#import "KRNode.h"
|
||||
#import "KRContext.h"
|
||||
#import "KRModel.h"
|
||||
#import "KRTexture.h"
|
||||
|
||||
class KRCollider : public KRNode {
|
||||
|
||||
public:
|
||||
KRCollider(KRScene &scene, std::string collider_name, std::string model_name);
|
||||
virtual ~KRCollider();
|
||||
|
||||
virtual std::string getElementName();
|
||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||
virtual KRAABB getBounds();
|
||||
|
||||
private:
|
||||
std::vector<KRModel *> m_models;
|
||||
std::string m_model_name;
|
||||
|
||||
void loadModel();
|
||||
};
|
||||
|
||||
#endif /* defined(__KREngine__KRCollider__) */
|
||||
@@ -15,6 +15,7 @@
|
||||
#import "KRSpotLight.h"
|
||||
#import "KRDirectionalLight.h"
|
||||
#import "KRInstance.h"
|
||||
#import "KRCollider.h"
|
||||
#import "KRParticleSystem.h"
|
||||
#import "KRParticleSystemNewtonian.h"
|
||||
#import "KRAABB.h"
|
||||
@@ -172,6 +173,8 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) {
|
||||
faces_camera = false;
|
||||
}
|
||||
new_node = new KRInstance(scene, szName, e->Attribute("mesh_name"), e->Attribute("light_map"), lod_min_coverage, receives_shadow, faces_camera);
|
||||
} else if(strcmp(szElementName, "collider") == 0) {
|
||||
new_node = new KRCollider(scene, szName, e->Attribute("collider_name"));
|
||||
} else if(strcmp(szElementName, "bone") == 0) {
|
||||
new_node = new KRBone(scene, szName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user