From e611fe23361a8b9900c165f72db4d622eb432330 Mon Sep 17 00:00:00 2001 From: Kearwood Gilbert Date: Fri, 3 May 2013 17:38:42 -0700 Subject: [PATCH] Implemented workaround for broken KRQuaternion::RotationMatrix Added KRFloat --- KREngine/Kraken.xcodeproj/project.pbxproj | 12 ++++++++++++ KREngine/kraken/KRFloat.cpp | 15 +++++++++++++++ KREngine/kraken/KRFloat.h | 16 ++++++++++++++++ KREngine/kraken/KRQuaternion.cpp | 11 ++++++++++- 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 KREngine/kraken/KRFloat.cpp create mode 100644 KREngine/kraken/KRFloat.h diff --git a/KREngine/Kraken.xcodeproj/project.pbxproj b/KREngine/Kraken.xcodeproj/project.pbxproj index dd00767..355f8ad 100644 --- a/KREngine/Kraken.xcodeproj/project.pbxproj +++ b/KREngine/Kraken.xcodeproj/project.pbxproj @@ -148,6 +148,10 @@ E48C697015374F5B00232E28 /* KRContext.h in Headers */ = {isa = PBXBuildFile; fileRef = E48C696E15374F5A00232E28 /* KRContext.h */; settings = {ATTRIBUTES = (Public, ); }; }; E48C697215374F7E00232E28 /* KRContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48C697115374F7E00232E28 /* KRContext.cpp */; }; E48C697315374F7E00232E28 /* KRContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48C697115374F7E00232E28 /* KRContext.cpp */; }; + E48CF942173453990005EBBB /* KRFloat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48CF940173453990005EBBB /* KRFloat.cpp */; }; + E48CF943173453990005EBBB /* KRFloat.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48CF940173453990005EBBB /* KRFloat.cpp */; }; + E48CF944173453990005EBBB /* KRFloat.h in Headers */ = {isa = PBXBuildFile; fileRef = E48CF941173453990005EBBB /* KRFloat.h */; }; + E48CF945173453990005EBBB /* KRFloat.h in Headers */ = {isa = PBXBuildFile; fileRef = E48CF941173453990005EBBB /* KRFloat.h */; }; E491018713C99BDC0098455B /* KREngine.mm in Sources */ = {isa = PBXBuildFile; fileRef = E491016F13C99BDC0098455B /* KREngine.mm */; }; E491018A13C99BDC0098455B /* KREngine.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017213C99BDC0098455B /* KREngine.h */; settings = {ATTRIBUTES = (Public, ); }; }; E491018E13C99BDC0098455B /* KRMat4.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017613C99BDC0098455B /* KRMat4.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -455,6 +459,8 @@ E48B68141697794F00D99917 /* KRAudioSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = KRAudioSource.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E48C696E15374F5A00232E28 /* KRContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = KRContext.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E48C697115374F7E00232E28 /* KRContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = KRContext.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; + E48CF940173453990005EBBB /* KRFloat.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRFloat.cpp; sourceTree = ""; }; + E48CF941173453990005EBBB /* KRFloat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRFloat.h; sourceTree = ""; }; E491016113C99B9E0098455B /* libkraken.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libkraken.a; sourceTree = BUILT_PRODUCTS_DIR; }; E491016413C99B9E0098455B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; E491016813C99B9E0098455B /* Kraken-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Kraken-Prefix.pch"; sourceTree = ""; }; @@ -792,6 +798,8 @@ E40BA45315EFF79500D7C3DD /* KRAABB.h */, E4EC73BF1720B1FF0065299F /* KRVector4.cpp */, E4EC73C01720B1FF0065299F /* KRVector4.h */, + E48CF940173453990005EBBB /* KRFloat.cpp */, + E48CF941173453990005EBBB /* KRFloat.h */, ); name = Math; sourceTree = ""; @@ -1229,6 +1237,7 @@ E4FE6AA816B21D660058B8CE /* forsyth.h in Headers */, E4AE635F1704FB0A00B460CD /* KRLODGroup.h in Headers */, E4EC73C31720B1FF0065299F /* KRVector4.h in Headers */, + E48CF944173453990005EBBB /* KRFloat.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1306,6 +1315,7 @@ E4AE63601704FB0A00B460CD /* KRLODGroup.h in Headers */, E499BF1F16AE753E007FCDBE /* KRCollider.h in Headers */, E499BF2316AE7636007FCDBE /* kraken-prefix.pch in Headers */, + E48CF945173453990005EBBB /* KRFloat.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1569,6 +1579,7 @@ E450273916E0491D00FDEC5C /* KRReverbZone.cpp in Sources */, E4AE635D1704FB0A00B460CD /* KRLODGroup.cpp in Sources */, E4EC73C11720B1FF0065299F /* KRVector4.cpp in Sources */, + E48CF942173453990005EBBB /* KRFloat.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1643,6 +1654,7 @@ E450273A16E0491D00FDEC5C /* KRReverbZone.cpp in Sources */, E4AE635E1704FB0A00B460CD /* KRLODGroup.cpp in Sources */, E4EC73C21720B1FF0065299F /* KRVector4.cpp in Sources */, + E48CF943173453990005EBBB /* KRFloat.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/KREngine/kraken/KRFloat.cpp b/KREngine/kraken/KRFloat.cpp new file mode 100644 index 0000000..cc72083 --- /dev/null +++ b/KREngine/kraken/KRFloat.cpp @@ -0,0 +1,15 @@ +// +// KRFloat.cpp +// Kraken +// +// Created by Kearwood Gilbert on 2013-05-03. +// Copyright (c) 2013 Kearwood Software. All rights reserved. +// + +#include "KRFloat.h" + +float KRFloat::SmoothStep(float a, float b, float t) +{ + float d = (3.0 * t * t - 2.0 * t * t * t); + return a * (1.0f - d) + b * d; +} \ No newline at end of file diff --git a/KREngine/kraken/KRFloat.h b/KREngine/kraken/KRFloat.h new file mode 100644 index 0000000..91085e0 --- /dev/null +++ b/KREngine/kraken/KRFloat.h @@ -0,0 +1,16 @@ +// +// KRFloat.h +// Kraken +// +// Created by Kearwood Gilbert on 2013-05-03. +// Copyright (c) 2013 Kearwood Software. All rights reserved. +// + +#ifndef KRFLOAT_H +#define KRFLOAT_H + +namespace KRFloat { + float SmoothStep(float a, float b, float t); +}; + +#endif /* defined(KRFLOAT_H) */ diff --git a/KREngine/kraken/KRQuaternion.cpp b/KREngine/kraken/KRQuaternion.cpp index ac0d4e2..0d5a3cb 100644 --- a/KREngine/kraken/KRQuaternion.cpp +++ b/KREngine/kraken/KRQuaternion.cpp @@ -270,8 +270,16 @@ void KRQuaternion::conjugate() { } KRMat4 KRQuaternion::rotationMatrix() const { - KRMat4 matRotate; + KRVector3 euler = eulerXYZ(); + KRMat4 matRotate; + matRotate.rotate(euler.x, X_AXIS); + matRotate.rotate(euler.y, Y_AXIS); + matRotate.rotate(euler.z, Z_AXIS); + + // FINDME - Determine why the more optimal routine commented below wasn't working + + /* matRotate.getPointer()[0] = 1.0 - 2.0 * (m_val[2] * m_val[2] + m_val[3] * m_val[3]); matRotate.getPointer()[1] = 2.0 * (m_val[1] * m_val[2] - m_val[0] * m_val[3]); matRotate.getPointer()[2] = 2.0 * (m_val[0] * m_val[2] + m_val[1] * m_val[3]); @@ -283,6 +291,7 @@ KRMat4 KRQuaternion::rotationMatrix() const { matRotate.getPointer()[8] = 2.0 * (m_val[1] * m_val[3] - m_val[0] * m_val[2]); matRotate.getPointer()[9] = 2.0 * (m_val[0] * m_val[1] + m_val[2] * m_val[3]); matRotate.getPointer()[10] = 1.0 - 2.0 * (m_val[1] * m_val[1] + m_val[2] * m_val[2]); + */ return matRotate; }