/s/KRAABB/AABB/g
Cleanup, new hash<> functions
This commit is contained in:
@@ -137,14 +137,14 @@ void KRAmbientZone::setGradientDistance(float gradient_distance)
|
||||
m_gradient_distance = gradient_distance;
|
||||
}
|
||||
|
||||
KRAABB KRAmbientZone::getBounds() {
|
||||
AABB KRAmbientZone::getBounds() {
|
||||
// Ambient zones always have a -1, -1, -1 to 1, 1, 1 bounding box
|
||||
return KRAABB(-Vector3::One(), Vector3::One(), getModelMatrix());
|
||||
return AABB(-Vector3::One(), Vector3::One(), getModelMatrix());
|
||||
}
|
||||
|
||||
float KRAmbientZone::getContainment(const Vector3 &pos)
|
||||
{
|
||||
KRAABB bounds = getBounds();
|
||||
AABB bounds = getBounds();
|
||||
if(bounds.contains(pos)) {
|
||||
Vector3 size = bounds.size();
|
||||
Vector3 diff = pos - bounds.center();
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
float getAmbientGain();
|
||||
void setAmbientGain(float ambient_gain);
|
||||
|
||||
virtual KRAABB getBounds();
|
||||
virtual AABB getBounds();
|
||||
|
||||
float getContainment(const Vector3 &pos);
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ void KRBone::loadXML(tinyxml2::XMLElement *e)
|
||||
setScaleCompensation(true);
|
||||
}
|
||||
|
||||
KRAABB KRBone::getBounds() {
|
||||
return KRAABB(-Vector3::One(), Vector3::One(), getModelMatrix()); // Only required for bone debug visualization
|
||||
AABB KRBone::getBounds() {
|
||||
return AABB(-Vector3::One(), Vector3::One(), getModelMatrix()); // Only required for bone debug visualization
|
||||
}
|
||||
|
||||
void KRBone::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass)
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
virtual std::string getElementName();
|
||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||
virtual KRAABB getBounds();
|
||||
virtual AABB getBounds();
|
||||
|
||||
void render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
|
||||
|
||||
@@ -476,7 +476,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend
|
||||
KRShader *pVisShader = getContext().getShaderManager()->getShader("visualize_overlay", this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
|
||||
m_pContext->getMeshManager()->bindVBO(&getContext().getMeshManager()->KRENGINE_VBO_DATA_3D_CUBE_VERTICES, 1.0f);
|
||||
for(unordered_map<KRAABB, int>::iterator itr=m_viewport.getVisibleBounds().begin(); itr != m_viewport.getVisibleBounds().end(); itr++) {
|
||||
for(unordered_map<AABB, int>::iterator itr=m_viewport.getVisibleBounds().begin(); itr != m_viewport.getVisibleBounds().end(); itr++) {
|
||||
Matrix4 matModel = Matrix4();
|
||||
matModel.scale((*itr).first.size() * 0.5f);
|
||||
matModel.translate((*itr).first.center());
|
||||
|
||||
@@ -83,12 +83,12 @@ void KRCollider::loadModel() {
|
||||
}
|
||||
}
|
||||
|
||||
KRAABB KRCollider::getBounds() {
|
||||
AABB KRCollider::getBounds() {
|
||||
loadModel();
|
||||
if(m_models.size() > 0) {
|
||||
return KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
|
||||
return AABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
|
||||
} else {
|
||||
return KRAABB::Infinite();
|
||||
return AABB::Infinite();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ bool KRCollider::sphereCast(const Vector3 &v0, const Vector3 &v1, float radius,
|
||||
if(layer_mask & m_layer_mask) { // Only test if layer masks have a common bit set
|
||||
loadModel();
|
||||
if(m_models.size()) {
|
||||
KRAABB sphereCastBounds = KRAABB( // TODO - Need to cache this; perhaps encasulate within a "spherecast" class to be passed through these functions
|
||||
AABB sphereCastBounds = AABB( // TODO - Need to cache this; perhaps encasulate within a "spherecast" class to be passed through these functions
|
||||
Vector3(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius),
|
||||
Vector3(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius)
|
||||
);
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
virtual std::string getElementName();
|
||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||
virtual KRAABB getBounds();
|
||||
virtual AABB getBounds();
|
||||
|
||||
bool lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask);
|
||||
bool rayCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask);
|
||||
|
||||
@@ -52,7 +52,7 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
|
||||
float max_depth = 1.0f;
|
||||
*/
|
||||
|
||||
KRAABB worldSpacefrustrumSliceBounds = KRAABB(Vector3(-1.0f, -1.0f, -1.0f), Vector3(1.0f, 1.0f, 1.0f), Matrix4::Invert(viewport.getViewProjectionMatrix()));
|
||||
AABB worldSpacefrustrumSliceBounds = AABB(Vector3(-1.0f, -1.0f, -1.0f), Vector3(1.0f, 1.0f, 1.0f), Matrix4::Invert(viewport.getViewProjectionMatrix()));
|
||||
worldSpacefrustrumSliceBounds.scale(KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE);
|
||||
|
||||
Vector3 shadowLook = -Vector3::Normalize(getWorldLightDirection());
|
||||
@@ -66,8 +66,8 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
|
||||
|
||||
Matrix4 matShadowView = Matrix4::LookAt(worldSpacefrustrumSliceBounds.center() - shadowLook, worldSpacefrustrumSliceBounds.center(), shadowUp);
|
||||
Matrix4 matShadowProjection = Matrix4();
|
||||
KRAABB shadowSpaceFrustrumSliceBounds = KRAABB(worldSpacefrustrumSliceBounds.min, worldSpacefrustrumSliceBounds.max, Matrix4::Invert(matShadowProjection));
|
||||
KRAABB shadowSpaceSceneBounds = KRAABB(getScene().getRootOctreeBounds().min, getScene().getRootOctreeBounds().max, Matrix4::Invert(matShadowProjection));
|
||||
AABB shadowSpaceFrustrumSliceBounds = AABB(worldSpacefrustrumSliceBounds.min, worldSpacefrustrumSliceBounds.max, Matrix4::Invert(matShadowProjection));
|
||||
AABB shadowSpaceSceneBounds = AABB(getScene().getRootOctreeBounds().min, getScene().getRootOctreeBounds().max, Matrix4::Invert(matShadowProjection));
|
||||
if(shadowSpaceSceneBounds.min.z < shadowSpaceFrustrumSliceBounds.min.z) shadowSpaceFrustrumSliceBounds.min.z = shadowSpaceSceneBounds.min.z; // Include any potential shadow casters that are outside the view frustrum
|
||||
matShadowProjection.scale(1.0f / shadowSpaceFrustrumSliceBounds.size().x, 1.0f / shadowSpaceFrustrumSliceBounds.size().y, 1.0f / shadowSpaceFrustrumSliceBounds.size().z);
|
||||
|
||||
@@ -76,8 +76,8 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
|
||||
matShadowProjection *= matBias;
|
||||
|
||||
KRViewport newShadowViewport = KRViewport(Vector2(KRENGINE_SHADOW_MAP_WIDTH, KRENGINE_SHADOW_MAP_HEIGHT), matShadowView, matShadowProjection);
|
||||
KRAABB prevShadowBounds = KRAABB(-Vector3::One(), Vector3::One(), Matrix4::Invert(m_shadowViewports[iShadow].getViewProjectionMatrix()));
|
||||
KRAABB minimumShadowBounds = KRAABB(-Vector3::One(), Vector3::One(), Matrix4::Invert(newShadowViewport.getViewProjectionMatrix()));
|
||||
AABB prevShadowBounds = AABB(-Vector3::One(), Vector3::One(), Matrix4::Invert(m_shadowViewports[iShadow].getViewProjectionMatrix()));
|
||||
AABB minimumShadowBounds = AABB(-Vector3::One(), Vector3::One(), Matrix4::Invert(newShadowViewport.getViewProjectionMatrix()));
|
||||
minimumShadowBounds.scale(1.0f / KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE);
|
||||
if(!prevShadowBounds.contains(minimumShadowBounds) || !shadowValid[iShadow] || true) { // FINDME, HACK - Re-generating the shadow map every frame. This should only be needed if the shadow contains non-static geometry
|
||||
m_shadowViewports[iShadow] = newShadowViewport;
|
||||
@@ -129,7 +129,7 @@ void KRDirectionalLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &
|
||||
}
|
||||
}
|
||||
|
||||
KRAABB KRDirectionalLight::getBounds()
|
||||
AABB KRDirectionalLight::getBounds()
|
||||
{
|
||||
return KRAABB::Infinite();
|
||||
return AABB::Infinite();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
Vector3 getWorldLightDirection();
|
||||
|
||||
virtual void render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
virtual KRAABB getBounds();
|
||||
virtual AABB getBounds();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ KRLODGroup::KRLODGroup(KRScene &scene, std::string name) : KRNode(scene, name)
|
||||
{
|
||||
m_min_distance = 0.0f;
|
||||
m_max_distance = 0.0f;
|
||||
m_reference = KRAABB(Vector3::Zero(), Vector3::Zero());
|
||||
m_reference = AABB(Vector3::Zero(), Vector3::Zero());
|
||||
m_use_world_units = true;
|
||||
}
|
||||
|
||||
@@ -92,12 +92,12 @@ void KRLODGroup::loadXML(tinyxml2::XMLElement *e)
|
||||
}
|
||||
|
||||
|
||||
const KRAABB &KRLODGroup::getReference() const
|
||||
const AABB &KRLODGroup::getReference() const
|
||||
{
|
||||
return m_reference;
|
||||
}
|
||||
|
||||
void KRLODGroup::setReference(const KRAABB &reference)
|
||||
void KRLODGroup::setReference(const AABB &reference)
|
||||
{
|
||||
m_reference = reference;
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ public:
|
||||
void setMinDistance(float min_distance);
|
||||
void setMaxDistance(float max_distance);
|
||||
|
||||
const KRAABB &getReference() const;
|
||||
void setReference(const KRAABB &reference);
|
||||
const AABB &getReference() const;
|
||||
void setReference(const AABB &reference);
|
||||
void setUseWorldUnits(bool use_world_units);
|
||||
bool getUseWorldUnits() const;
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
private:
|
||||
float m_min_distance;
|
||||
float m_max_distance;
|
||||
KRAABB m_reference; // Point of reference, used for distance calculation. Usually set to the bounding box center
|
||||
AABB m_reference; // Point of reference, used for distance calculation. Usually set to the bounding box center
|
||||
bool m_use_world_units;
|
||||
};
|
||||
|
||||
|
||||
@@ -241,23 +241,23 @@ kraken_stream_level KRModel::getStreamLevel(const KRViewport &viewport)
|
||||
return stream_level;
|
||||
}
|
||||
|
||||
KRAABB KRModel::getBounds() {
|
||||
AABB KRModel::getBounds() {
|
||||
loadModel();
|
||||
if(m_models.size() > 0) {
|
||||
if(m_faces_camera) {
|
||||
KRAABB normal_bounds = KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
|
||||
AABB normal_bounds = AABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
|
||||
float max_dimension = normal_bounds.longest_radius();
|
||||
return KRAABB(normal_bounds.center()-Vector3(max_dimension), normal_bounds.center() + Vector3(max_dimension));
|
||||
return AABB(normal_bounds.center()-Vector3(max_dimension), normal_bounds.center() + Vector3(max_dimension));
|
||||
} else {
|
||||
|
||||
if(!(m_boundsCachedMat == getModelMatrix())) {
|
||||
m_boundsCachedMat = getModelMatrix();
|
||||
m_boundsCached = KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
|
||||
m_boundsCached = AABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
|
||||
}
|
||||
return m_boundsCached;
|
||||
}
|
||||
} else {
|
||||
return KRAABB::Infinite();
|
||||
return AABB::Infinite();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
|
||||
virtual void render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
|
||||
virtual KRAABB getBounds();
|
||||
virtual AABB getBounds();
|
||||
|
||||
void setRimColor(const Vector3 &rim_color);
|
||||
void setRimPower(float rim_power);
|
||||
@@ -85,7 +85,7 @@ private:
|
||||
|
||||
|
||||
Matrix4 m_boundsCachedMat;
|
||||
KRAABB m_boundsCached;
|
||||
AABB m_boundsCached;
|
||||
|
||||
|
||||
Vector3 m_rim_color;
|
||||
|
||||
@@ -476,14 +476,14 @@ KRScene &KRNode::getScene() {
|
||||
return *m_pScene;
|
||||
}
|
||||
|
||||
KRAABB KRNode::getBounds() {
|
||||
AABB KRNode::getBounds() {
|
||||
if(!m_boundsValid) {
|
||||
KRAABB bounds = KRAABB::Zero();
|
||||
AABB bounds = AABB::Zero();
|
||||
|
||||
bool first_child = true;
|
||||
for(std::set<KRNode *>::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
|
||||
KRNode *child = (*itr);
|
||||
if(child->getBounds() != KRAABB::Zero()) {
|
||||
if(child->getBounds() != AABB::Zero()) {
|
||||
if(first_child) {
|
||||
first_child = false;
|
||||
bounds = child->getBounds();
|
||||
|
||||
@@ -18,7 +18,7 @@ using namespace kraken;
|
||||
|
||||
namespace kraken {
|
||||
class Matrix4;
|
||||
class KRAABB;
|
||||
class AABB;
|
||||
} // namespace kraken
|
||||
class KRCamera;
|
||||
class KRShaderManager;
|
||||
@@ -123,7 +123,7 @@ public:
|
||||
void setWorldScale(const Vector3 &v);
|
||||
void setWorldRotation(const Vector3 &v);
|
||||
|
||||
virtual KRAABB getBounds();
|
||||
virtual AABB getBounds();
|
||||
void invalidateBounds() const;
|
||||
const Matrix4 &getModelMatrix();
|
||||
const Matrix4 &getInverseModelMatrix();
|
||||
@@ -230,7 +230,7 @@ private:
|
||||
bool m_activePoseMatrixValid;
|
||||
bool m_inverseBindPoseMatrixValid;
|
||||
|
||||
mutable KRAABB m_bounds;
|
||||
mutable AABB m_bounds;
|
||||
mutable bool m_boundsValid;
|
||||
|
||||
std::string m_name;
|
||||
|
||||
@@ -25,10 +25,10 @@ KROctree::~KROctree()
|
||||
|
||||
void KROctree::add(KRNode *pNode)
|
||||
{
|
||||
KRAABB nodeBounds = pNode->getBounds();
|
||||
if(nodeBounds == KRAABB::Zero()) {
|
||||
AABB nodeBounds = pNode->getBounds();
|
||||
if(nodeBounds == AABB::Zero()) {
|
||||
// This item is not visible, don't add it to the octree or outer scene nodes
|
||||
} else if(nodeBounds == KRAABB::Infinite()) {
|
||||
} else if(nodeBounds == AABB::Infinite()) {
|
||||
// This item is infinitely large; we track it separately
|
||||
m_outerSceneNodes.insert(pNode);
|
||||
} else {
|
||||
@@ -40,12 +40,12 @@ void KROctree::add(KRNode *pNode)
|
||||
// Keep encapsulating the root node until the new root contains the inserted node
|
||||
bool bInsideRoot = false;
|
||||
while(!bInsideRoot) {
|
||||
KRAABB rootBounds = m_pRootNode->getBounds();
|
||||
AABB rootBounds = m_pRootNode->getBounds();
|
||||
Vector3 rootSize = rootBounds.size();
|
||||
if(nodeBounds.min.x < rootBounds.min.x || nodeBounds.min.y < rootBounds.min.y || nodeBounds.min.z < rootBounds.min.z) {
|
||||
m_pRootNode = new KROctreeNode(NULL, KRAABB(rootBounds.min - rootSize, rootBounds.max), 7, m_pRootNode);
|
||||
m_pRootNode = new KROctreeNode(NULL, AABB(rootBounds.min - rootSize, rootBounds.max), 7, m_pRootNode);
|
||||
} else if(nodeBounds.max.x > rootBounds.max.x || nodeBounds.max.y > rootBounds.max.y || nodeBounds.max.z > rootBounds.max.z) {
|
||||
m_pRootNode = new KROctreeNode(NULL, KRAABB(rootBounds.min, rootBounds.max + rootSize), 0, m_pRootNode);
|
||||
m_pRootNode = new KROctreeNode(NULL, AABB(rootBounds.min, rootBounds.max + rootSize), 0, m_pRootNode);
|
||||
} else {
|
||||
bInsideRoot = true;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "KRNode.h"
|
||||
#include "KRCollider.h"
|
||||
|
||||
KROctreeNode::KROctreeNode(KROctreeNode *parent, const KRAABB &bounds) : m_bounds(bounds)
|
||||
KROctreeNode::KROctreeNode(KROctreeNode *parent, const AABB &bounds) : m_bounds(bounds)
|
||||
{
|
||||
m_parent = parent;
|
||||
|
||||
@@ -21,7 +21,7 @@ KROctreeNode::KROctreeNode(KROctreeNode *parent, const KRAABB &bounds) : m_bound
|
||||
m_activeQuery = false;
|
||||
}
|
||||
|
||||
KROctreeNode::KROctreeNode(KROctreeNode *parent, const KRAABB &bounds, int iChild, KROctreeNode *pChild) : m_bounds(bounds)
|
||||
KROctreeNode::KROctreeNode(KROctreeNode *parent, const AABB &bounds, int iChild, KROctreeNode *pChild) : m_bounds(bounds)
|
||||
{
|
||||
// This constructor is used when expanding the octree and replacing the root node with a new root that encapsulates it
|
||||
m_parent = parent;
|
||||
@@ -76,7 +76,7 @@ void KROctreeNode::endOcclusionQuery()
|
||||
}
|
||||
|
||||
|
||||
KRAABB KROctreeNode::getBounds()
|
||||
AABB KROctreeNode::getBounds()
|
||||
{
|
||||
return m_bounds;
|
||||
}
|
||||
@@ -95,11 +95,11 @@ void KROctreeNode::add(KRNode *pNode)
|
||||
}
|
||||
}
|
||||
|
||||
KRAABB KROctreeNode::getChildBounds(int iChild)
|
||||
AABB KROctreeNode::getChildBounds(int iChild)
|
||||
{
|
||||
Vector3 center = m_bounds.center();
|
||||
|
||||
return KRAABB(
|
||||
return AABB(
|
||||
Vector3(
|
||||
(iChild & 1) == 0 ? m_bounds.min.x : center.x,
|
||||
(iChild & 2) == 0 ? m_bounds.min.y : center.y,
|
||||
@@ -264,7 +264,7 @@ bool KROctreeNode::sphereCast(const Vector3 &v0, const Vector3 &v1, float radius
|
||||
} else {
|
||||
*/
|
||||
|
||||
KRAABB swept_bounds = KRAABB(Vector3(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius), Vector3(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius));
|
||||
AABB swept_bounds = AABB(Vector3(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius), Vector3(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius));
|
||||
// FINDME, TODO - Investigate AABB - swept sphere intersections or OBB - AABB intersections: "if(getBounds().intersectsSweptSphere(v0, v1, radius)) {"
|
||||
if(getBounds().intersects(swept_bounds)) {
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ class KRNode;
|
||||
|
||||
class KROctreeNode {
|
||||
public:
|
||||
KROctreeNode(KROctreeNode *parent, const KRAABB &bounds);
|
||||
KROctreeNode(KROctreeNode *parent, const KRAABB &bounds, int iChild, KROctreeNode *pChild);
|
||||
KROctreeNode(KROctreeNode *parent, const AABB &bounds);
|
||||
KROctreeNode(KROctreeNode *parent, const AABB &bounds, int iChild, KROctreeNode *pChild);
|
||||
~KROctreeNode();
|
||||
|
||||
KROctreeNode **getChildren();
|
||||
@@ -27,12 +27,12 @@ public:
|
||||
void remove(KRNode *pNode);
|
||||
void update(KRNode *pNode);
|
||||
|
||||
KRAABB getBounds();
|
||||
AABB getBounds();
|
||||
|
||||
KROctreeNode *getParent();
|
||||
void setChildNode(int iChild, KROctreeNode *pChild);
|
||||
int getChildIndex(KRNode *pNode);
|
||||
KRAABB getChildBounds(int iChild);
|
||||
AABB getChildBounds(int iChild);
|
||||
void trim();
|
||||
bool isEmpty() const;
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
KRAABB m_bounds;
|
||||
AABB m_bounds;
|
||||
|
||||
KROctreeNode *m_parent;
|
||||
KROctreeNode *m_children[8];
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||
|
||||
virtual KRAABB getBounds() = 0;
|
||||
virtual AABB getBounds() = 0;
|
||||
|
||||
virtual void render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass) = 0;
|
||||
|
||||
|
||||
@@ -39,9 +39,9 @@ tinyxml2::XMLElement *KRParticleSystemNewtonian::saveXML( tinyxml2::XMLNode *par
|
||||
}
|
||||
|
||||
|
||||
KRAABB KRParticleSystemNewtonian::getBounds()
|
||||
AABB KRParticleSystemNewtonian::getBounds()
|
||||
{
|
||||
return KRAABB(-Vector3::One(), Vector3::One(), getModelMatrix());
|
||||
return AABB(-Vector3::One(), Vector3::One(), getModelMatrix());
|
||||
}
|
||||
|
||||
void KRParticleSystemNewtonian::physicsUpdate(float deltaTime)
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||
|
||||
|
||||
virtual KRAABB getBounds();
|
||||
virtual AABB getBounds();
|
||||
|
||||
virtual void render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
|
||||
|
||||
@@ -31,12 +31,12 @@ std::string KRPointLight::getElementName() {
|
||||
return "point_light";
|
||||
}
|
||||
|
||||
KRAABB KRPointLight::getBounds() {
|
||||
AABB KRPointLight::getBounds() {
|
||||
float influence_radius = m_decayStart - sqrt(m_intensity * 0.01f) / sqrt(KRLIGHT_MIN_INFLUENCE);
|
||||
if(influence_radius < m_flareOcclusionSize) {
|
||||
influence_radius = m_flareOcclusionSize;
|
||||
}
|
||||
return KRAABB(Vector3(-influence_radius), Vector3(influence_radius), getModelMatrix());
|
||||
return AABB(Vector3(-influence_radius), Vector3(influence_radius), getModelMatrix());
|
||||
}
|
||||
|
||||
void KRPointLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass)
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
virtual ~KRPointLight();
|
||||
|
||||
virtual std::string getElementName();
|
||||
virtual KRAABB getBounds();
|
||||
virtual AABB getBounds();
|
||||
|
||||
virtual void render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
|
||||
|
||||
@@ -954,7 +954,7 @@ void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pG
|
||||
KRLODSet *lod_set = new KRLODSet(parent_node->getScene(), name);
|
||||
parent_node->addChild(lod_set);
|
||||
|
||||
KRAABB reference_bounds;
|
||||
AABB reference_bounds;
|
||||
// Create a lod_group node for each fbx child node
|
||||
int child_count = pNode->GetChildCount();
|
||||
for(int i = 0; i < child_count; i++)
|
||||
@@ -1022,7 +1022,7 @@ void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pG
|
||||
reference_bounds = new_node->getBounds();
|
||||
}
|
||||
|
||||
new_node->setReference(KRAABB(reference_bounds.min, reference_bounds.max, new_node->getInverseModelMatrix()));
|
||||
new_node->setReference(AABB(reference_bounds.min, reference_bounds.max, new_node->getInverseModelMatrix()));
|
||||
}
|
||||
} else {
|
||||
KRNode *new_node = NULL;
|
||||
|
||||
@@ -136,14 +136,14 @@ void KRReverbZone::setGradientDistance(float gradient_distance)
|
||||
m_gradient_distance = gradient_distance;
|
||||
}
|
||||
|
||||
KRAABB KRReverbZone::getBounds() {
|
||||
AABB KRReverbZone::getBounds() {
|
||||
// Reverb zones always have a -1, -1, -1 to 1, 1, 1 bounding box
|
||||
return KRAABB(-Vector3::One(), Vector3::One(), getModelMatrix());
|
||||
return AABB(-Vector3::One(), Vector3::One(), getModelMatrix());
|
||||
}
|
||||
|
||||
float KRReverbZone::getContainment(const Vector3 &pos)
|
||||
{
|
||||
KRAABB bounds = getBounds();
|
||||
AABB bounds = getBounds();
|
||||
if(bounds.contains(pos)) {
|
||||
Vector3 size = bounds.size();
|
||||
Vector3 diff = pos - bounds.center();
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
float getReverbGain();
|
||||
void setReverbGain(float reverb_gain);
|
||||
|
||||
virtual KRAABB getBounds();
|
||||
virtual AABB getBounds();
|
||||
|
||||
float getContainment(const Vector3 &pos);
|
||||
|
||||
|
||||
@@ -97,18 +97,18 @@ std::set<KRLight *> &KRScene::getLights()
|
||||
return m_lights;
|
||||
}
|
||||
|
||||
void KRScene::render(KRCamera *pCamera, unordered_map<KRAABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame) {
|
||||
void KRScene::render(KRCamera *pCamera, unordered_map<AABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame) {
|
||||
if(new_frame) {
|
||||
// Expire cached occlusion test results.
|
||||
// Cached "failed" results are expired on the next frame (marked with .second of -1)
|
||||
// Cached "success" results are expired after KRENGINE_OCCLUSION_TEST_EXPIRY frames (marked with .second of the last frame
|
||||
std::set<KRAABB> expired_visible_bounds;
|
||||
for(unordered_map<KRAABB, int>::iterator visible_bounds_itr = visibleBounds.begin(); visible_bounds_itr != visibleBounds.end(); visible_bounds_itr++) {
|
||||
std::set<AABB> expired_visible_bounds;
|
||||
for(unordered_map<AABB, int>::iterator visible_bounds_itr = visibleBounds.begin(); visible_bounds_itr != visibleBounds.end(); visible_bounds_itr++) {
|
||||
if((*visible_bounds_itr).second == -1 || (*visible_bounds_itr).second + KRENGINE_OCCLUSION_TEST_EXPIRY < getContext().getCurrentFrame()) {
|
||||
expired_visible_bounds.insert((*visible_bounds_itr).first);
|
||||
}
|
||||
}
|
||||
for(std::set<KRAABB>::iterator expired_visible_bounds_itr = expired_visible_bounds.begin(); expired_visible_bounds_itr != expired_visible_bounds.end(); expired_visible_bounds_itr++) {
|
||||
for(std::set<AABB>::iterator expired_visible_bounds_itr = expired_visible_bounds.begin(); expired_visible_bounds_itr != expired_visible_bounds.end(); expired_visible_bounds_itr++) {
|
||||
visibleBounds.erase(*expired_visible_bounds_itr);
|
||||
}
|
||||
}
|
||||
@@ -175,11 +175,11 @@ void KRScene::render(KRCamera *pCamera, unordered_map<KRAABB, int> &visibleBound
|
||||
}
|
||||
}
|
||||
|
||||
void KRScene::render(KROctreeNode *pOctreeNode, unordered_map<KRAABB, int> &visibleBounds, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly)
|
||||
void KRScene::render(KROctreeNode *pOctreeNode, unordered_map<AABB, int> &visibleBounds, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly)
|
||||
{
|
||||
if(pOctreeNode) {
|
||||
|
||||
KRAABB octreeBounds = pOctreeNode->getBounds();
|
||||
AABB octreeBounds = pOctreeNode->getBounds();
|
||||
|
||||
if(bOcclusionResultsPass) {
|
||||
// ----====---- Occlusion results pass ----====----
|
||||
@@ -208,7 +208,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map<KRAABB, int> &visi
|
||||
bool in_viewport = false;
|
||||
if(renderPass == KRNode::RENDER_PASS_PRESTREAM) {
|
||||
// When pre-streaming, objects are streamed in behind and in-front of the camera
|
||||
KRAABB viewportExtents = KRAABB(viewport.getCameraPosition() - Vector3(pCamera->settings.getPerspectiveFarZ()), viewport.getCameraPosition() + Vector3(pCamera->settings.getPerspectiveFarZ()));
|
||||
AABB viewportExtents = AABB(viewport.getCameraPosition() - Vector3(pCamera->settings.getPerspectiveFarZ()), viewport.getCameraPosition() + Vector3(pCamera->settings.getPerspectiveFarZ()));
|
||||
in_viewport = octreeBounds.intersects(viewportExtents);
|
||||
} else {
|
||||
in_viewport = viewport.visible(pOctreeNode->getBounds());
|
||||
@@ -227,7 +227,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map<KRAABB, int> &visi
|
||||
if(!bVisible) {
|
||||
// Assume bounding boxes are visible without occlusion test queries if the camera is inside the box.
|
||||
// The near clipping plane of the camera is taken into consideration by expanding the match area
|
||||
KRAABB cameraExtents = KRAABB(viewport.getCameraPosition() - Vector3(pCamera->settings.getPerspectiveNearZ()), viewport.getCameraPosition() + Vector3(pCamera->settings.getPerspectiveNearZ()));
|
||||
AABB cameraExtents = AABB(viewport.getCameraPosition() - Vector3(pCamera->settings.getPerspectiveNearZ()), viewport.getCameraPosition() + Vector3(pCamera->settings.getPerspectiveNearZ()));
|
||||
bVisible = octreeBounds.intersects(cameraExtents);
|
||||
if(bVisible) {
|
||||
// Record the frame number in which the camera was within the bounds
|
||||
@@ -240,7 +240,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map<KRAABB, int> &visi
|
||||
if(!bVisible) {
|
||||
// Check if a previous occlusion query has returned true, taking advantage of temporal consistency of visible elements from frame to frame
|
||||
// If the previous frame rendered this octree, then attempt to render it in this frame without performing a pre-occlusion test
|
||||
unordered_map<KRAABB, int>::iterator match_itr = visibleBounds.find(octreeBounds);
|
||||
unordered_map<AABB, int>::iterator match_itr = visibleBounds.find(octreeBounds);
|
||||
if(match_itr != visibleBounds.end()) {
|
||||
if((*match_itr).second == -1) {
|
||||
// We have already tested these bounds with a negative result
|
||||
@@ -569,12 +569,12 @@ void KRScene::addDefaultLights()
|
||||
m_pRootNode->addChild(light1);
|
||||
}
|
||||
|
||||
KRAABB KRScene::getRootOctreeBounds()
|
||||
AABB KRScene::getRootOctreeBounds()
|
||||
{
|
||||
if(m_nodeTree.getRootNode()) {
|
||||
return m_nodeTree.getRootNode()->getBounds();
|
||||
} else {
|
||||
return KRAABB(-Vector3::One(), Vector3::One());
|
||||
return AABB(-Vector3::One(), Vector3::One());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,9 +70,9 @@ public:
|
||||
bool sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask);
|
||||
|
||||
void renderFrame(GLint defaultFBO, float deltaTime, int width, int height);
|
||||
void render(KRCamera *pCamera, unordered_map<KRAABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame);
|
||||
void render(KRCamera *pCamera, unordered_map<AABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame);
|
||||
|
||||
void render(KROctreeNode *pOctreeNode, unordered_map<KRAABB, int> &visibleBounds, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly);
|
||||
void render(KROctreeNode *pOctreeNode, unordered_map<AABB, int> &visibleBounds, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly);
|
||||
|
||||
void updateOctree(const KRViewport &viewport);
|
||||
void buildOctreeForTheFirstTime();
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
void physicsUpdate(float deltaTime);
|
||||
void addDefaultLights();
|
||||
|
||||
KRAABB getRootOctreeBounds();
|
||||
AABB getRootOctreeBounds();
|
||||
|
||||
std::set<KRAmbientZone *> &getAmbientZones();
|
||||
std::set<KRReverbZone *> &getReverbZones();
|
||||
|
||||
@@ -50,12 +50,12 @@ void KRSpotLight::setOuterAngle(float outerAngle) {
|
||||
m_outerAngle = outerAngle;
|
||||
}
|
||||
|
||||
KRAABB KRSpotLight::getBounds() {
|
||||
AABB KRSpotLight::getBounds() {
|
||||
float influence_radius = m_decayStart - sqrt(m_intensity * 0.01f) / sqrt(KRLIGHT_MIN_INFLUENCE);
|
||||
if(influence_radius < m_flareOcclusionSize) {
|
||||
influence_radius = m_flareOcclusionSize;
|
||||
}
|
||||
return KRAABB(Vector3(-influence_radius), Vector3(influence_radius), getModelMatrix());
|
||||
return AABB(Vector3(-influence_radius), Vector3(influence_radius), getModelMatrix());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
virtual std::string getElementName();
|
||||
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
|
||||
virtual void loadXML(tinyxml2::XMLElement *e);
|
||||
virtual KRAABB getBounds();
|
||||
virtual AABB getBounds();
|
||||
|
||||
float getInnerAngle();
|
||||
float getOuterAngle();
|
||||
|
||||
@@ -76,8 +76,8 @@ float KRSprite::getSpriteAlpha() const
|
||||
return m_spriteAlpha;
|
||||
}
|
||||
|
||||
KRAABB KRSprite::getBounds() {
|
||||
return KRAABB(-Vector3::One() * 0.5f, Vector3::One() * 0.5f, getModelMatrix());
|
||||
AABB KRSprite::getBounds() {
|
||||
return AABB(-Vector3::One() * 0.5f, Vector3::One() * 0.5f, getModelMatrix());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
|
||||
virtual void render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
|
||||
|
||||
virtual KRAABB getBounds();
|
||||
virtual AABB getBounds();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ void KRViewport::calculateDerivedValues()
|
||||
}
|
||||
|
||||
|
||||
unordered_map<KRAABB, int> &KRViewport::getVisibleBounds()
|
||||
unordered_map<AABB, int> &KRViewport::getVisibleBounds()
|
||||
{
|
||||
return m_visibleBounds;
|
||||
}
|
||||
@@ -169,7 +169,7 @@ void KRViewport::setLODBias(float lod_bias)
|
||||
m_lodBias = lod_bias;
|
||||
}
|
||||
|
||||
float KRViewport::coverage(const KRAABB &b) const
|
||||
float KRViewport::coverage(const AABB &b) const
|
||||
{
|
||||
if(!visible(b)) {
|
||||
return 0.0f; // Culled out by view frustrum
|
||||
@@ -213,7 +213,7 @@ float KRViewport::coverage(const KRAABB &b) const
|
||||
}
|
||||
|
||||
|
||||
bool KRViewport::visible(const KRAABB &b) const
|
||||
bool KRViewport::visible(const AABB &b) const
|
||||
{
|
||||
// test if bounding box would be within the visible range of the clip space transformed by matViewProjection
|
||||
// This is used for view frustrum culling
|
||||
|
||||
@@ -38,13 +38,13 @@ public:
|
||||
// Overload assignment operator
|
||||
KRViewport& operator=(const KRViewport &v);
|
||||
|
||||
unordered_map<KRAABB, int> &getVisibleBounds();
|
||||
unordered_map<AABB, int> &getVisibleBounds();
|
||||
|
||||
const std::set<KRLight *> &getVisibleLights();
|
||||
void setVisibleLights(const std::set<KRLight *> visibleLights);
|
||||
|
||||
bool visible(const KRAABB &b) const;
|
||||
float coverage(const KRAABB &b) const;
|
||||
bool visible(const AABB &b) const;
|
||||
float coverage(const AABB &b) const;
|
||||
|
||||
private:
|
||||
Vector2 m_size;
|
||||
@@ -65,7 +65,7 @@ private:
|
||||
|
||||
void calculateDerivedValues();
|
||||
|
||||
unordered_map<KRAABB, int> m_visibleBounds; // AABB's that output fragments in the last frame
|
||||
unordered_map<AABB, int> m_visibleBounds; // AABB's that output fragments in the last frame
|
||||
|
||||
|
||||
};
|
||||
|
||||
54
kraken/KRAABB.cpp → kraken/aabb.cpp
Executable file → Normal file
54
kraken/KRAABB.cpp → kraken/aabb.cpp
Executable file → Normal file
@@ -10,19 +10,19 @@
|
||||
#include "assert.h"
|
||||
#include "KRHelpers.h"
|
||||
|
||||
KRAABB::KRAABB()
|
||||
AABB::AABB()
|
||||
{
|
||||
min = Vector3::Min();
|
||||
max = Vector3::Max();
|
||||
}
|
||||
|
||||
KRAABB::KRAABB(const Vector3 &minPoint, const Vector3 &maxPoint)
|
||||
AABB::AABB(const Vector3 &minPoint, const Vector3 &maxPoint)
|
||||
{
|
||||
min = minPoint;
|
||||
max = maxPoint;
|
||||
}
|
||||
|
||||
KRAABB::KRAABB(const Vector3 &corner1, const Vector3 &corner2, const Matrix4 &modelMatrix)
|
||||
AABB::AABB(const Vector3 &corner1, const Vector3 &corner2, const Matrix4 &modelMatrix)
|
||||
{
|
||||
for(int iCorner=0; iCorner<8; iCorner++) {
|
||||
Vector3 sourceCornerVertex = Matrix4::DotWDiv(modelMatrix, Vector3(
|
||||
@@ -45,12 +45,12 @@ KRAABB::KRAABB(const Vector3 &corner1, const Vector3 &corner2, const Matrix4 &mo
|
||||
}
|
||||
}
|
||||
|
||||
KRAABB::~KRAABB()
|
||||
AABB::~AABB()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
KRAABB& KRAABB::operator =(const KRAABB& b)
|
||||
AABB& AABB::operator =(const AABB& b)
|
||||
{
|
||||
min = b.min;
|
||||
max = b.max;
|
||||
@@ -58,33 +58,33 @@ KRAABB& KRAABB::operator =(const KRAABB& b)
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool KRAABB::operator ==(const KRAABB& b) const
|
||||
bool AABB::operator ==(const AABB& b) const
|
||||
{
|
||||
return min == b.min && max == b.max;
|
||||
}
|
||||
|
||||
bool KRAABB::operator !=(const KRAABB& b) const
|
||||
bool AABB::operator !=(const AABB& b) const
|
||||
{
|
||||
return min != b.min || max != b.max;
|
||||
}
|
||||
|
||||
Vector3 KRAABB::center() const
|
||||
Vector3 AABB::center() const
|
||||
{
|
||||
return (min + max) * 0.5f;
|
||||
}
|
||||
|
||||
Vector3 KRAABB::size() const
|
||||
Vector3 AABB::size() const
|
||||
{
|
||||
return max - min;
|
||||
}
|
||||
|
||||
float KRAABB::volume() const
|
||||
float AABB::volume() const
|
||||
{
|
||||
Vector3 s = size();
|
||||
return s.x * s.y * s.z;
|
||||
}
|
||||
|
||||
void KRAABB::scale(const Vector3 &s)
|
||||
void AABB::scale(const Vector3 &s)
|
||||
{
|
||||
Vector3 prev_center = center();
|
||||
Vector3 prev_size = size();
|
||||
@@ -93,12 +93,12 @@ void KRAABB::scale(const Vector3 &s)
|
||||
max = prev_center + new_scale;
|
||||
}
|
||||
|
||||
void KRAABB::scale(float s)
|
||||
void AABB::scale(float s)
|
||||
{
|
||||
scale(Vector3(s));
|
||||
}
|
||||
|
||||
bool KRAABB::operator >(const KRAABB& b) const
|
||||
bool AABB::operator >(const AABB& b) const
|
||||
{
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
if(min > b.min) {
|
||||
@@ -112,7 +112,7 @@ bool KRAABB::operator >(const KRAABB& b) const
|
||||
}
|
||||
|
||||
}
|
||||
bool KRAABB::operator <(const KRAABB& b) const
|
||||
bool AABB::operator <(const AABB& b) const
|
||||
{
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
|
||||
@@ -127,34 +127,34 @@ bool KRAABB::operator <(const KRAABB& b) const
|
||||
}
|
||||
}
|
||||
|
||||
bool KRAABB::intersects(const KRAABB& b) const
|
||||
bool AABB::intersects(const AABB& b) const
|
||||
{
|
||||
// Return true if the two volumes intersect
|
||||
return min.x <= b.max.x && min.y <= b.max.y && min.z <= b.max.z && max.x >= b.min.x && max.y >= b.min.y && max.z >= b.min.z;
|
||||
}
|
||||
|
||||
bool KRAABB::contains(const KRAABB &b) const
|
||||
bool AABB::contains(const AABB &b) const
|
||||
{
|
||||
// Return true if the passed KRAABB is entirely contained within this KRAABB
|
||||
return b.min.x >= min.x && b.min.y >= min.y && b.min.z >= min.z && b.max.x <= max.x && b.max.y <= max.y && b.max.z <= max.z;
|
||||
}
|
||||
|
||||
bool KRAABB::contains(const Vector3 &v) const
|
||||
bool AABB::contains(const Vector3 &v) const
|
||||
{
|
||||
return v.x >= min.x && v.x <= max.x && v.y >= min.y && v.y <= max.y && v.z >= min.z && v.z <= max.z;
|
||||
}
|
||||
|
||||
KRAABB KRAABB::Infinite()
|
||||
AABB AABB::Infinite()
|
||||
{
|
||||
return KRAABB(Vector3::Min(), Vector3::Max());
|
||||
return AABB(Vector3::Min(), Vector3::Max());
|
||||
}
|
||||
|
||||
KRAABB KRAABB::Zero()
|
||||
AABB AABB::Zero()
|
||||
{
|
||||
return KRAABB(Vector3::Zero(), Vector3::Zero());
|
||||
return AABB(Vector3::Zero(), Vector3::Zero());
|
||||
}
|
||||
|
||||
float KRAABB::longest_radius() const
|
||||
float AABB::longest_radius() const
|
||||
{
|
||||
float radius1 = (center() - min).magnitude();
|
||||
float radius2 = (max - center()).magnitude();
|
||||
@@ -162,7 +162,7 @@ float KRAABB::longest_radius() const
|
||||
}
|
||||
|
||||
|
||||
bool KRAABB::intersectsLine(const Vector3 &v1, const Vector3 &v2) const
|
||||
bool AABB::intersectsLine(const Vector3 &v1, const Vector3 &v2) const
|
||||
{
|
||||
Vector3 dir = Vector3::Normalize(v2 - v1);
|
||||
float length = (v2 - v1).magnitude();
|
||||
@@ -205,7 +205,7 @@ bool KRAABB::intersectsLine(const Vector3 &v1, const Vector3 &v2) const
|
||||
return false ; // the ray did not hit the box.
|
||||
}
|
||||
|
||||
bool KRAABB::intersectsRay(const Vector3 &v1, const Vector3 &dir) const
|
||||
bool AABB::intersectsRay(const Vector3 &v1, const Vector3 &dir) const
|
||||
{
|
||||
/*
|
||||
Fast Ray-Box Intersection
|
||||
@@ -281,7 +281,7 @@ bool KRAABB::intersectsRay(const Vector3 &v1, const Vector3 &dir) const
|
||||
return true; /* ray hits box */
|
||||
}
|
||||
|
||||
bool KRAABB::intersectsSphere(const Vector3 ¢er, float radius) const
|
||||
bool AABB::intersectsSphere(const Vector3 ¢er, float radius) const
|
||||
{
|
||||
// Arvo's Algorithm
|
||||
|
||||
@@ -317,7 +317,7 @@ bool KRAABB::intersectsSphere(const Vector3 ¢er, float radius) const
|
||||
return squaredDistance <= radius;
|
||||
}
|
||||
|
||||
void KRAABB::encapsulate(const KRAABB & b)
|
||||
void AABB::encapsulate(const AABB & b)
|
||||
{
|
||||
if(b.min.x < min.x) min.x = b.min.x;
|
||||
if(b.min.y < min.y) min.y = b.min.y;
|
||||
@@ -328,7 +328,7 @@ void KRAABB::encapsulate(const KRAABB & b)
|
||||
if(b.max.z > max.z) max.z = b.max.z;
|
||||
}
|
||||
|
||||
Vector3 KRAABB::nearestPoint(const Vector3 & v) const
|
||||
Vector3 AABB::nearestPoint(const Vector3 & v) const
|
||||
{
|
||||
return Vector3(KRCLAMP(v.x, min.x, max.x), KRCLAMP(v.y, min.y, max.y), KRCLAMP(v.z, min.z, max.z));
|
||||
}
|
||||
@@ -49,12 +49,12 @@ Matrix4::Matrix4(float *pMat) {
|
||||
memcpy(c, pMat, sizeof(float) * 16);
|
||||
}
|
||||
|
||||
Matrix4::Matrix4(const Vector3 &axis_x, const Vector3 &axis_y, const Vector3 &axis_z, const Vector3 &trans)
|
||||
Matrix4::Matrix4(const Vector3 &new_axis_x, const Vector3 &new_axis_y, const Vector3 &new_axis_z, const Vector3 &new_transform)
|
||||
{
|
||||
c[0] = axis_x.x; c[1] = axis_x.y; c[2] = axis_x.z; c[3] = 0.0f;
|
||||
c[4] = axis_y.x; c[5] = axis_y.y; c[6] = axis_y.z; c[7] = 0.0f;
|
||||
c[8] = axis_z.x; c[9] = axis_z.y; c[10] = axis_z.z; c[11] = 0.0f;
|
||||
c[12] = trans.x; c[13] = trans.y; c[14] = trans.z; c[15] = 1.0f;
|
||||
c[0] = new_axis_x.x; c[1] = new_axis_x.y; c[2] = new_axis_x.z; c[3] = 0.0f;
|
||||
c[4] = new_axis_y.x; c[5] = new_axis_y.y; c[6] = new_axis_y.z; c[7] = 0.0f;
|
||||
c[8] = new_axis_z.x; c[9] = new_axis_z.y; c[10] = new_axis_z.z; c[11] = 0.0f;
|
||||
c[12] = new_transform.x; c[13] = new_transform.y; c[14] = new_transform.z; c[15] = 1.0f;
|
||||
}
|
||||
|
||||
Matrix4::~Matrix4() {
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
// Axis aligned bounding box
|
||||
// Axis aligned bounding box (AABB)
|
||||
|
||||
#ifndef KRAABB_H
|
||||
#define KRAABB_H
|
||||
#ifndef KRAKEN_AABB_H
|
||||
#define KRAKEN_AABB_H
|
||||
|
||||
#include <functional> // for hash<>
|
||||
|
||||
@@ -20,12 +20,15 @@ namespace kraken {
|
||||
|
||||
class Matrix4;
|
||||
|
||||
class KRAABB {
|
||||
class AABB {
|
||||
public:
|
||||
KRAABB(const Vector3 &minPoint, const Vector3 &maxPoint);
|
||||
KRAABB(const Vector3 &corner1, const Vector3 &corner2, const Matrix4 &modelMatrix);
|
||||
KRAABB();
|
||||
~KRAABB();
|
||||
Vector3 min;
|
||||
Vector3 max;
|
||||
|
||||
AABB(const Vector3 &minPoint, const Vector3 &maxPoint);
|
||||
AABB(const Vector3 &corner1, const Vector3 &corner2, const Matrix4 &modelMatrix);
|
||||
AABB();
|
||||
~AABB();
|
||||
|
||||
void scale(const Vector3 &s);
|
||||
void scale(float s);
|
||||
@@ -33,28 +36,25 @@ public:
|
||||
Vector3 center() const;
|
||||
Vector3 size() const;
|
||||
float volume() const;
|
||||
bool intersects(const KRAABB& b) const;
|
||||
bool contains(const KRAABB &b) const;
|
||||
bool intersects(const AABB& b) const;
|
||||
bool contains(const AABB &b) const;
|
||||
bool contains(const Vector3 &v) const;
|
||||
|
||||
bool intersectsLine(const Vector3 &v1, const Vector3 &v2) const;
|
||||
bool intersectsRay(const Vector3 &v1, const Vector3 &dir) const;
|
||||
bool intersectsSphere(const Vector3 ¢er, float radius) const;
|
||||
void encapsulate(const KRAABB & b);
|
||||
void encapsulate(const AABB & b);
|
||||
|
||||
KRAABB& operator =(const KRAABB& b);
|
||||
bool operator ==(const KRAABB& b) const;
|
||||
bool operator !=(const KRAABB& b) const;
|
||||
AABB& operator =(const AABB& b);
|
||||
bool operator ==(const AABB& b) const;
|
||||
bool operator !=(const AABB& b) const;
|
||||
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
bool operator >(const KRAABB& b) const;
|
||||
bool operator <(const KRAABB& b) const;
|
||||
bool operator >(const AABB& b) const;
|
||||
bool operator <(const AABB& b) const;
|
||||
|
||||
Vector3 min;
|
||||
Vector3 max;
|
||||
|
||||
static KRAABB Infinite();
|
||||
static KRAABB Zero();
|
||||
static AABB Infinite();
|
||||
static AABB Zero();
|
||||
|
||||
float longest_radius() const;
|
||||
Vector3 nearestPoint(const Vector3 & v) const;
|
||||
@@ -64,9 +64,9 @@ public:
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<kraken::KRAABB> {
|
||||
struct hash<kraken::AABB> {
|
||||
public:
|
||||
size_t operator()(const kraken::KRAABB &s) const
|
||||
size_t operator()(const kraken::AABB &s) const
|
||||
{
|
||||
size_t h1 = hash<kraken::Vector3>()(s.min);
|
||||
size_t h2 = hash<kraken::Vector3>()(s.max);
|
||||
@@ -76,4 +76,4 @@ namespace std {
|
||||
} // namespace std
|
||||
|
||||
|
||||
#endif /* defined(KRAABB_H) */
|
||||
#endif /* defined(KRAKEN_AABB_H) */
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "vector4.h"
|
||||
#include "matrix4.h"
|
||||
#include "quaternion.h"
|
||||
#include "KRAABB.h"
|
||||
#include "aabb.h"
|
||||
#include "triangle3.h"
|
||||
|
||||
#endif // KRAKEN_H
|
||||
|
||||
@@ -49,14 +49,20 @@ class Quaternion;
|
||||
class Matrix4 {
|
||||
public:
|
||||
|
||||
float c[16]; // Matrix components, in column-major order
|
||||
union {
|
||||
struct {
|
||||
Vector4 axis_x, axis_y, axis_z, transform;
|
||||
};
|
||||
// Matrix components, in column-major order
|
||||
float c[16];
|
||||
};
|
||||
|
||||
// Default constructor - Creates an identity matrix
|
||||
Matrix4();
|
||||
|
||||
Matrix4(float *pMat);
|
||||
|
||||
Matrix4(const Vector3 &axis_x, const Vector3 &axis_y, const Vector3 &axis_z, const Vector3 &trans);
|
||||
Matrix4(const Vector3 &new_axis_x, const Vector3 &new_axis_y, const Vector3 &new_axis_z, const Vector3 &new_transform);
|
||||
|
||||
// Destructor
|
||||
~Matrix4();
|
||||
@@ -112,4 +118,19 @@ public:
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<kraken::Matrix4> {
|
||||
public:
|
||||
size_t operator()(const kraken::Matrix4 &s) const
|
||||
{
|
||||
size_t h1 = hash<kraken::Vector4>()(s.axis_x);
|
||||
size_t h2 = hash<kraken::Vector4>()(s.axis_y);
|
||||
size_t h3 = hash<kraken::Vector4>()(s.axis_z);
|
||||
size_t h4 = hash<kraken::Vector4>()(s.transform);
|
||||
return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3);
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#endif // KRAKEN_MATRIX4_H
|
||||
|
||||
@@ -38,6 +38,13 @@ namespace kraken {
|
||||
|
||||
class Quaternion {
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
float w, x, y, z;
|
||||
};
|
||||
float c[4];
|
||||
};
|
||||
|
||||
Quaternion();
|
||||
Quaternion(float w, float x, float y, float z);
|
||||
Quaternion(const Quaternion& p);
|
||||
@@ -81,10 +88,23 @@ public:
|
||||
static Quaternion Lerp(const Quaternion &a, const Quaternion &b, float t);
|
||||
static Quaternion Slerp(const Quaternion &a, const Quaternion &b, float t);
|
||||
static float Dot(const Quaternion &v1, const Quaternion &v2);
|
||||
private:
|
||||
float m_val[4];
|
||||
};
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<kraken::Quaternion> {
|
||||
public:
|
||||
size_t operator()(const kraken::Quaternion &s) const
|
||||
{
|
||||
size_t h1 = hash<float>()(s.c[0]);
|
||||
size_t h2 = hash<float>()(s.c[1]);
|
||||
size_t h3 = hash<float>()(s.c[2]);
|
||||
size_t h4 = hash<float>()(s.c[3]);
|
||||
return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3);
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#endif // KRAKEN_QUATERNION_H
|
||||
|
||||
@@ -36,31 +36,31 @@
|
||||
namespace kraken {
|
||||
|
||||
Quaternion::Quaternion() {
|
||||
m_val[0] = 1.0;
|
||||
m_val[1] = 0.0;
|
||||
m_val[2] = 0.0;
|
||||
m_val[3] = 0.0;
|
||||
c[0] = 1.0;
|
||||
c[1] = 0.0;
|
||||
c[2] = 0.0;
|
||||
c[3] = 0.0;
|
||||
}
|
||||
|
||||
Quaternion::Quaternion(float w, float x, float y, float z) {
|
||||
m_val[0] = w;
|
||||
m_val[1] = x;
|
||||
m_val[2] = y;
|
||||
m_val[3] = z;
|
||||
c[0] = w;
|
||||
c[1] = x;
|
||||
c[2] = y;
|
||||
c[3] = z;
|
||||
}
|
||||
|
||||
Quaternion::Quaternion(const Quaternion& p) {
|
||||
m_val[0] = p[0];
|
||||
m_val[1] = p[1];
|
||||
m_val[2] = p[2];
|
||||
m_val[3] = p[3];
|
||||
c[0] = p[0];
|
||||
c[1] = p[1];
|
||||
c[2] = p[2];
|
||||
c[3] = p[3];
|
||||
}
|
||||
|
||||
Quaternion& Quaternion::operator =( const Quaternion& p ) {
|
||||
m_val[0] = p[0];
|
||||
m_val[1] = p[1];
|
||||
m_val[2] = p[2];
|
||||
m_val[3] = p[3];
|
||||
c[0] = p[0];
|
||||
c[1] = p[1];
|
||||
c[2] = p[2];
|
||||
c[3] = p[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -71,10 +71,10 @@ Quaternion::Quaternion(const Vector3 &euler) {
|
||||
Quaternion::Quaternion(const Vector3 &from_vector, const Vector3 &to_vector) {
|
||||
|
||||
Vector3 a = Vector3::Cross(from_vector, to_vector);
|
||||
m_val[0] = a[0];
|
||||
m_val[1] = a[1];
|
||||
m_val[2] = a[2];
|
||||
m_val[3] = sqrt(from_vector.sqrMagnitude() * to_vector.sqrMagnitude()) + Vector3::Dot(from_vector, to_vector);
|
||||
c[0] = a[0];
|
||||
c[1] = a[1];
|
||||
c[2] = a[2];
|
||||
c[3] = sqrt(from_vector.sqrMagnitude() * to_vector.sqrMagnitude()) + Vector3::Dot(from_vector, to_vector);
|
||||
normalize();
|
||||
}
|
||||
|
||||
@@ -98,39 +98,39 @@ void Quaternion::setEulerZYX(const Vector3 &euler) {
|
||||
float s2 = sin(euler[1] * 0.5f);
|
||||
float s3 = sin(euler[2] * 0.5f);
|
||||
|
||||
m_val[0] = c1 * c2 * c3 + s1 * s2 * s3;
|
||||
m_val[1] = s1 * c2 * c3 - c1 * s2 * s3;
|
||||
m_val[2] = c1 * s2 * c3 + s1 * c2 * s3;
|
||||
m_val[3] = c1 * c2 * s3 - s1 * s2 * c3;
|
||||
c[0] = c1 * c2 * c3 + s1 * s2 * s3;
|
||||
c[1] = s1 * c2 * c3 - c1 * s2 * s3;
|
||||
c[2] = c1 * s2 * c3 + s1 * c2 * s3;
|
||||
c[3] = c1 * c2 * s3 - s1 * s2 * c3;
|
||||
}
|
||||
|
||||
float Quaternion::operator [](unsigned i) const {
|
||||
return m_val[i];
|
||||
return c[i];
|
||||
}
|
||||
|
||||
float &Quaternion::operator [](unsigned i) {
|
||||
return m_val[i];
|
||||
return c[i];
|
||||
}
|
||||
|
||||
Vector3 Quaternion::eulerXYZ() const {
|
||||
double a2 = 2 * (m_val[0] * m_val[2] - m_val[1] * m_val[3]);
|
||||
double a2 = 2 * (c[0] * c[2] - c[1] * c[3]);
|
||||
if(a2 <= -0.99999) {
|
||||
return Vector3(
|
||||
2.0 * atan2(m_val[1], m_val[0]),
|
||||
2.0 * atan2(c[1], c[0]),
|
||||
-PI * 0.5f,
|
||||
0
|
||||
);
|
||||
} else if(a2 >= 0.99999) {
|
||||
return Vector3(
|
||||
2.0 * atan2(m_val[1], m_val[0]),
|
||||
2.0 * atan2(c[1], c[0]),
|
||||
PI * 0.5f,
|
||||
0
|
||||
);
|
||||
} else {
|
||||
return Vector3(
|
||||
atan2(2 * (m_val[0] * m_val[1] + m_val[2] * m_val[3]), (1 - 2 * (m_val[1] * m_val[1] + m_val[2] * m_val[2]))),
|
||||
atan2(2 * (c[0] * c[1] + c[2] * c[3]), (1 - 2 * (c[1] * c[1] + c[2] * c[2]))),
|
||||
asin(a2),
|
||||
atan2(2 * (m_val[0] * m_val[3] + m_val[1] * m_val[2]), (1 - 2 * (m_val[2] * m_val[2] + m_val[3] * m_val[3])))
|
||||
atan2(2 * (c[0] * c[3] + c[1] * c[2]), (1 - 2 * (c[2] * c[2] + c[3] * c[3])))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -154,14 +154,14 @@ bool operator !=(Quaternion &v1, Quaternion &v2) {
|
||||
}
|
||||
|
||||
Quaternion Quaternion::operator *(const Quaternion &v) {
|
||||
float t0 = (m_val[3]-m_val[2])*(v[2]-v[3]);
|
||||
float t1 = (m_val[0]+m_val[1])*(v[0]+v[1]);
|
||||
float t2 = (m_val[0]-m_val[1])*(v[2]+v[3]);
|
||||
float t3 = (m_val[3]+m_val[2])*(v[0]-v[1]);
|
||||
float t4 = (m_val[3]-m_val[1])*(v[1]-v[2]);
|
||||
float t5 = (m_val[3]+m_val[1])*(v[1]+v[2]);
|
||||
float t6 = (m_val[0]+m_val[2])*(v[0]-v[3]);
|
||||
float t7 = (m_val[0]-m_val[2])*(v[0]+v[3]);
|
||||
float t0 = (c[3]-c[2])*(v[2]-v[3]);
|
||||
float t1 = (c[0]+c[1])*(v[0]+v[1]);
|
||||
float t2 = (c[0]-c[1])*(v[2]+v[3]);
|
||||
float t3 = (c[3]+c[2])*(v[0]-v[1]);
|
||||
float t4 = (c[3]-c[1])*(v[1]-v[2]);
|
||||
float t5 = (c[3]+c[1])*(v[1]+v[2]);
|
||||
float t6 = (c[0]+c[2])*(v[0]-v[3]);
|
||||
float t7 = (c[0]-c[2])*(v[0]+v[3]);
|
||||
float t8 = t5+t6+t7;
|
||||
float t9 = (t4+t8)/2;
|
||||
|
||||
@@ -174,72 +174,72 @@ Quaternion Quaternion::operator *(const Quaternion &v) {
|
||||
}
|
||||
|
||||
Quaternion Quaternion::operator *(float v) const {
|
||||
return Quaternion(m_val[0] * v, m_val[1] * v, m_val[2] * v, m_val[3] * v);
|
||||
return Quaternion(c[0] * v, c[1] * v, c[2] * v, c[3] * v);
|
||||
}
|
||||
|
||||
Quaternion Quaternion::operator /(float num) const {
|
||||
float inv_num = 1.0f / num;
|
||||
return Quaternion(m_val[0] * inv_num, m_val[1] * inv_num, m_val[2] * inv_num, m_val[3] * inv_num);
|
||||
return Quaternion(c[0] * inv_num, c[1] * inv_num, c[2] * inv_num, c[3] * inv_num);
|
||||
}
|
||||
|
||||
Quaternion Quaternion::operator +(const Quaternion &v) const {
|
||||
return Quaternion(m_val[0] + v[0], m_val[1] + v[1], m_val[2] + v[2], m_val[3] + v[3]);
|
||||
return Quaternion(c[0] + v[0], c[1] + v[1], c[2] + v[2], c[3] + v[3]);
|
||||
}
|
||||
|
||||
Quaternion Quaternion::operator -(const Quaternion &v) const {
|
||||
return Quaternion(m_val[0] - v[0], m_val[1] - v[1], m_val[2] - v[2], m_val[3] - v[3]);
|
||||
return Quaternion(c[0] - v[0], c[1] - v[1], c[2] - v[2], c[3] - v[3]);
|
||||
}
|
||||
|
||||
Quaternion& Quaternion::operator +=(const Quaternion& v) {
|
||||
m_val[0] += v[0];
|
||||
m_val[1] += v[1];
|
||||
m_val[2] += v[2];
|
||||
m_val[3] += v[3];
|
||||
c[0] += v[0];
|
||||
c[1] += v[1];
|
||||
c[2] += v[2];
|
||||
c[3] += v[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
Quaternion& Quaternion::operator -=(const Quaternion& v) {
|
||||
m_val[0] -= v[0];
|
||||
m_val[1] -= v[1];
|
||||
m_val[2] -= v[2];
|
||||
m_val[3] -= v[3];
|
||||
c[0] -= v[0];
|
||||
c[1] -= v[1];
|
||||
c[2] -= v[2];
|
||||
c[3] -= v[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
Quaternion& Quaternion::operator *=(const Quaternion& v) {
|
||||
float t0 = (m_val[3]-m_val[2])*(v[2]-v[3]);
|
||||
float t1 = (m_val[0]+m_val[1])*(v[0]+v[1]);
|
||||
float t2 = (m_val[0]-m_val[1])*(v[2]+v[3]);
|
||||
float t3 = (m_val[3]+m_val[2])*(v[0]-v[1]);
|
||||
float t4 = (m_val[3]-m_val[1])*(v[1]-v[2]);
|
||||
float t5 = (m_val[3]+m_val[1])*(v[1]+v[2]);
|
||||
float t6 = (m_val[0]+m_val[2])*(v[0]-v[3]);
|
||||
float t7 = (m_val[0]-m_val[2])*(v[0]+v[3]);
|
||||
float t0 = (c[3]-c[2])*(v[2]-v[3]);
|
||||
float t1 = (c[0]+c[1])*(v[0]+v[1]);
|
||||
float t2 = (c[0]-c[1])*(v[2]+v[3]);
|
||||
float t3 = (c[3]+c[2])*(v[0]-v[1]);
|
||||
float t4 = (c[3]-c[1])*(v[1]-v[2]);
|
||||
float t5 = (c[3]+c[1])*(v[1]+v[2]);
|
||||
float t6 = (c[0]+c[2])*(v[0]-v[3]);
|
||||
float t7 = (c[0]-c[2])*(v[0]+v[3]);
|
||||
float t8 = t5+t6+t7;
|
||||
float t9 = (t4+t8)/2;
|
||||
|
||||
m_val[0] = t0+t9-t5;
|
||||
m_val[1] = t1+t9-t8;
|
||||
m_val[2] = t2+t9-t7;
|
||||
m_val[3] = t3+t9-t6;
|
||||
c[0] = t0+t9-t5;
|
||||
c[1] = t1+t9-t8;
|
||||
c[2] = t2+t9-t7;
|
||||
c[3] = t3+t9-t6;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Quaternion& Quaternion::operator *=(const float& v) {
|
||||
m_val[0] *= v;
|
||||
m_val[1] *= v;
|
||||
m_val[2] *= v;
|
||||
m_val[3] *= v;
|
||||
c[0] *= v;
|
||||
c[1] *= v;
|
||||
c[2] *= v;
|
||||
c[3] *= v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Quaternion& Quaternion::operator /=(const float& v) {
|
||||
float inv_v = 1.0f / v;
|
||||
m_val[0] *= inv_v;
|
||||
m_val[1] *= inv_v;
|
||||
m_val[2] *= inv_v;
|
||||
m_val[3] *= inv_v;
|
||||
c[0] *= inv_v;
|
||||
c[1] *= inv_v;
|
||||
c[2] *= inv_v;
|
||||
c[3] *= inv_v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ Quaternion Quaternion::operator +() const {
|
||||
}
|
||||
|
||||
Quaternion Quaternion::operator -() const {
|
||||
return Quaternion(-m_val[0], -m_val[1], -m_val[2], -m_val[3]);
|
||||
return Quaternion(-c[0], -c[1], -c[2], -c[3]);
|
||||
}
|
||||
|
||||
Quaternion Normalize(const Quaternion &v1) {
|
||||
@@ -262,11 +262,11 @@ Quaternion Normalize(const Quaternion &v1) {
|
||||
}
|
||||
|
||||
void Quaternion::normalize() {
|
||||
float inv_magnitude = 1.0f / sqrtf(m_val[0] * m_val[0] + m_val[1] * m_val[1] + m_val[2] * m_val[2] + m_val[3] * m_val[3]);
|
||||
m_val[0] *= inv_magnitude;
|
||||
m_val[1] *= inv_magnitude;
|
||||
m_val[2] *= inv_magnitude;
|
||||
m_val[3] *= inv_magnitude;
|
||||
float inv_magnitude = 1.0f / sqrtf(c[0] * c[0] + c[1] * c[1] + c[2] * c[2] + c[3] * c[3]);
|
||||
c[0] *= inv_magnitude;
|
||||
c[1] *= inv_magnitude;
|
||||
c[2] *= inv_magnitude;
|
||||
c[3] *= inv_magnitude;
|
||||
}
|
||||
|
||||
Quaternion Conjugate(const Quaternion &v1) {
|
||||
@@ -274,9 +274,9 @@ Quaternion Conjugate(const Quaternion &v1) {
|
||||
}
|
||||
|
||||
void Quaternion::conjugate() {
|
||||
m_val[1] = -m_val[1];
|
||||
m_val[2] = -m_val[2];
|
||||
m_val[3] = -m_val[3];
|
||||
c[1] = -c[1];
|
||||
c[2] = -c[2];
|
||||
c[3] = -c[3];
|
||||
}
|
||||
|
||||
Matrix4 Quaternion::rotationMatrix() const {
|
||||
@@ -293,17 +293,17 @@ Matrix4 Quaternion::rotationMatrix() const {
|
||||
// FINDME - Determine why the more optimal routine commented below wasn't working
|
||||
|
||||
|
||||
matRotate.c[0] = 1.0 - 2.0 * (m_val[2] * m_val[2] + m_val[3] * m_val[3]);
|
||||
matRotate.c[1] = 2.0 * (m_val[1] * m_val[2] - m_val[0] * m_val[3]);
|
||||
matRotate.c[2] = 2.0 * (m_val[0] * m_val[2] + m_val[1] * m_val[3]);
|
||||
matRotate.c[0] = 1.0 - 2.0 * (c[2] * c[2] + c[3] * c[3]);
|
||||
matRotate.c[1] = 2.0 * (c[1] * c[2] - c[0] * c[3]);
|
||||
matRotate.c[2] = 2.0 * (c[0] * c[2] + c[1] * c[3]);
|
||||
|
||||
matRotate.c[4] = 2.0 * (m_val[1] * m_val[2] + m_val[0] * m_val[3]);
|
||||
matRotate.c[5] = 1.0 - 2.0 * (m_val[1] * m_val[1] + m_val[3] * m_val[3]);
|
||||
matRotate.c[6] = 2.0 * (m_val[2] * m_val[3] - m_val[0] * m_val[1]);
|
||||
matRotate.c[4] = 2.0 * (c[1] * c[2] + c[0] * c[3]);
|
||||
matRotate.c[5] = 1.0 - 2.0 * (c[1] * c[1] + c[3] * c[3]);
|
||||
matRotate.c[6] = 2.0 * (c[2] * c[3] - c[0] * c[1]);
|
||||
|
||||
matRotate.c[8] = 2.0 * (m_val[1] * m_val[3] - m_val[0] * m_val[2]);
|
||||
matRotate.c[9] = 2.0 * (m_val[0] * m_val[1] + m_val[2] * m_val[3]);
|
||||
matRotate.c[10] = 1.0 - 2.0 * (m_val[1] * m_val[1] + m_val[2] * m_val[2]);
|
||||
matRotate.c[8] = 2.0 * (c[1] * c[3] - c[0] * c[2]);
|
||||
matRotate.c[9] = 2.0 * (c[0] * c[1] + c[2] * c[3]);
|
||||
matRotate.c[10] = 1.0 - 2.0 * (c[1] * c[1] + c[2] * c[2]);
|
||||
|
||||
return matRotate;
|
||||
}
|
||||
@@ -318,7 +318,7 @@ Quaternion Quaternion::FromAngleAxis(const Vector3 &axis, float angle)
|
||||
|
||||
float Quaternion::Dot(const Quaternion &v1, const Quaternion &v2)
|
||||
{
|
||||
return v1.m_val[0] * v2.m_val[0] + v1.m_val[1] * v2.m_val[1] + v1.m_val[2] * v2.m_val[2] + v1.m_val[3] * v2.m_val[3];
|
||||
return v1.c[0] * v2.c[0] + v1.c[1] * v2.c[1] + v1.c[2] * v2.c[2] + v1.c[3] * v2.c[3];
|
||||
}
|
||||
|
||||
Quaternion Quaternion::Lerp(const Quaternion &a, const Quaternion &b, float t)
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\3rdparty\forsyth\forsyth.cpp" />
|
||||
<ClCompile Include="..\3rdparty\tinyxml2\tinyxml2.cpp" />
|
||||
<ClCompile Include="..\kraken\KRAABB.cpp" />
|
||||
<ClCompile Include="..\kraken\aabb.cpp" />
|
||||
<ClCompile Include="..\kraken\KRAmbientZone.cpp" />
|
||||
<ClCompile Include="..\kraken\KRAnimation.cpp" />
|
||||
<ClCompile Include="..\kraken\KRAnimationAttribute.cpp" />
|
||||
@@ -271,7 +271,7 @@
|
||||
<ClInclude Include="..\kraken\KRUnknown.h" />
|
||||
<ClInclude Include="..\kraken\KRUnknownManager.h" />
|
||||
<ClInclude Include="..\kraken\KRViewport.h" />
|
||||
<ClInclude Include="..\kraken\public\KRAABB.h" />
|
||||
<ClInclude Include="..\kraken\public\aabb.h" />
|
||||
<ClInclude Include="..\kraken\public\kraken.h" />
|
||||
<ClInclude Include="..\kraken\public\scalar.h" />
|
||||
<ClInclude Include="..\kraken\public\matrix4.h" />
|
||||
|
||||
@@ -33,9 +33,6 @@
|
||||
<ClCompile Include="..\kraken\KRFloat.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\kraken\KRAABB.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\kraken\KRViewport.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -252,6 +249,9 @@
|
||||
<ClCompile Include="..\kraken\triangle3.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\kraken\aabb.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\3rdparty\tinyxml2\tinyxml2.h">
|
||||
@@ -476,9 +476,6 @@
|
||||
<ClInclude Include="..\kraken\public\kraken.h">
|
||||
<Filter>Header Files\public</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\kraken\public\KRAABB.h">
|
||||
<Filter>Header Files\public</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\kraken\public\vector2.h">
|
||||
<Filter>Header Files\public</Filter>
|
||||
</ClInclude>
|
||||
@@ -500,5 +497,8 @@
|
||||
<ClInclude Include="..\kraken\public\triangle3.h">
|
||||
<Filter>Header Files\public</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\kraken\public\aabb.h">
|
||||
<Filter>Header Files\public</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user