Updated Subrepos, hydra data types are now POD -- refactored Kraken to match. Eliminated some warnings
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -2,3 +2,7 @@
|
||||
Kraken.xcodeproj/xcuserdata
|
||||
kraken_win/build/
|
||||
build/
|
||||
kraken.dir/
|
||||
Win32/
|
||||
x64/
|
||||
kraken_win
|
||||
|
||||
2
3rdparty/glad
vendored
2
3rdparty/glad
vendored
Submodule 3rdparty/glad updated: 5831fb7741...3ea14553f9
2
3rdparty/glfw
vendored
2
3rdparty/glfw
vendored
Submodule 3rdparty/glfw updated: 23dfeee4cb...0be4f3f75a
2
hydra
2
hydra
Submodule hydra updated: 00bb9b6689...759b7af066
@@ -2,16 +2,6 @@ include_directories(public)
|
||||
add_subdirectory(public)
|
||||
set(KRAKEN_PUBLIC_HEADERS "${KRAKEN_PUBLIC_HEADERS}" PARENT_SCOPE)
|
||||
|
||||
add_sources(scalar.cpp)
|
||||
add_sources(vector2.cpp)
|
||||
add_sources(vector3.cpp)
|
||||
add_sources(vector4.cpp)
|
||||
add_sources(triangle3.cpp)
|
||||
add_sources(quaternion.cpp)
|
||||
add_sources(matrix4.cpp)
|
||||
add_sources(aabb.cpp)
|
||||
add_sources(hitinfo.cpp)
|
||||
|
||||
# Private Implementation
|
||||
add_sources(KRAmbientZone.cpp)
|
||||
add_sources(KRAnimation.cpp)
|
||||
|
||||
@@ -139,7 +139,7 @@ void KRAmbientZone::setGradientDistance(float gradient_distance)
|
||||
|
||||
AABB KRAmbientZone::getBounds() {
|
||||
// Ambient zones always have a -1, -1, -1 to 1, 1, 1 bounding box
|
||||
return AABB(-Vector3::One(), Vector3::One(), getModelMatrix());
|
||||
return AABB::Create(-Vector3::One(), Vector3::One(), getModelMatrix());
|
||||
}
|
||||
|
||||
float KRAmbientZone::getContainment(const Vector3 &pos)
|
||||
@@ -149,7 +149,7 @@ float KRAmbientZone::getContainment(const Vector3 &pos)
|
||||
Vector3 size = bounds.size();
|
||||
Vector3 diff = pos - bounds.center();
|
||||
diff = diff * 2.0f;
|
||||
diff = Vector3(diff.x / size.x, diff.y / size.y, diff.z / size.z);
|
||||
diff = Vector3::Create(diff.x / size.x, diff.y / size.y, diff.z / size.z);
|
||||
float d = diff.magnitude();
|
||||
|
||||
if(m_gradient_distance <= 0.0f) {
|
||||
|
||||
@@ -309,7 +309,7 @@ void KRAudioManager::renderReverb()
|
||||
for(unordered_map<std::string, siren_reverb_zone_weight_info>::iterator zone_itr=m_reverb_zone_weights.begin(); zone_itr != m_reverb_zone_weights.end(); zone_itr++) {
|
||||
siren_reverb_zone_weight_info zi = (*zone_itr).second;
|
||||
if(zi.reverb_sample) {
|
||||
int zone_sample_blocks = KRMIN(zi.reverb_sample->getFrameCount(), m_reverb_max_length * 44100) / KRENGINE_AUDIO_BLOCK_LENGTH + 1;
|
||||
int zone_sample_blocks = KRMIN(zi.reverb_sample->getFrameCount(), (int)(m_reverb_max_length * 44100.0f)) / KRENGINE_AUDIO_BLOCK_LENGTH + 1;
|
||||
impulse_response_blocks = KRMAX(impulse_response_blocks, zone_sample_blocks);
|
||||
}
|
||||
}
|
||||
@@ -421,374 +421,374 @@ void KRSetAUCanonical(AudioStreamBasicDescription &desc, UInt32 nChannels, bool
|
||||
|
||||
void KRAudioManager::initHRTF()
|
||||
{
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,005.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,010.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,015.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,020.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,025.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,035.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,040.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,050.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,055.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,065.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,070.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,075.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,080.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,085.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,095.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,100.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,105.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,110.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,115.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,125.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,130.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,140.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,145.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,155.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,160.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,165.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,170.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,175.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-10.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,005.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,010.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,015.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,020.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,025.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,035.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,040.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,050.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,055.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,065.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,070.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,075.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,080.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,085.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,095.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,100.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,105.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,110.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,115.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,125.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,130.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,140.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,145.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,155.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,160.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,165.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,170.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,175.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-20.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,006.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,012.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,018.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,024.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,036.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,042.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,048.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,054.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,066.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,072.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,078.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,084.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,096.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,102.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,108.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,114.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,126.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,132.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,138.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,144.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,156.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,162.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,168.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,174.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-30.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,006.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,013.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,019.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,026.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,032.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,039.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,051.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,058.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,064.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,071.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,077.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,084.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,096.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,103.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,109.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,116.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,122.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,129.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,141.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,148.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,154.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,161.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,167.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,174.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(-40.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,005.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,010.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,015.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,020.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,025.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,035.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,040.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,050.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,055.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,065.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,070.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,075.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,080.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,085.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,095.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,100.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,105.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,110.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,115.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,125.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,130.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,140.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,145.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,155.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,160.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,165.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,170.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,175.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(0.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,005.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,010.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,015.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,020.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,025.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,035.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,040.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,050.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,055.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,065.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,070.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,075.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,080.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,085.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,095.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,100.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,105.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,110.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,115.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,125.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,130.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,140.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,145.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,155.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,160.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,165.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,170.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,175.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(10.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,005.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,010.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,015.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,020.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,025.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,035.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,040.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,050.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,055.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,065.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,070.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,075.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,080.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,085.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,095.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,100.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,105.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,110.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,115.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,125.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,130.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,140.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,145.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,155.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,160.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,165.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,170.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,175.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(20.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,006.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,012.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,018.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,024.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,036.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,042.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,048.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,054.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,066.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,072.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,078.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,084.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,096.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,102.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,108.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,114.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,126.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,132.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,138.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,144.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,156.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,162.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,168.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,174.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(30.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,006.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,013.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,019.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,026.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,032.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,039.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,051.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,058.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,064.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,071.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,077.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,084.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,096.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,103.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,109.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,116.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,122.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,129.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,141.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,148.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,154.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,161.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,167.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,174.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(40.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,008.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,016.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,024.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,032.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,040.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,048.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,056.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,064.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,072.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,080.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,088.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,096.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,104.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,112.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,128.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,136.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,144.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,152.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,160.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,168.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(50.0f,176.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,010.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,020.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,040.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,050.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,070.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,080.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,100.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,110.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,130.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,140.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,160.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,170.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(60.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(70.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(70.0f,015.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(70.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(70.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(70.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(70.0f,075.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(70.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(70.0f,105.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(70.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(70.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(70.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(70.0f,165.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(70.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(80.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(80.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(80.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(80.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(80.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(80.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(80.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2(90.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,005.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,010.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,015.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,020.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,025.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,035.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,040.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,050.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,055.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,065.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,070.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,075.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,080.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,085.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,095.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,100.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,105.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,110.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,115.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,125.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,130.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,140.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,145.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,155.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,160.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,165.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,170.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,175.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-10.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,005.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,010.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,015.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,020.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,025.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,035.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,040.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,050.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,055.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,065.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,070.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,075.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,080.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,085.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,095.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,100.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,105.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,110.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,115.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,125.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,130.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,140.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,145.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,155.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,160.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,165.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,170.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,175.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-20.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,006.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,012.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,018.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,024.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,036.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,042.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,048.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,054.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,066.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,072.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,078.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,084.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,096.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,102.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,108.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,114.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,126.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,132.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,138.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,144.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,156.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,162.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,168.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,174.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-30.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,006.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,013.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,019.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,026.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,032.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,039.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,051.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,058.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,064.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,071.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,077.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,084.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,096.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,103.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,109.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,116.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,122.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,129.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,141.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,148.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,154.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,161.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,167.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,174.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(-40.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,005.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,010.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,015.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,020.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,025.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,035.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,040.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,050.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,055.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,065.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,070.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,075.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,080.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,085.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,095.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,100.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,105.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,110.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,115.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,125.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,130.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,140.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,145.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,155.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,160.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,165.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,170.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,175.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(0.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,005.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,010.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,015.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,020.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,025.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,035.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,040.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,050.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,055.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,065.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,070.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,075.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,080.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,085.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,095.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,100.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,105.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,110.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,115.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,125.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,130.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,140.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,145.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,155.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,160.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,165.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,170.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,175.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(10.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,005.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,010.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,015.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,020.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,025.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,035.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,040.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,050.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,055.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,065.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,070.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,075.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,080.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,085.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,095.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,100.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,105.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,110.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,115.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,125.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,130.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,140.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,145.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,155.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,160.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,165.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,170.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,175.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(20.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,006.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,012.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,018.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,024.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,036.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,042.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,048.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,054.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,066.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,072.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,078.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,084.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,096.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,102.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,108.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,114.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,126.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,132.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,138.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,144.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,156.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,162.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,168.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,174.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(30.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,006.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,013.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,019.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,026.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,032.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,039.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,051.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,058.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,064.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,071.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,077.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,084.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,096.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,103.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,109.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,116.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,122.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,129.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,141.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,148.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,154.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,161.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,167.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,174.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(40.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,008.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,016.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,024.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,032.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,040.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,048.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,056.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,064.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,072.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,080.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,088.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,096.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,104.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,112.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,128.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,136.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,144.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,152.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,160.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,168.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(50.0f,176.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,010.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,020.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,040.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,050.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,070.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,080.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,100.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,110.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,130.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,140.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,160.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,170.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(60.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(70.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(70.0f,015.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(70.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(70.0f,045.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(70.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(70.0f,075.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(70.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(70.0f,105.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(70.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(70.0f,135.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(70.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(70.0f,165.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(70.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(80.0f,000.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(80.0f,030.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(80.0f,060.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(80.0f,090.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(80.0f,120.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(80.0f,150.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(80.0f,180.0f));
|
||||
m_hrtf_sample_locations.push_back(Vector2::Create(90.0f,000.0f));
|
||||
|
||||
if(m_hrtf_data) {
|
||||
delete m_hrtf_data;
|
||||
@@ -1204,9 +1204,9 @@ void KRAudioManager::makeCurrentContext()
|
||||
void KRAudioManager::setListenerOrientationFromModelMatrix(const Matrix4 &modelMatrix)
|
||||
{
|
||||
setListenerOrientation(
|
||||
Matrix4::Dot(modelMatrix, Vector3(0.0, 0.0, 0.0)),
|
||||
Vector3::Normalize(Matrix4::Dot(modelMatrix, Vector3(0.0, 0.0, -1.0)) - m_listener_position),
|
||||
Vector3::Normalize(Matrix4::Dot(modelMatrix, Vector3(0.0, 1.0, 0.0)) - m_listener_position)
|
||||
Matrix4::Dot(modelMatrix, Vector3::Create(0.0, 0.0, 0.0)),
|
||||
Vector3::Normalize(Matrix4::Dot(modelMatrix, Vector3::Create(0.0, 0.0, -1.0)) - m_listener_position),
|
||||
Vector3::Normalize(Matrix4::Dot(modelMatrix, Vector3::Create(0.0, 1.0, 0.0)) - m_listener_position)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1458,7 +1458,7 @@ void KRAudioManager::startFrame(float deltaTime)
|
||||
|
||||
if(gain > 0.0f) {
|
||||
|
||||
Vector3 source_listener_space = Vector3(
|
||||
Vector3 source_listener_space = Vector3::Create(
|
||||
Vector3::Dot(listener_right, diff),
|
||||
Vector3::Dot(m_listener_up, diff),
|
||||
Vector3::Dot(m_listener_forward, diff)
|
||||
@@ -1476,11 +1476,11 @@ void KRAudioManager::startFrame(float deltaTime)
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 source_dir2 = Vector2::Normalize(Vector2(source_dir.x, source_dir.z));
|
||||
Vector2 source_dir2 = Vector2::Normalize(Vector2::Create(source_dir.x, source_dir.z));
|
||||
float azimuth = -atan2(source_dir2.x, -source_dir2.y);
|
||||
float elevation = atan( source_dir.y / sqrt(source_dir.x * source_dir.x + source_dir.z * source_dir.z));
|
||||
|
||||
Vector2 adjusted_source_dir = Vector2(elevation, azimuth);
|
||||
Vector2 adjusted_source_dir = Vector2::Create(elevation, azimuth);
|
||||
|
||||
if(!m_high_quality_hrtf) {
|
||||
adjusted_source_dir = getNearestHRTFSample(adjusted_source_dir);
|
||||
|
||||
@@ -36,7 +36,7 @@ void KRBone::loadXML(tinyxml2::XMLElement *e)
|
||||
}
|
||||
|
||||
AABB KRBone::getBounds() {
|
||||
return AABB(-Vector3::One(), Vector3::One(), getModelMatrix()); // Only required for bone debug visualization
|
||||
return AABB::Create(-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)
|
||||
|
||||
@@ -113,7 +113,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend
|
||||
|
||||
//Matrix4 viewMatrix = Matrix4::Invert(getModelMatrix());
|
||||
|
||||
settings.setViewportSize(Vector2(m_backingWidth, m_backingHeight));
|
||||
settings.setViewportSize(Vector2::Create(m_backingWidth, m_backingHeight));
|
||||
Matrix4 projectionMatrix;
|
||||
projectionMatrix.perspective(settings.perspective_fov, settings.m_viewportSize.x / settings.m_viewportSize.y, settings.perspective_nearz, settings.perspective_farz);
|
||||
m_viewport = KRViewport(settings.getViewportSize(), viewMatrix, projectionMatrix);
|
||||
@@ -419,7 +419,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend
|
||||
|
||||
GL_PUSH_GROUP_MARKER("Volumetric Lighting");
|
||||
|
||||
KRViewport volumetricLightingViewport = KRViewport(Vector2(volumetricBufferWidth, volumetricBufferHeight), m_viewport.getViewMatrix(), m_viewport.getProjectionMatrix());
|
||||
KRViewport volumetricLightingViewport = KRViewport(Vector2::Create(volumetricBufferWidth, volumetricBufferHeight), m_viewport.getViewMatrix(), m_viewport.getProjectionMatrix());
|
||||
|
||||
if(settings.volumetric_environment_downsample != 0) {
|
||||
// Set render target
|
||||
@@ -790,9 +790,9 @@ void KRCamera::renderPost()
|
||||
DebugTextVertexData *vertex_data = (DebugTextVertexData *)m_debug_text_vertices.getStart();
|
||||
|
||||
pChar = szText;
|
||||
float dScaleX = 2.0 / (1024 / 16);
|
||||
float dScaleY = 2.0 / (768 / 16);
|
||||
float dTexScale = 1.0 / 16.0;
|
||||
float dScaleX = 2.0f / (1024f / 16f);
|
||||
float dScaleY = 2.0f / (768f / 16f);
|
||||
float dTexScale = 1.0f / 16.0f;
|
||||
int iRow = row_count - 1; iCol = 0; iTab = 0;
|
||||
while(*pChar) {
|
||||
char c = *pChar++;
|
||||
@@ -808,12 +808,12 @@ void KRCamera::renderPost()
|
||||
int iTexCol = iChar % 16;
|
||||
int iTexRow = 15 - (iChar - iTexCol) / 16;
|
||||
|
||||
Vector2 top_left_pos = Vector2(-1.0f + dScaleX * iCol, dScaleY * iRow - 1.0);
|
||||
Vector2 bottom_right_pos = Vector2(-1.0 + dScaleX * (iCol + 1), dScaleY * iRow + dScaleY - 1.0);
|
||||
top_left_pos += Vector2(1.0f / 2048.0f * 0.5f, 1.0f / 1536.0f * 0.5f);
|
||||
bottom_right_pos += Vector2(1.0f / 2048.0f * 0.5f, 1.0f / 1536.0f * 0.5f);
|
||||
Vector2 top_left_uv = Vector2(dTexScale * iTexCol, dTexScale * iTexRow);
|
||||
Vector2 bottom_right_uv = Vector2(dTexScale * iTexCol + dTexScale, dTexScale * iTexRow + dTexScale);
|
||||
Vector2 top_left_pos = Vector2::Create(-1.0f + dScaleX * iCol, dScaleY * iRow - 1.0f);
|
||||
Vector2 bottom_right_pos = Vector2::Create(-1.0 + dScaleX * (iCol + 1), dScaleY * iRow + dScaleY - 1.0f);
|
||||
top_left_pos += Vector2::Create(1.0f / 2048.0f * 0.5f, 1.0f / 1536.0f * 0.5f);
|
||||
bottom_right_pos += Vector2::Create(1.0f / 2048.0f * 0.5f, 1.0f / 1536.0f * 0.5f);
|
||||
Vector2 top_left_uv = Vector2::Create(dTexScale * iTexCol, dTexScale * iTexRow);
|
||||
Vector2 bottom_right_uv = Vector2::Create(dTexScale * iTexCol + dTexScale, dTexScale * iTexRow + dTexScale);
|
||||
|
||||
vertex_data[vertex_count].x = top_left_pos.x;
|
||||
vertex_data[vertex_count].y = top_left_pos.y;
|
||||
@@ -1109,7 +1109,7 @@ Vector2 KRCamera::getDownsample()
|
||||
|
||||
void KRCamera::setDownsample(float v)
|
||||
{
|
||||
m_downsample = v;
|
||||
m_downsample = Vector2::Create(v);
|
||||
}
|
||||
|
||||
void KRCamera::setFadeColor(const Vector4 &fade_color)
|
||||
|
||||
@@ -86,7 +86,7 @@ void KRCollider::loadModel() {
|
||||
AABB KRCollider::getBounds() {
|
||||
loadModel();
|
||||
if(m_models.size() > 0) {
|
||||
return AABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
|
||||
return AABB::Create(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
|
||||
} else {
|
||||
return AABB::Infinite();
|
||||
}
|
||||
@@ -147,9 +147,9 @@ 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()) {
|
||||
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)
|
||||
AABB sphereCastBounds = AABB::Create( // TODO - Need to cache this; perhaps encasulate within a "spherecast" class to be passed through these functions
|
||||
Vector3::Create(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius),
|
||||
Vector3::Create(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius)
|
||||
);
|
||||
|
||||
if(getBounds().intersects(sphereCastBounds)) {
|
||||
|
||||
@@ -54,7 +54,7 @@ void FFTWorkspace::create(size_t length)
|
||||
cos_table = new float[size];
|
||||
sin_table = new float[size];
|
||||
for (int i = 0; i < size / 2; i++) {
|
||||
float a = 2 * M_PI * i / length;
|
||||
float a = 2.0f * M_PI * i / length;
|
||||
cos_table[i] = cos(a);
|
||||
sin_table[i] = sin(a);
|
||||
}
|
||||
|
||||
@@ -52,13 +52,13 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
|
||||
float max_depth = 1.0f;
|
||||
*/
|
||||
|
||||
AABB worldSpacefrustrumSliceBounds = AABB(Vector3(-1.0f, -1.0f, -1.0f), Vector3(1.0f, 1.0f, 1.0f), Matrix4::Invert(viewport.getViewProjectionMatrix()));
|
||||
AABB worldSpacefrustrumSliceBounds = AABB::Create(Vector3::Create(-1.0f, -1.0f, -1.0f), Vector3::Create(1.0f, 1.0f, 1.0f), Matrix4::Invert(viewport.getViewProjectionMatrix()));
|
||||
worldSpacefrustrumSliceBounds.scale(KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE);
|
||||
|
||||
Vector3 shadowLook = -Vector3::Normalize(getWorldLightDirection());
|
||||
|
||||
Vector3 shadowUp(0.0, 1.0, 0.0);
|
||||
if(Vector3::Dot(shadowUp, shadowLook) > 0.99f) shadowUp = Vector3(0.0, 0.0, 1.0); // Ensure shadow look direction is not parallel with the shadowUp direction
|
||||
Vector3 shadowUp = Vector3::Create(0.0, 1.0, 0.0);
|
||||
if(Vector3::Dot(shadowUp, shadowLook) > 0.99f) shadowUp = Vector3::Create(0.0, 0.0, 1.0); // Ensure shadow look direction is not parallel with the shadowUp direction
|
||||
|
||||
// Matrix4 matShadowView = Matrix4::LookAt(viewport.getCameraPosition() - shadowLook, viewport.getCameraPosition(), shadowUp);
|
||||
// Matrix4 matShadowProjection = Matrix4();
|
||||
@@ -66,8 +66,8 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
|
||||
|
||||
Matrix4 matShadowView = Matrix4::LookAt(worldSpacefrustrumSliceBounds.center() - shadowLook, worldSpacefrustrumSliceBounds.center(), shadowUp);
|
||||
Matrix4 matShadowProjection = Matrix4();
|
||||
AABB shadowSpaceFrustrumSliceBounds = AABB(worldSpacefrustrumSliceBounds.min, worldSpacefrustrumSliceBounds.max, Matrix4::Invert(matShadowProjection));
|
||||
AABB shadowSpaceSceneBounds = AABB(getScene().getRootOctreeBounds().min, getScene().getRootOctreeBounds().max, Matrix4::Invert(matShadowProjection));
|
||||
AABB shadowSpaceFrustrumSliceBounds = AABB::Create(worldSpacefrustrumSliceBounds.min, worldSpacefrustrumSliceBounds.max, Matrix4::Invert(matShadowProjection));
|
||||
AABB shadowSpaceSceneBounds = AABB::Create(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);
|
||||
|
||||
@@ -75,9 +75,9 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
|
||||
matBias.bias();
|
||||
matShadowProjection *= matBias;
|
||||
|
||||
KRViewport newShadowViewport = KRViewport(Vector2(KRENGINE_SHADOW_MAP_WIDTH, KRENGINE_SHADOW_MAP_HEIGHT), matShadowView, matShadowProjection);
|
||||
AABB prevShadowBounds = AABB(-Vector3::One(), Vector3::One(), Matrix4::Invert(m_shadowViewports[iShadow].getViewProjectionMatrix()));
|
||||
AABB minimumShadowBounds = AABB(-Vector3::One(), Vector3::One(), Matrix4::Invert(newShadowViewport.getViewProjectionMatrix()));
|
||||
KRViewport newShadowViewport = KRViewport(Vector2::Create(KRENGINE_SHADOW_MAP_WIDTH, KRENGINE_SHADOW_MAP_HEIGHT), matShadowView, matShadowProjection);
|
||||
AABB prevShadowBounds = AABB::Create(-Vector3::One(), Vector3::One(), Matrix4::Invert(m_shadowViewports[iShadow].getViewProjectionMatrix()));
|
||||
AABB minimumShadowBounds = AABB::Create(-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;
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include "KRHelpers.h"
|
||||
using namespace kraken;
|
||||
|
||||
#include "hydra.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
#ifndef KRHELPERS_H
|
||||
#define KRHELPERS_H
|
||||
|
||||
#include "vector2.h"
|
||||
#include "vector3.h"
|
||||
#include "matrix4.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include <glad/glad.h>
|
||||
#elif defined(__linux__) || defined(__unix__) || defined(__posix__)
|
||||
|
||||
@@ -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 = AABB(Vector3::Zero(), Vector3::Zero());
|
||||
m_reference = AABB::Create(Vector3::Zero(), Vector3::Zero());
|
||||
m_use_world_units = true;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ void KRLODGroup::loadXML(tinyxml2::XMLElement *e)
|
||||
z = 0.0f;
|
||||
}
|
||||
|
||||
m_reference.min = Vector3(x,y,z);
|
||||
m_reference.min = Vector3::Create(x,y,z);
|
||||
|
||||
x=0.0f; y=0.0f; z=0.0f;
|
||||
if(e->QueryFloatAttribute("reference_max_x", &x) != tinyxml2::XML_SUCCESS) {
|
||||
@@ -83,7 +83,7 @@ void KRLODGroup::loadXML(tinyxml2::XMLElement *e)
|
||||
if(e->QueryFloatAttribute("reference_max_z", &z) != tinyxml2::XML_SUCCESS) {
|
||||
z = 0.0f;
|
||||
}
|
||||
m_reference.max = Vector3(x,y,z);
|
||||
m_reference.max = Vector3::Create(x,y,z);
|
||||
|
||||
m_use_world_units = true;
|
||||
if(e->QueryBoolAttribute("use_world_units", &m_use_world_units) != tinyxml2::XML_SUCCESS) {
|
||||
|
||||
@@ -29,8 +29,8 @@ KRLight::KRLight(KRScene &scene, std::string name) : KRNode(scene, name)
|
||||
m_color = Vector3::One();
|
||||
m_flareTexture = "";
|
||||
m_pFlareTexture = NULL;
|
||||
m_flareSize = 0.0;
|
||||
m_flareOcclusionSize = 0.05;
|
||||
m_flareSize = 0.0f;
|
||||
m_flareOcclusionSize = 0.05f;
|
||||
m_casts_shadow = true;
|
||||
m_light_shafts = true;
|
||||
m_dust_particle_density = 0.1f;
|
||||
@@ -86,7 +86,7 @@ void KRLight::loadXML(tinyxml2::XMLElement *e) {
|
||||
if(e->QueryFloatAttribute("color_b", &z) != tinyxml2::XML_SUCCESS) {
|
||||
z = 1.0;
|
||||
}
|
||||
m_color = Vector3(x,y,z);
|
||||
m_color = Vector3::Create(x,y,z);
|
||||
|
||||
if(e->QueryFloatAttribute("intensity", &m_intensity) != tinyxml2::XML_SUCCESS) {
|
||||
m_intensity = 100.0;
|
||||
@@ -101,7 +101,7 @@ void KRLight::loadXML(tinyxml2::XMLElement *e) {
|
||||
}
|
||||
|
||||
if(e->QueryFloatAttribute("flare_occlusion_size", &m_flareOcclusionSize) != tinyxml2::XML_SUCCESS) {
|
||||
m_flareOcclusionSize = 0.05;
|
||||
m_flareOcclusionSize = 0.05f;
|
||||
}
|
||||
|
||||
if(e->QueryBoolAttribute("casts_shadow", &m_casts_shadow) != tinyxml2::XML_SUCCESS) {
|
||||
@@ -263,7 +263,7 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_light
|
||||
float slice_far = -pCamera->settings.volumetric_environment_max_distance;
|
||||
float slice_spacing = (slice_far - slice_near) / slice_count;
|
||||
|
||||
pFogShader->setUniform(KRShader::KRENGINE_UNIFORM_SLICE_DEPTH_SCALE, Vector2(slice_near, slice_spacing));
|
||||
pFogShader->setUniform(KRShader::KRENGINE_UNIFORM_SLICE_DEPTH_SCALE, Vector2::Create(slice_near, slice_spacing));
|
||||
pFogShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, (m_color * pCamera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 1000.0f));
|
||||
|
||||
KRDataBlock index_data;
|
||||
|
||||
@@ -56,14 +56,14 @@ KRMaterial::KRMaterial(KRContext &context, const char *szName) : KRResource(cont
|
||||
m_normalMap = "";
|
||||
m_reflectionMap = "";
|
||||
m_reflectionCube = "";
|
||||
m_ambientMapOffset = Vector2(0.0f, 0.0f);
|
||||
m_specularMapOffset = Vector2(0.0f, 0.0f);
|
||||
m_diffuseMapOffset = Vector2(0.0f, 0.0f);
|
||||
m_ambientMapScale = Vector2(1.0f, 1.0f);
|
||||
m_specularMapScale = Vector2(1.0f, 1.0f);
|
||||
m_diffuseMapScale = Vector2(1.0f, 1.0f);
|
||||
m_reflectionMapOffset = Vector2(0.0f, 0.0f);
|
||||
m_reflectionMapScale = Vector2(1.0f, 1.0f);
|
||||
m_ambientMapOffset = Vector2::Create(0.0f, 0.0f);
|
||||
m_specularMapOffset = Vector2::Create(0.0f, 0.0f);
|
||||
m_diffuseMapOffset = Vector2::Create(0.0f, 0.0f);
|
||||
m_ambientMapScale = Vector2::Create(1.0f, 1.0f);
|
||||
m_specularMapScale = Vector2::Create(1.0f, 1.0f);
|
||||
m_diffuseMapScale = Vector2::Create(1.0f, 1.0f);
|
||||
m_reflectionMapOffset = Vector2::Create(0.0f, 0.0f);
|
||||
m_reflectionMapScale = Vector2::Create(1.0f, 1.0f);
|
||||
m_alpha_mode = KRMATERIAL_ALPHA_MODE_OPAQUE;
|
||||
}
|
||||
|
||||
@@ -365,14 +365,14 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_ligh
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
|
||||
// We pre-multiply the light color with the material color in the forward renderer
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, Vector3(m_diffuseColor.x * pCamera->settings.light_intensity.x, m_diffuseColor.y * pCamera->settings.light_intensity.y, m_diffuseColor.z * pCamera->settings.light_intensity.z));
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, Vector3::Create(m_diffuseColor.x * pCamera->settings.light_intensity.x, m_diffuseColor.y * pCamera->settings.light_intensity.y, m_diffuseColor.z * pCamera->settings.light_intensity.z));
|
||||
} else {
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, m_diffuseColor);
|
||||
}
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
|
||||
// We pre-multiply the light color with the material color in the forward renderer
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR, Vector3(m_specularColor.x * pCamera->settings.light_intensity.x, m_specularColor.y * pCamera->settings.light_intensity.y, m_specularColor.z * pCamera->settings.light_intensity.z));
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR, Vector3::Create(m_specularColor.x * pCamera->settings.light_intensity.x, m_specularColor.y * pCamera->settings.light_intensity.y, m_specularColor.z * pCamera->settings.light_intensity.z));
|
||||
} else {
|
||||
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR, m_specularColor);
|
||||
}
|
||||
|
||||
@@ -162,49 +162,49 @@ bool KRMaterialManager::load(const char *szName, KRDataBlock *data) {
|
||||
char *pScan2 = szSymbol[1];
|
||||
float r = strtof(pScan2, &pScan2);
|
||||
if(cSymbols == 2) {
|
||||
pMaterial->setAmbient(Vector3(r, r, r));
|
||||
pMaterial->setAmbient(Vector3::Create(r, r, r));
|
||||
} else if(cSymbols == 4) {
|
||||
pScan2 = szSymbol[2];
|
||||
float g = strtof(pScan2, &pScan2);
|
||||
pScan2 = szSymbol[3];
|
||||
float b = strtof(pScan2, &pScan2);
|
||||
pMaterial->setAmbient(Vector3(r, g, b));
|
||||
pMaterial->setAmbient(Vector3::Create(r, g, b));
|
||||
}
|
||||
} else if(strcmp(szSymbol[0], "kd") == 0) {
|
||||
char *pScan2 = szSymbol[1];
|
||||
float r = strtof(pScan2, &pScan2);
|
||||
if(cSymbols == 2) {
|
||||
pMaterial->setDiffuse(Vector3(r, r, r));
|
||||
pMaterial->setDiffuse(Vector3::Create(r, r, r));
|
||||
} else if(cSymbols == 4) {
|
||||
pScan2 = szSymbol[2];
|
||||
float g = strtof(pScan2, &pScan2);
|
||||
pScan2 = szSymbol[3];
|
||||
float b = strtof(pScan2, &pScan2);
|
||||
pMaterial->setDiffuse(Vector3(r, g, b));
|
||||
pMaterial->setDiffuse(Vector3::Create(r, g, b));
|
||||
}
|
||||
} else if(strcmp(szSymbol[0], "ks") == 0) {
|
||||
char *pScan2 = szSymbol[1];
|
||||
float r = strtof(pScan2, &pScan2);
|
||||
if(cSymbols == 2) {
|
||||
pMaterial->setSpecular(Vector3(r, r, r));
|
||||
pMaterial->setSpecular(Vector3::Create(r, r, r));
|
||||
} else if(cSymbols == 4) {
|
||||
pScan2 = szSymbol[2];
|
||||
float g = strtof(pScan2, &pScan2);
|
||||
pScan2 = szSymbol[3];
|
||||
float b = strtof(pScan2, &pScan2);
|
||||
pMaterial->setSpecular(Vector3(r, g, b));
|
||||
pMaterial->setSpecular(Vector3::Create(r, g, b));
|
||||
}
|
||||
} else if(strcmp(szSymbol[0], "kr") == 0) {
|
||||
char *pScan2 = szSymbol[1];
|
||||
float r = strtof(pScan2, &pScan2);
|
||||
if(cSymbols == 2) {
|
||||
pMaterial->setReflection(Vector3(r, r, r));
|
||||
pMaterial->setReflection(Vector3::Create(r, r, r));
|
||||
} else if(cSymbols == 4) {
|
||||
pScan2 = szSymbol[2];
|
||||
float g = strtof(pScan2, &pScan2);
|
||||
pScan2 = szSymbol[3];
|
||||
float b = strtof(pScan2, &pScan2);
|
||||
pMaterial->setReflection(Vector3(r, g, b));
|
||||
pMaterial->setReflection(Vector3::Create(r, g, b));
|
||||
}
|
||||
} else if(strcmp(szSymbol[0], "tr") == 0) {
|
||||
char *pScan2 = szSymbol[1];
|
||||
@@ -228,8 +228,8 @@ bool KRMaterialManager::load(const char *szName, KRDataBlock *data) {
|
||||
*pLastPeriod = '\0';
|
||||
}
|
||||
|
||||
Vector2 texture_scale = Vector2(1.0f, 1.0f);
|
||||
Vector2 texture_offset = Vector2(0.0f, 0.0f);
|
||||
Vector2 texture_scale = Vector2::Create(1.0f, 1.0f);
|
||||
Vector2 texture_offset = Vector2::Create(0.0f, 0.0f);
|
||||
|
||||
int iScanSymbol = 2;
|
||||
int iScaleParam = -1;
|
||||
|
||||
@@ -153,8 +153,8 @@ void KRMesh::loadPack(KRDataBlock *data) {
|
||||
m_pIndexBaseData = m_pData->getSubBlock(sizeof(pack_header) + sizeof(pack_material) * ph.submesh_count + sizeof(pack_bone) * ph.bone_count + KRALIGN(2 * ph.index_count), ph.index_base_count * 8);
|
||||
m_pIndexBaseData->lock();
|
||||
|
||||
m_minPoint = Vector3(ph.minx, ph.miny, ph.minz);
|
||||
m_maxPoint = Vector3(ph.maxx, ph.maxy, ph.maxz);
|
||||
m_minPoint = Vector3::Create(ph.minx, ph.miny, ph.minz);
|
||||
m_maxPoint = Vector3::Create(ph.maxx, ph.maxy, ph.maxz);
|
||||
|
||||
updateAttributeOffsets();
|
||||
}
|
||||
@@ -721,11 +721,11 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool
|
||||
Vector2 uv1 = getVertexUVA(iVertex + 1);
|
||||
Vector2 uv2 = getVertexUVA(iVertex + 2);
|
||||
|
||||
Vector2 st1 = Vector2(uv1.x - uv0.x, uv1.y - uv0.y);
|
||||
Vector2 st2 = Vector2(uv2.x - uv0.x, uv2.y - uv0.y);
|
||||
Vector2 st1 = Vector2::Create(uv1.x - uv0.x, uv1.y - uv0.y);
|
||||
Vector2 st2 = Vector2::Create(uv2.x - uv0.x, uv2.y - uv0.y);
|
||||
double coef = 1/ (st1.x * st2.y - st2.x * st1.y);
|
||||
|
||||
Vector3 tangent(
|
||||
Vector3 tangent = Vector3::Create(
|
||||
coef * ((v1.x * st2.y) + (v2.x * -st1.y)),
|
||||
coef * ((v1.y * st2.y) + (v2.y * -st1.y)),
|
||||
coef * ((v1.z * st2.y) + (v2.z * -st1.y))
|
||||
@@ -855,9 +855,9 @@ Vector3 KRMesh::getVertexPosition(int index) const
|
||||
{
|
||||
if(has_vertex_attribute(KRENGINE_ATTRIB_VERTEX_SHORT)) {
|
||||
short *v = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX_SHORT]);
|
||||
return Vector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f);
|
||||
return Vector3::Create((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f);
|
||||
} else if(has_vertex_attribute(KRENGINE_ATTRIB_VERTEX)) {
|
||||
return Vector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX]));
|
||||
return Vector3::Create((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX]));
|
||||
} else {
|
||||
return Vector3::Zero();
|
||||
}
|
||||
@@ -867,9 +867,9 @@ Vector3 KRMesh::getVertexNormal(int index) const
|
||||
{
|
||||
if(has_vertex_attribute(KRENGINE_ATTRIB_NORMAL_SHORT)) {
|
||||
short *v = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL_SHORT]);
|
||||
return Vector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f);
|
||||
return Vector3::Create((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f);
|
||||
} else if(has_vertex_attribute(KRENGINE_ATTRIB_NORMAL)) {
|
||||
return Vector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL]));
|
||||
return Vector3::Create((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL]));
|
||||
} else {
|
||||
return Vector3::Zero();
|
||||
}
|
||||
@@ -879,9 +879,9 @@ Vector3 KRMesh::getVertexTangent(int index) const
|
||||
{
|
||||
if(has_vertex_attribute(KRENGINE_ATTRIB_TANGENT_SHORT)) {
|
||||
short *v = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT_SHORT]);
|
||||
return Vector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f);
|
||||
return Vector3::Create((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f);
|
||||
} else if(has_vertex_attribute(KRENGINE_ATTRIB_TANGENT)) {
|
||||
return Vector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT]));
|
||||
return Vector3::Create((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT]));
|
||||
} else {
|
||||
return Vector3::Zero();
|
||||
}
|
||||
@@ -891,9 +891,9 @@ Vector2 KRMesh::getVertexUVA(int index) const
|
||||
{
|
||||
if(has_vertex_attribute(KRENGINE_ATTRIB_TEXUVA_SHORT)) {
|
||||
short *v = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TEXUVA_SHORT]);
|
||||
return Vector2((float)v[0] / 32767.0f, (float)v[1] / 32767.0f);
|
||||
return Vector2::Create((float)v[0] / 32767.0f, (float)v[1] / 32767.0f);
|
||||
} else if(has_vertex_attribute(KRENGINE_ATTRIB_TEXUVA)) {
|
||||
return Vector2((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TEXUVA]));
|
||||
return Vector2::Create((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TEXUVA]));
|
||||
} else {
|
||||
return Vector2::Zero();
|
||||
}
|
||||
@@ -903,9 +903,9 @@ Vector2 KRMesh::getVertexUVB(int index) const
|
||||
{
|
||||
if(has_vertex_attribute(KRENGINE_ATTRIB_TEXUVB_SHORT)) {
|
||||
short *v = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TEXUVB_SHORT]);
|
||||
return Vector2((float)v[0] / 32767.0f, (float)v[1] / 32767.0f);
|
||||
return Vector2::Create((float)v[0] / 32767.0f, (float)v[1] / 32767.0f);
|
||||
} else if(has_vertex_attribute(KRENGINE_ATTRIB_TEXUVB)) {
|
||||
return Vector2((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TEXUVB]));
|
||||
return Vector2::Create((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TEXUVB]));
|
||||
} else {
|
||||
return Vector2::Zero();
|
||||
}
|
||||
@@ -1089,7 +1089,7 @@ char *KRMesh::getBoneName(int bone_index)
|
||||
|
||||
Matrix4 KRMesh::getBoneBindPose(int bone_index)
|
||||
{
|
||||
return Matrix4(getBone(bone_index)->bind_pose);
|
||||
return Matrix4::Create(getBone(bone_index)->bind_pose);
|
||||
}
|
||||
|
||||
KRMesh::model_format_t KRMesh::getModelFormat() const
|
||||
@@ -1116,7 +1116,7 @@ bool KRMesh::rayCast(const Vector3 &start, const Vector3 &dir, const Triangle3 &
|
||||
distance_v0 /= distance_total;
|
||||
distance_v1 /= distance_total;
|
||||
distance_v2 /= distance_total;
|
||||
Vector3 normal = Vector3::Normalize(tri_n0 * (1.0 - distance_v0) + tri_n1 * (1.0 - distance_v1) + tri_n2 * (1.0 - distance_v2));
|
||||
Vector3 normal = Vector3::Normalize(tri_n0 * (1.0f - distance_v0) + tri_n1 * (1.0f - distance_v1) + tri_n2 * (1.0f - distance_v2));
|
||||
|
||||
hitinfo = HitInfo(hit_point, normal, new_hit_distance);
|
||||
return true;
|
||||
@@ -1148,7 +1148,7 @@ bool KRMesh::rayCast(const Vector3 &start, const Vector3 &dir, HitInfo &hitinfo)
|
||||
tri_vert_index[1] = getTriangleVertexIndex(submesh_index, triangle_index*3 + 1);
|
||||
tri_vert_index[2] = getTriangleVertexIndex(submesh_index, triangle_index*3 + 2);
|
||||
|
||||
Triangle3 tri = Triangle3(getVertexPosition(tri_vert_index[0]), getVertexPosition(tri_vert_index[1]), getVertexPosition(tri_vert_index[2]));
|
||||
Triangle3 tri = Triangle3::Create(getVertexPosition(tri_vert_index[0]), getVertexPosition(tri_vert_index[1]), getVertexPosition(tri_vert_index[2]));
|
||||
|
||||
if(rayCast(start, dir, tri, getVertexNormal(tri_vert_index[0]), getVertexNormal(tri_vert_index[1]), getVertexNormal(tri_vert_index[2]), hitinfo)) hit_found = true;
|
||||
}
|
||||
@@ -1194,7 +1194,7 @@ bool KRMesh::sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const
|
||||
tri_vert_index[1] = getTriangleVertexIndex(submesh_index, triangle_index*3 + 1);
|
||||
tri_vert_index[2] = getTriangleVertexIndex(submesh_index, triangle_index*3 + 2);
|
||||
|
||||
Triangle3 tri = Triangle3(getVertexPosition(tri_vert_index[0]), getVertexPosition(tri_vert_index[1]), getVertexPosition(tri_vert_index[2]));
|
||||
Triangle3 tri = Triangle3::Create(getVertexPosition(tri_vert_index[0]), getVertexPosition(tri_vert_index[1]), getVertexPosition(tri_vert_index[2]));
|
||||
|
||||
if(sphereCast(model_to_world, v0, v1, radius, tri, hitinfo)) hit_found = true;
|
||||
|
||||
@@ -1239,7 +1239,7 @@ bool KRMesh::sphereCast(const Matrix4 &model_to_world, const Vector3 &v0, const
|
||||
Vector3 new_hit_point;
|
||||
float new_hit_distance;
|
||||
|
||||
Triangle3 world_tri = Triangle3(Matrix4::Dot(model_to_world, tri[0]), Matrix4::Dot(model_to_world, tri[1]), Matrix4::Dot(model_to_world, tri[2]));
|
||||
Triangle3 world_tri = Triangle3::Create(Matrix4::Dot(model_to_world, tri[0]), Matrix4::Dot(model_to_world, tri[1]), Matrix4::Dot(model_to_world, tri[2]));
|
||||
|
||||
if(world_tri.sphereCast(start, dir, radius, new_hit_point, new_hit_distance)) {
|
||||
if((!hitinfo.didHit() || hitinfo.getDistance() > new_hit_distance) && new_hit_distance <= (v1 - v0).magnitude()) {
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include "hydra.h"
|
||||
|
||||
using namespace kraken;
|
||||
|
||||
#define MAX_VBO_SIZE 65535
|
||||
|
||||
@@ -38,20 +38,20 @@ KRMeshCube::KRMeshCube(KRContext &context) : KRMesh(context, "__cube")
|
||||
|
||||
KRMesh::mesh_info mi;
|
||||
|
||||
mi.vertices.push_back(Vector3(1.0, 1.0, 1.0));
|
||||
mi.vertices.push_back(Vector3(-1.0, 1.0, 1.0));
|
||||
mi.vertices.push_back(Vector3(1.0,-1.0, 1.0));
|
||||
mi.vertices.push_back(Vector3(-1.0,-1.0, 1.0));
|
||||
mi.vertices.push_back(Vector3(-1.0,-1.0,-1.0));
|
||||
mi.vertices.push_back(Vector3(-1.0, 1.0, 1.0));
|
||||
mi.vertices.push_back(Vector3(-1.0, 1.0,-1.0));
|
||||
mi.vertices.push_back(Vector3(1.0, 1.0, 1.0));
|
||||
mi.vertices.push_back(Vector3(1.0, 1.0,-1.0));
|
||||
mi.vertices.push_back(Vector3(1.0,-1.0, 1.0));
|
||||
mi.vertices.push_back(Vector3(1.0,-1.0,-1.0));
|
||||
mi.vertices.push_back(Vector3(-1.0,-1.0,-1.0));
|
||||
mi.vertices.push_back(Vector3(1.0, 1.0,-1.0));
|
||||
mi.vertices.push_back(Vector3(-1.0, 1.0,-1.0));
|
||||
mi.vertices.push_back(Vector3::Create(1.0, 1.0, 1.0));
|
||||
mi.vertices.push_back(Vector3::Create(-1.0, 1.0, 1.0));
|
||||
mi.vertices.push_back(Vector3::Create(1.0,-1.0, 1.0));
|
||||
mi.vertices.push_back(Vector3::Create(-1.0,-1.0, 1.0));
|
||||
mi.vertices.push_back(Vector3::Create(-1.0,-1.0,-1.0));
|
||||
mi.vertices.push_back(Vector3::Create(-1.0, 1.0, 1.0));
|
||||
mi.vertices.push_back(Vector3::Create(-1.0, 1.0,-1.0));
|
||||
mi.vertices.push_back(Vector3::Create(1.0, 1.0, 1.0));
|
||||
mi.vertices.push_back(Vector3::Create(1.0, 1.0,-1.0));
|
||||
mi.vertices.push_back(Vector3::Create(1.0,-1.0, 1.0));
|
||||
mi.vertices.push_back(Vector3::Create(1.0,-1.0,-1.0));
|
||||
mi.vertices.push_back(Vector3::Create(-1.0,-1.0,-1.0));
|
||||
mi.vertices.push_back(Vector3::Create(1.0, 1.0,-1.0));
|
||||
mi.vertices.push_back(Vector3::Create(-1.0, 1.0,-1.0));
|
||||
|
||||
|
||||
mi.submesh_starts.push_back(0);
|
||||
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
|
||||
// Disable copy constructors
|
||||
KRVBOData(const KRVBOData& o) = delete;
|
||||
KRVBOData(KRVBOData& o) = delete;
|
||||
KRVBOData& operator=(const KRVBOData& o) = delete;
|
||||
|
||||
long getSize() { return m_size; }
|
||||
|
||||
|
||||
@@ -38,15 +38,15 @@ KRMeshQuad::KRMeshQuad(KRContext &context) : KRMesh(context, "__quad")
|
||||
|
||||
KRMesh::mesh_info mi;
|
||||
|
||||
mi.vertices.push_back(Vector3(-1.0f, -1.0f, 0.0f));
|
||||
mi.vertices.push_back(Vector3(1.0f, -1.0f, 0.0f));
|
||||
mi.vertices.push_back(Vector3(-1.0f, 1.0f, 0.0f));
|
||||
mi.vertices.push_back(Vector3(1.0f, 1.0f, 0.0f));
|
||||
mi.vertices.push_back(Vector3::Create(-1.0f, -1.0f, 0.0f));
|
||||
mi.vertices.push_back(Vector3::Create(1.0f, -1.0f, 0.0f));
|
||||
mi.vertices.push_back(Vector3::Create(-1.0f, 1.0f, 0.0f));
|
||||
mi.vertices.push_back(Vector3::Create(1.0f, 1.0f, 0.0f));
|
||||
|
||||
mi.uva.push_back(Vector2(0.0f, 0.0f));
|
||||
mi.uva.push_back(Vector2(1.0f, 0.0f));
|
||||
mi.uva.push_back(Vector2(0.0f, 1.0f));
|
||||
mi.uva.push_back(Vector2(1.0f, 1.0f));
|
||||
mi.uva.push_back(Vector2::Create(0.0f, 0.0f));
|
||||
mi.uva.push_back(Vector2::Create(1.0f, 0.0f));
|
||||
mi.uva.push_back(Vector2::Create(0.0f, 1.0f));
|
||||
mi.uva.push_back(Vector2::Create(1.0f, 1.0f));
|
||||
|
||||
|
||||
mi.submesh_starts.push_back(0);
|
||||
|
||||
@@ -62,12 +62,12 @@ KRMeshSphere::KRMeshSphere(KRContext &context) : KRMesh(context, "__sphere")
|
||||
int i,it;
|
||||
float a;
|
||||
Vector3 p[6] = {
|
||||
Vector3(0,0,1),
|
||||
Vector3(0,0,-1),
|
||||
Vector3(-1,-1,0),
|
||||
Vector3(1,-1,0),
|
||||
Vector3(1,1,0),
|
||||
Vector3(-1,1,0)
|
||||
Vector3::Create(0,0,1),
|
||||
Vector3::Create(0,0,-1),
|
||||
Vector3::Create(-1,-1,0),
|
||||
Vector3::Create(1,-1,0),
|
||||
Vector3::Create(1,1,0),
|
||||
Vector3::Create(-1,1,0)
|
||||
};
|
||||
|
||||
Vector3 pa,pb,pc;
|
||||
|
||||
@@ -200,7 +200,7 @@ void KRModel::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_light
|
||||
if(m_faces_camera) {
|
||||
Vector3 model_center = Matrix4::Dot(matModel, Vector3::Zero());
|
||||
Vector3 camera_pos = viewport.getCameraPosition();
|
||||
matModel = Quaternion(Vector3::Forward(), Vector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel;
|
||||
matModel = Quaternion::Create(Vector3::Forward(), Vector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel;
|
||||
}
|
||||
|
||||
pModel->render(getName(), pCamera, point_lights, directional_lights, spot_lights, viewport, matModel, m_pLightMap, renderPass, m_bones[pModel], m_rim_color, m_rim_power, lod_coverage);
|
||||
@@ -245,14 +245,14 @@ AABB KRModel::getBounds() {
|
||||
loadModel();
|
||||
if(m_models.size() > 0) {
|
||||
if(m_faces_camera) {
|
||||
AABB normal_bounds = AABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
|
||||
AABB normal_bounds = AABB::Create(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
|
||||
float max_dimension = normal_bounds.longest_radius();
|
||||
return AABB(normal_bounds.center()-Vector3(max_dimension), normal_bounds.center() + Vector3(max_dimension));
|
||||
return AABB::Create(normal_bounds.center()-Vector3::Create(max_dimension), normal_bounds.center() + Vector3::Create(max_dimension));
|
||||
} else {
|
||||
|
||||
if(!(m_boundsCachedMat == getModelMatrix())) {
|
||||
m_boundsCachedMat = getModelMatrix();
|
||||
m_boundsCached = AABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
|
||||
m_boundsCached = AABB::Create(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
|
||||
}
|
||||
return m_boundsCached;
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ void KRNode::setWorldTranslation(const Vector3 &v)
|
||||
void KRNode::setWorldRotation(const Vector3 &v)
|
||||
{
|
||||
if(m_parentNode) {
|
||||
setLocalRotation((Quaternion(v) * -m_parentNode->getWorldRotation()).eulerXYZ());
|
||||
setLocalRotation((Quaternion::Create(v) * -m_parentNode->getWorldRotation()).eulerXYZ());
|
||||
setPreRotation(Vector3::Zero());
|
||||
setPostRotation(Vector3::Zero());
|
||||
} else {
|
||||
@@ -702,7 +702,7 @@ const Matrix4 &KRNode::getActivePoseMatrix()
|
||||
}
|
||||
|
||||
const Quaternion KRNode::getWorldRotation() {
|
||||
Quaternion world_rotation = Quaternion(m_postRotation) * Quaternion(m_localRotation) * Quaternion(m_preRotation);
|
||||
Quaternion world_rotation = Quaternion::Create(m_postRotation) * Quaternion::Create(m_localRotation) * Quaternion::Create(m_preRotation);
|
||||
if(m_parentNode) {
|
||||
world_rotation = world_rotation * m_parentNode->getWorldRotation();
|
||||
}
|
||||
@@ -710,7 +710,7 @@ const Quaternion KRNode::getWorldRotation() {
|
||||
}
|
||||
|
||||
const Quaternion KRNode::getBindPoseWorldRotation() {
|
||||
Quaternion world_rotation = Quaternion(m_initialPostRotation) * Quaternion(m_initialLocalRotation) * Quaternion(m_initialPreRotation);
|
||||
Quaternion world_rotation = Quaternion::Create(m_initialPostRotation) * Quaternion::Create(m_initialLocalRotation) * Quaternion::Create(m_initialPreRotation);
|
||||
if(dynamic_cast<KRBone *>(m_parentNode)) {
|
||||
world_rotation = world_rotation * m_parentNode->getBindPoseWorldRotation();
|
||||
}
|
||||
@@ -718,7 +718,7 @@ const Quaternion KRNode::getBindPoseWorldRotation() {
|
||||
}
|
||||
|
||||
const Quaternion KRNode::getActivePoseWorldRotation() {
|
||||
Quaternion world_rotation = Quaternion(m_postRotation) * Quaternion(m_localRotation) * Quaternion(m_preRotation);
|
||||
Quaternion world_rotation = Quaternion::Create(m_postRotation) * Quaternion::Create(m_localRotation) * Quaternion::Create(m_preRotation);
|
||||
if(dynamic_cast<KRBone *>(m_parentNode)) {
|
||||
world_rotation = world_rotation * m_parentNode->getActivePoseWorldRotation();
|
||||
}
|
||||
@@ -768,87 +768,87 @@ void KRNode::SetAttribute(node_attribute_type attrib, float v)
|
||||
//printf("%s - ", m_name.c_str());
|
||||
switch(attrib) {
|
||||
case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_X:
|
||||
setLocalTranslation(Vector3(v, m_localTranslation.y, m_localTranslation.z));
|
||||
setLocalTranslation(Vector3::Create(v, m_localTranslation.y, m_localTranslation.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_Y:
|
||||
setLocalTranslation(Vector3(m_localTranslation.x, v, m_localTranslation.z));
|
||||
setLocalTranslation(Vector3::Create(m_localTranslation.x, v, m_localTranslation.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_Z:
|
||||
setLocalTranslation(Vector3(m_localTranslation.x, m_localTranslation.y, v));
|
||||
setLocalTranslation(Vector3::Create(m_localTranslation.x, m_localTranslation.y, v));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_SCALE_X:
|
||||
setLocalScale(Vector3(v, m_localScale.y, m_localScale.z));
|
||||
setLocalScale(Vector3::Create(v, m_localScale.y, m_localScale.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_SCALE_Y:
|
||||
setLocalScale(Vector3(m_localScale.x, v, m_localScale.z));
|
||||
setLocalScale(Vector3::Create(m_localScale.x, v, m_localScale.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_SCALE_Z:
|
||||
setLocalScale(Vector3(m_localScale.x, m_localScale.y, v));
|
||||
setLocalScale(Vector3::Create(m_localScale.x, m_localScale.y, v));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_ROTATE_X:
|
||||
setLocalRotation(Vector3(v * DEGREES_TO_RAD, m_localRotation.y, m_localRotation.z));
|
||||
setLocalRotation(Vector3::Create(v * DEGREES_TO_RAD, m_localRotation.y, m_localRotation.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_ROTATE_Y:
|
||||
setLocalRotation(Vector3(m_localRotation.x, v * DEGREES_TO_RAD, m_localRotation.z));
|
||||
setLocalRotation(Vector3::Create(m_localRotation.x, v * DEGREES_TO_RAD, m_localRotation.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_ROTATE_Z:
|
||||
setLocalRotation(Vector3(m_localRotation.x, m_localRotation.y, v * DEGREES_TO_RAD));
|
||||
setLocalRotation(Vector3::Create(m_localRotation.x, m_localRotation.y, v * DEGREES_TO_RAD));
|
||||
break;
|
||||
|
||||
|
||||
case KRENGINE_NODE_ATTRIBUTE_PRE_ROTATION_X:
|
||||
setPreRotation(Vector3(v * DEGREES_TO_RAD, m_preRotation.y, m_preRotation.z));
|
||||
setPreRotation(Vector3::Create(v * DEGREES_TO_RAD, m_preRotation.y, m_preRotation.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_PRE_ROTATION_Y:
|
||||
setPreRotation(Vector3(m_preRotation.x, v * DEGREES_TO_RAD, m_preRotation.z));
|
||||
setPreRotation(Vector3::Create(m_preRotation.x, v * DEGREES_TO_RAD, m_preRotation.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_PRE_ROTATION_Z:
|
||||
setPreRotation(Vector3(m_preRotation.x, m_preRotation.y, v * DEGREES_TO_RAD));
|
||||
setPreRotation(Vector3::Create(m_preRotation.x, m_preRotation.y, v * DEGREES_TO_RAD));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_POST_ROTATION_X:
|
||||
setPostRotation(Vector3(v * DEGREES_TO_RAD, m_postRotation.y, m_postRotation.z));
|
||||
setPostRotation(Vector3::Create(v * DEGREES_TO_RAD, m_postRotation.y, m_postRotation.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_POST_ROTATION_Y:
|
||||
setPostRotation(Vector3(m_postRotation.x, v * DEGREES_TO_RAD, m_postRotation.z));
|
||||
setPostRotation(Vector3::Create(m_postRotation.x, v * DEGREES_TO_RAD, m_postRotation.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_POST_ROTATION_Z:
|
||||
setPostRotation(Vector3(m_postRotation.x, m_postRotation.y, v * DEGREES_TO_RAD));
|
||||
setPostRotation(Vector3::Create(m_postRotation.x, m_postRotation.y, v * DEGREES_TO_RAD));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_ROTATION_PIVOT_X:
|
||||
setRotationPivot(Vector3(v, m_rotationPivot.y, m_rotationPivot.z));
|
||||
setRotationPivot(Vector3::Create(v, m_rotationPivot.y, m_rotationPivot.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_ROTATION_PIVOT_Y:
|
||||
setRotationPivot(Vector3(m_rotationPivot.x, v, m_rotationPivot.z));
|
||||
setRotationPivot(Vector3::Create(m_rotationPivot.x, v, m_rotationPivot.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_ROTATION_PIVOT_Z:
|
||||
setRotationPivot(Vector3(m_rotationPivot.x, m_rotationPivot.y, v));
|
||||
setRotationPivot(Vector3::Create(m_rotationPivot.x, m_rotationPivot.y, v));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_SCALE_PIVOT_X:
|
||||
setScalingPivot(Vector3(v, m_scalingPivot.y, m_scalingPivot.z));
|
||||
setScalingPivot(Vector3::Create(v, m_scalingPivot.y, m_scalingPivot.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_SCALE_PIVOT_Y:
|
||||
setScalingPivot(Vector3(m_scalingPivot.x, v, m_scalingPivot.z));
|
||||
setScalingPivot(Vector3::Create(m_scalingPivot.x, v, m_scalingPivot.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_SCALE_PIVOT_Z:
|
||||
setScalingPivot(Vector3(m_scalingPivot.x, m_scalingPivot.y, v));
|
||||
setScalingPivot(Vector3::Create(m_scalingPivot.x, m_scalingPivot.y, v));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_ROTATE_OFFSET_X:
|
||||
setRotationOffset(Vector3(v, m_rotationOffset.y, m_rotationOffset.z));
|
||||
setRotationOffset(Vector3::Create(v, m_rotationOffset.y, m_rotationOffset.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_ROTATE_OFFSET_Y:
|
||||
setRotationOffset(Vector3(m_rotationOffset.x, v, m_rotationOffset.z));
|
||||
setRotationOffset(Vector3::Create(m_rotationOffset.x, v, m_rotationOffset.z));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_ROTATE_OFFSET_Z:
|
||||
setRotationOffset(Vector3(m_rotationOffset.x, m_rotationOffset.y, v));
|
||||
setRotationOffset(Vector3::Create(m_rotationOffset.x, m_rotationOffset.y, v));
|
||||
break;
|
||||
case KRENGINE_NODE_SCALE_OFFSET_X:
|
||||
setScalingOffset(Vector3(v, m_scalingOffset.y, m_scalingOffset.z));
|
||||
setScalingOffset(Vector3::Create(v, m_scalingOffset.y, m_scalingOffset.z));
|
||||
break;
|
||||
case KRENGINE_NODE_SCALE_OFFSET_Y:
|
||||
setScalingOffset(Vector3(m_scalingOffset.x, v, m_scalingOffset.z));
|
||||
setScalingOffset(Vector3::Create(m_scalingOffset.x, v, m_scalingOffset.z));
|
||||
break;
|
||||
case KRENGINE_NODE_SCALE_OFFSET_Z:
|
||||
setScalingOffset(Vector3(m_scalingOffset.x, m_scalingOffset.y, v));
|
||||
setScalingOffset(Vector3::Create(m_scalingOffset.x, m_scalingOffset.y, v));
|
||||
break;
|
||||
case KRENGINE_NODE_ATTRIBUTE_NONE:
|
||||
case KRENGINE_NODE_ATTRIBUTE_COUNT:
|
||||
|
||||
@@ -43,9 +43,9 @@ void KROctree::add(KRNode *pNode)
|
||||
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, AABB(rootBounds.min - rootSize, rootBounds.max), 7, m_pRootNode);
|
||||
m_pRootNode = new KROctreeNode(NULL, AABB::Create(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, AABB(rootBounds.min, rootBounds.max + rootSize), 0, m_pRootNode);
|
||||
m_pRootNode = new KROctreeNode(NULL, AABB::Create(rootBounds.min, rootBounds.max + rootSize), 0, m_pRootNode);
|
||||
} else {
|
||||
bInsideRoot = true;
|
||||
}
|
||||
|
||||
@@ -99,12 +99,12 @@ AABB KROctreeNode::getChildBounds(int iChild)
|
||||
{
|
||||
Vector3 center = m_bounds.center();
|
||||
|
||||
return AABB(
|
||||
Vector3(
|
||||
return AABB::Create(
|
||||
Vector3::Create(
|
||||
(iChild & 1) == 0 ? m_bounds.min.x : center.x,
|
||||
(iChild & 2) == 0 ? m_bounds.min.y : center.y,
|
||||
(iChild & 4) == 0 ? m_bounds.min.z : center.z),
|
||||
Vector3(
|
||||
Vector3::Create(
|
||||
(iChild & 1) == 0 ? center.x : m_bounds.max.x,
|
||||
(iChild & 2) == 0 ? center.y : m_bounds.max.y,
|
||||
(iChild & 4) == 0 ? center.z : m_bounds.max.z)
|
||||
@@ -264,7 +264,7 @@ bool KROctreeNode::sphereCast(const Vector3 &v0, const Vector3 &v1, float radius
|
||||
} else {
|
||||
*/
|
||||
|
||||
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));
|
||||
AABB swept_bounds = AABB::Create(Vector3::Create(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius), Vector3::Create(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)) {
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#define KROCTREENODE_H
|
||||
|
||||
#include "KREngine-common.h"
|
||||
#include "public/hitinfo.h"
|
||||
#include "hitinfo.h"
|
||||
|
||||
class KRNode;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ AABB KRPointLight::getBounds() {
|
||||
if(influence_radius < m_flareOcclusionSize) {
|
||||
influence_radius = m_flareOcclusionSize;
|
||||
}
|
||||
return AABB(Vector3(-influence_radius), Vector3(influence_radius), getModelMatrix());
|
||||
return AABB::Create(Vector3::Create(-influence_radius), Vector3::Create(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)
|
||||
@@ -156,19 +156,19 @@ void KRPointLight::generateMesh() {
|
||||
int i,it;
|
||||
float a;
|
||||
Vector3 p[6] = {
|
||||
Vector3(0,0,1),
|
||||
Vector3(0,0,-1),
|
||||
Vector3(-1,-1,0),
|
||||
Vector3(1,-1,0),
|
||||
Vector3(1,1,0),
|
||||
Vector3(-1,1,0)
|
||||
Vector3::Create(0,0,1),
|
||||
Vector3::Create(0,0,-1),
|
||||
Vector3::Create(-1,-1,0),
|
||||
Vector3::Create(1,-1,0),
|
||||
Vector3::Create(1,1,0),
|
||||
Vector3::Create(-1,1,0)
|
||||
};
|
||||
|
||||
Vector3 pa,pb,pc;
|
||||
int nt = 0,ntold;
|
||||
|
||||
/* Create the level 0 object */
|
||||
a = 1 / sqrt(2.0);
|
||||
a = 1.0f / sqrtf(2.0f);
|
||||
for (i=0;i<6;i++) {
|
||||
p[i].x *= a;
|
||||
p[i].y *= a;
|
||||
|
||||
@@ -36,7 +36,7 @@ KRRenderSettings::KRRenderSettings()
|
||||
ambient_intensity = Vector3::Zero();
|
||||
light_intensity = Vector3::One();
|
||||
|
||||
perspective_fov = 45.0 * D2R;
|
||||
perspective_fov = 45.0f * D2R;
|
||||
perspective_nearz = 0.3f; // was 0.05f
|
||||
perspective_farz = 1000.0f;
|
||||
|
||||
@@ -60,14 +60,14 @@ KRRenderSettings::KRRenderSettings()
|
||||
volumetric_environment_enable = false;
|
||||
volumetric_environment_downsample = 2;
|
||||
volumetric_environment_max_distance = 100.0f;
|
||||
volumetric_environment_quality = (50 - 5.0) / 495.0f;
|
||||
volumetric_environment_quality = (50.0f - 5.0f) / 495.0f;
|
||||
volumetric_environment_intensity = 0.9f;
|
||||
|
||||
|
||||
fog_near = 50.0f;
|
||||
fog_far = 500.0f;
|
||||
fog_density = 0.0005f;
|
||||
fog_color = Vector3(0.45, 0.45, 0.5);
|
||||
fog_color = Vector3::Create(0.45f, 0.45f, 0.5f);
|
||||
fog_type = 0;
|
||||
|
||||
dust_particle_intensity = 0.25f;
|
||||
|
||||
@@ -154,7 +154,7 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
|
||||
y = strtof(pChar, &pChar);
|
||||
pChar = szSymbol[3];
|
||||
z = strtof(pChar, &pChar);
|
||||
indexed_vertices.push_back(Vector3(x,y,z));
|
||||
indexed_vertices.push_back(Vector3::Create(x,y,z));
|
||||
} else if(strcmp(szSymbol[0], "vt") == 0) {
|
||||
// Vertex Texture UV Coordinate (vt)
|
||||
char *pChar = szSymbol[1];
|
||||
@@ -163,7 +163,7 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
|
||||
u = strtof(pChar, &pChar);
|
||||
pChar = szSymbol[2];
|
||||
v = strtof(pChar, &pChar);
|
||||
indexed_uva.push_back(Vector2(u,v));
|
||||
indexed_uva.push_back(Vector2::Create(u,v));
|
||||
} else if(strcmp(szSymbol[0], "vn") == 0) {
|
||||
// Vertex Normal (vn)
|
||||
float x,y,z;
|
||||
@@ -173,7 +173,7 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
|
||||
y = strtof(pChar, &pChar);
|
||||
pChar = szSymbol[3];
|
||||
z = strtof(pChar, &pChar);
|
||||
indexed_normals.push_back(Vector3(x,y,z));
|
||||
indexed_normals.push_back(Vector3::Create(x,y,z));
|
||||
} else if(strcmp(szSymbol[0], "f") == 0) {
|
||||
// Face (f)
|
||||
int cFaceVertices = cSymbols - 1;
|
||||
|
||||
@@ -138,7 +138,7 @@ void KRReverbZone::setGradientDistance(float gradient_distance)
|
||||
|
||||
AABB KRReverbZone::getBounds() {
|
||||
// Reverb zones always have a -1, -1, -1 to 1, 1, 1 bounding box
|
||||
return AABB(-Vector3::One(), Vector3::One(), getModelMatrix());
|
||||
return AABB::Create(-Vector3::One(), Vector3::One(), getModelMatrix());
|
||||
}
|
||||
|
||||
float KRReverbZone::getContainment(const Vector3 &pos)
|
||||
@@ -148,7 +148,7 @@ float KRReverbZone::getContainment(const Vector3 &pos)
|
||||
Vector3 size = bounds.size();
|
||||
Vector3 diff = pos - bounds.center();
|
||||
diff = diff * 2.0f;
|
||||
diff = Vector3(diff.x / size.x, diff.y / size.y, diff.z / size.z);
|
||||
diff = Vector3::Create(diff.x / size.x, diff.y / size.y, diff.z / size.z);
|
||||
float d = diff.magnitude();
|
||||
|
||||
if(m_gradient_distance <= 0.0f) {
|
||||
|
||||
@@ -208,7 +208,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map<AABB, int> &visibl
|
||||
bool in_viewport = false;
|
||||
if(renderPass == KRNode::RENDER_PASS_PRESTREAM) {
|
||||
// When pre-streaming, objects are streamed in behind and in-front of the camera
|
||||
AABB viewportExtents = AABB(viewport.getCameraPosition() - Vector3(pCamera->settings.getPerspectiveFarZ()), viewport.getCameraPosition() + Vector3(pCamera->settings.getPerspectiveFarZ()));
|
||||
AABB viewportExtents = AABB::Create(viewport.getCameraPosition() - Vector3::Create(pCamera->settings.getPerspectiveFarZ()), viewport.getCameraPosition() + Vector3::Create(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<AABB, int> &visibl
|
||||
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
|
||||
AABB cameraExtents = AABB(viewport.getCameraPosition() - Vector3(pCamera->settings.getPerspectiveNearZ()), viewport.getCameraPosition() + Vector3(pCamera->settings.getPerspectiveNearZ()));
|
||||
AABB cameraExtents = AABB::Create(viewport.getCameraPosition() - Vector3::Create(pCamera->settings.getPerspectiveNearZ()), viewport.getCameraPosition() + Vector3::Create(pCamera->settings.getPerspectiveNearZ()));
|
||||
bVisible = octreeBounds.intersects(cameraExtents);
|
||||
if(bVisible) {
|
||||
// Record the frame number in which the camera was within the bounds
|
||||
@@ -565,7 +565,7 @@ void KRScene::addDefaultLights()
|
||||
{
|
||||
KRDirectionalLight *light1 = new KRDirectionalLight(*this, "default_light1");
|
||||
|
||||
light1->setLocalRotation((Quaternion(Vector3(0.0, M_PI * 0.10, 0.0)) * Quaternion(Vector3(0.0, 0.0, -M_PI * 0.15))).eulerXYZ());
|
||||
light1->setLocalRotation((Quaternion::Create(Vector3::Create(0.0f, M_PI * 0.10f, 0.0f)) * Quaternion::Create(Vector3::Create(0.0f, 0.0f, -M_PI * 0.15f))).eulerXYZ());
|
||||
m_pRootNode->addChild(light1);
|
||||
}
|
||||
|
||||
@@ -574,7 +574,7 @@ AABB KRScene::getRootOctreeBounds()
|
||||
if(m_nodeTree.getRootNode()) {
|
||||
return m_nodeTree.getRootNode()->getBounds();
|
||||
} else {
|
||||
return AABB(-Vector3::One(), Vector3::One());
|
||||
return AABB::Create(-Vector3::One(), Vector3::One());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -503,7 +503,7 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const Matrix4
|
||||
}
|
||||
|
||||
if(m_uniforms[KRENGINE_UNIFORM_VIEWPORT] != -1) {
|
||||
setUniform(KRENGINE_UNIFORM_VIEWPORT, Vector4(
|
||||
setUniform(KRENGINE_UNIFORM_VIEWPORT, Vector4::Create(
|
||||
(GLfloat)0.0,
|
||||
(GLfloat)0.0,
|
||||
(GLfloat)viewport.getSize().x,
|
||||
|
||||
@@ -55,7 +55,7 @@ AABB KRSpotLight::getBounds() {
|
||||
if(influence_radius < m_flareOcclusionSize) {
|
||||
influence_radius = m_flareOcclusionSize;
|
||||
}
|
||||
return AABB(Vector3(-influence_radius), Vector3(influence_radius), getModelMatrix());
|
||||
return AABB::Create(Vector3::Create(-influence_radius), Vector3::Create(influence_radius), getModelMatrix());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ float KRSprite::getSpriteAlpha() const
|
||||
}
|
||||
|
||||
AABB KRSprite::getBounds() {
|
||||
return AABB(-Vector3::One() * 0.5f, Vector3::One() * 0.5f, getModelMatrix());
|
||||
return AABB::Create(-Vector3::One() * 0.5f, Vector3::One() * 0.5f, getModelMatrix());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ void KRViewport::calculateDerivedValues()
|
||||
m_matInverseView = Matrix4::Invert(m_matView);
|
||||
m_matInverseProjection = Matrix4::Invert(m_matProjection);
|
||||
m_cameraPosition = Matrix4::Dot(m_matInverseView, Vector3::Zero());
|
||||
m_cameraDirection = Matrix4::Dot(m_matInverseView, Vector3(0.0, 0.0, 1.0)) - Matrix4::Dot(m_matInverseView, Vector3(0.0, 0.0, 0.0));
|
||||
m_cameraDirection = Matrix4::Dot(m_matInverseView, Vector3::Create(0.0, 0.0, 1.0)) - Matrix4::Dot(m_matInverseView, Vector3::Create(0.0, 0.0, 0.0));
|
||||
|
||||
for(int i=0; i<8; i++) {
|
||||
m_frontToBackOrder[i] = i;
|
||||
@@ -221,7 +221,7 @@ bool KRViewport::visible(const AABB &b) const
|
||||
int outside_count[6] = {0, 0, 0, 0, 0, 0};
|
||||
|
||||
for(int iCorner=0; iCorner<8; iCorner++) {
|
||||
Vector4 sourceCornerVertex = Vector4(
|
||||
Vector4 sourceCornerVertex = Vector4::Create(
|
||||
(iCorner & 1) == 0 ? b.min.x : b.max.x,
|
||||
(iCorner & 2) == 0 ? b.min.y : b.max.y,
|
||||
(iCorner & 4) == 0 ? b.min.z : b.max.z, 1.0f);
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
#include "KREngine-common.h"
|
||||
|
||||
#include "aabb.h"
|
||||
|
||||
class KRLight;
|
||||
|
||||
class KRViewport {
|
||||
|
||||
339
kraken/aabb.cpp
339
kraken/aabb.cpp
@@ -1,339 +0,0 @@
|
||||
//
|
||||
// KRAABB.cpp
|
||||
// KREngine
|
||||
//
|
||||
// Created by Kearwood Gilbert on 2012-08-30.
|
||||
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
#include "public/kraken.h"
|
||||
#include "assert.h"
|
||||
#include "KRHelpers.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
AABB::AABB()
|
||||
{
|
||||
min = Vector3::Min();
|
||||
max = Vector3::Max();
|
||||
}
|
||||
|
||||
AABB::AABB(const Vector3 &minPoint, const Vector3 &maxPoint)
|
||||
{
|
||||
min = minPoint;
|
||||
max = maxPoint;
|
||||
}
|
||||
|
||||
AABB::AABB(const Vector3 &corner1, const Vector3 &corner2, const Matrix4 &modelMatrix)
|
||||
{
|
||||
for(int iCorner=0; iCorner<8; iCorner++) {
|
||||
Vector3 sourceCornerVertex = Matrix4::DotWDiv(modelMatrix, Vector3(
|
||||
(iCorner & 1) == 0 ? corner1.x : corner2.x,
|
||||
(iCorner & 2) == 0 ? corner1.y : corner2.y,
|
||||
(iCorner & 4) == 0 ? corner1.z : corner2.z));
|
||||
|
||||
|
||||
if(iCorner == 0) {
|
||||
min = sourceCornerVertex;
|
||||
max = sourceCornerVertex;
|
||||
} else {
|
||||
if(sourceCornerVertex.x < min.x) min.x = sourceCornerVertex.x;
|
||||
if(sourceCornerVertex.y < min.y) min.y = sourceCornerVertex.y;
|
||||
if(sourceCornerVertex.z < min.z) min.z = sourceCornerVertex.z;
|
||||
if(sourceCornerVertex.x > max.x) max.x = sourceCornerVertex.x;
|
||||
if(sourceCornerVertex.y > max.y) max.y = sourceCornerVertex.y;
|
||||
if(sourceCornerVertex.z > max.z) max.z = sourceCornerVertex.z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AABB::~AABB()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AABB& AABB::operator =(const AABB& b)
|
||||
{
|
||||
min = b.min;
|
||||
max = b.max;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool AABB::operator ==(const AABB& b) const
|
||||
{
|
||||
return min == b.min && max == b.max;
|
||||
}
|
||||
|
||||
bool AABB::operator !=(const AABB& b) const
|
||||
{
|
||||
return min != b.min || max != b.max;
|
||||
}
|
||||
|
||||
Vector3 AABB::center() const
|
||||
{
|
||||
return (min + max) * 0.5f;
|
||||
}
|
||||
|
||||
Vector3 AABB::size() const
|
||||
{
|
||||
return max - min;
|
||||
}
|
||||
|
||||
float AABB::volume() const
|
||||
{
|
||||
Vector3 s = size();
|
||||
return s.x * s.y * s.z;
|
||||
}
|
||||
|
||||
void AABB::scale(const Vector3 &s)
|
||||
{
|
||||
Vector3 prev_center = center();
|
||||
Vector3 prev_size = size();
|
||||
Vector3 new_scale = Vector3(prev_size.x * s.x, prev_size.y * s.y, prev_size.z * s.z) * 0.5f;
|
||||
min = prev_center - new_scale;
|
||||
max = prev_center + new_scale;
|
||||
}
|
||||
|
||||
void AABB::scale(float s)
|
||||
{
|
||||
scale(Vector3(s));
|
||||
}
|
||||
|
||||
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) {
|
||||
return true;
|
||||
} else if(min < b.min) {
|
||||
return false;
|
||||
} else if(max > b.max) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
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) {
|
||||
return true;
|
||||
} else if(min > b.min) {
|
||||
return false;
|
||||
} else if(max < b.max) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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 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 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;
|
||||
}
|
||||
|
||||
AABB AABB::Infinite()
|
||||
{
|
||||
return AABB(Vector3::Min(), Vector3::Max());
|
||||
}
|
||||
|
||||
AABB AABB::Zero()
|
||||
{
|
||||
return AABB(Vector3::Zero(), Vector3::Zero());
|
||||
}
|
||||
|
||||
float AABB::longest_radius() const
|
||||
{
|
||||
float radius1 = (center() - min).magnitude();
|
||||
float radius2 = (max - center()).magnitude();
|
||||
return radius1 > radius2 ? radius1 : radius2;
|
||||
}
|
||||
|
||||
|
||||
bool AABB::intersectsLine(const Vector3 &v1, const Vector3 &v2) const
|
||||
{
|
||||
Vector3 dir = Vector3::Normalize(v2 - v1);
|
||||
float length = (v2 - v1).magnitude();
|
||||
|
||||
// EZ cases: if the ray starts inside the box, or ends inside
|
||||
// the box, then it definitely hits the box.
|
||||
// I'm using this code for ray tracing with an octree,
|
||||
// so I needed rays that start and end within an
|
||||
// octree node to COUNT as hits.
|
||||
// You could modify this test to (ray starts inside and ends outside)
|
||||
// to qualify as a hit if you wanted to NOT count totally internal rays
|
||||
if( contains( v1 ) || contains( v2 ) )
|
||||
return true ;
|
||||
|
||||
// the algorithm says, find 3 t's,
|
||||
Vector3 t ;
|
||||
|
||||
// LARGEST t is the only one we need to test if it's on the face.
|
||||
for(int i = 0 ; i < 3 ; i++) {
|
||||
if( dir[i] > 0 ) { // CULL BACK FACE
|
||||
t[i] = ( min[i] - v1[i] ) / dir[i];
|
||||
} else {
|
||||
t[i] = ( max[i] - v1[i] ) / dir[i];
|
||||
}
|
||||
}
|
||||
|
||||
int mi = 0;
|
||||
if(t[1] > t[mi]) mi = 1;
|
||||
if(t[2] > t[mi]) mi = 2;
|
||||
if(t[mi] >= 0 && t[mi] <= length) {
|
||||
Vector3 pt = v1 + dir * t[mi];
|
||||
|
||||
// check it's in the box in other 2 dimensions
|
||||
int o1 = ( mi + 1 ) % 3 ; // i=0: o1=1, o2=2, i=1: o1=2,o2=0 etc.
|
||||
int o2 = ( mi + 2 ) % 3 ;
|
||||
|
||||
return pt[o1] >= min[o1] && pt[o1] <= max[o1] && pt[o2] >= min[o2] && pt[o2] <= max[o2];
|
||||
}
|
||||
|
||||
return false ; // the ray did not hit the box.
|
||||
}
|
||||
|
||||
bool AABB::intersectsRay(const Vector3 &v1, const Vector3 &dir) const
|
||||
{
|
||||
/*
|
||||
Fast Ray-Box Intersection
|
||||
by Andrew Woo
|
||||
from "Graphics Gems", Academic Press, 1990
|
||||
*/
|
||||
|
||||
// FINDME, TODO - Perhaps there is a more efficient algorithm, as we don't actually need the exact coordinate of the intersection
|
||||
|
||||
enum {
|
||||
RIGHT = 0,
|
||||
LEFT = 1,
|
||||
MIDDLE = 2
|
||||
} quadrant[3];
|
||||
|
||||
bool inside = true;
|
||||
Vector3 maxT;
|
||||
Vector3 coord;
|
||||
double candidatePlane[3];
|
||||
|
||||
// Find candidate planes; this loop can be avoided if rays cast all from the eye(assume perpsective view)
|
||||
for (int i=0; i<3; i++)
|
||||
if(v1.c[i] < min.c[i]) {
|
||||
quadrant[i] = LEFT;
|
||||
candidatePlane[i] = min.c[i];
|
||||
inside = false;
|
||||
} else if(v1.c[i] > max.c[i]) {
|
||||
quadrant[i] = RIGHT;
|
||||
candidatePlane[i] = max.c[i];
|
||||
inside = false;
|
||||
} else {
|
||||
quadrant[i] = MIDDLE;
|
||||
}
|
||||
|
||||
/* Ray v1 inside bounding box */
|
||||
if (inside) {
|
||||
coord = v1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Calculate T distances to candidate planes */
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (quadrant[i] != MIDDLE && dir[i] != 0.0f) {
|
||||
maxT.c[i] = (candidatePlane[i]-v1.c[i]) / dir[i];
|
||||
} else {
|
||||
maxT.c[i] = -1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get largest of the maxT's for final choice of intersection */
|
||||
int whichPlane = 0;
|
||||
for (int i = 1; i < 3; i++) {
|
||||
if (maxT.c[whichPlane] < maxT.c[i]) {
|
||||
whichPlane = i;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check final candidate actually inside box */
|
||||
if (maxT.c[whichPlane] < 0.0f) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (whichPlane != i) {
|
||||
coord[i] = v1.c[i] + maxT.c[whichPlane] *dir[i];
|
||||
if (coord[i] < min.c[i] || coord[i] > max.c[i]) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
assert(quadrant[i] != MIDDLE); // This should not be possible
|
||||
coord[i] = candidatePlane[i];
|
||||
}
|
||||
}
|
||||
return true; /* ray hits box */
|
||||
}
|
||||
|
||||
bool AABB::intersectsSphere(const Vector3 ¢er, float radius) const
|
||||
{
|
||||
// Arvo's Algorithm
|
||||
|
||||
float squaredDistance = 0;
|
||||
|
||||
// process X
|
||||
if (center.x < min.x) {
|
||||
float diff = center.x - min.x;
|
||||
squaredDistance += diff * diff;
|
||||
} else if (center.x > max.x) {
|
||||
float diff = center.x - max.x;
|
||||
squaredDistance += diff * diff;
|
||||
}
|
||||
|
||||
// process Y
|
||||
if (center.y < min.y) {
|
||||
float diff = center.y - min.y;
|
||||
squaredDistance += diff * diff;
|
||||
} else if (center.y > max.y) {
|
||||
float diff = center.y - max.y;
|
||||
squaredDistance += diff * diff;
|
||||
}
|
||||
|
||||
// process Z
|
||||
if (center.z < min.z) {
|
||||
float diff = center.z - min.z;
|
||||
squaredDistance += diff * diff;
|
||||
} else if (center.z > max.z) {
|
||||
float diff = center.z - max.z;
|
||||
squaredDistance += diff * diff;
|
||||
}
|
||||
|
||||
return squaredDistance <= radius;
|
||||
}
|
||||
|
||||
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;
|
||||
if(b.min.z < min.z) min.z = b.min.z;
|
||||
|
||||
if(b.max.x > max.x) max.x = b.max.x;
|
||||
if(b.max.y > max.y) max.y = b.max.y;
|
||||
if(b.max.z > max.z) max.z = b.max.z;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
//
|
||||
// HitInfo.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 "public/kraken.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
HitInfo::HitInfo()
|
||||
{
|
||||
m_position = Vector3::Zero();
|
||||
m_normal = Vector3::Zero();
|
||||
m_distance = 0.0f;
|
||||
m_node = NULL;
|
||||
}
|
||||
|
||||
HitInfo::HitInfo(const Vector3 &position, const Vector3 &normal, const float distance, KRNode *node)
|
||||
{
|
||||
m_position = position;
|
||||
m_normal = normal;
|
||||
m_distance = distance;
|
||||
m_node = node;
|
||||
}
|
||||
|
||||
HitInfo::HitInfo(const Vector3 &position, const Vector3 &normal, const float distance)
|
||||
{
|
||||
m_position = position;
|
||||
m_normal = normal;
|
||||
m_distance = distance;
|
||||
m_node = NULL;
|
||||
}
|
||||
|
||||
HitInfo::~HitInfo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool HitInfo::didHit() const
|
||||
{
|
||||
return m_normal != Vector3::Zero();
|
||||
}
|
||||
|
||||
Vector3 HitInfo::getPosition() const
|
||||
{
|
||||
return m_position;
|
||||
}
|
||||
|
||||
Vector3 HitInfo::getNormal() const
|
||||
{
|
||||
return m_normal;
|
||||
}
|
||||
|
||||
float HitInfo::getDistance() const
|
||||
{
|
||||
return m_distance;
|
||||
}
|
||||
|
||||
KRNode *HitInfo::getNode() const
|
||||
{
|
||||
return m_node;
|
||||
}
|
||||
|
||||
HitInfo& HitInfo::operator =(const HitInfo& b)
|
||||
{
|
||||
m_position = b.m_position;
|
||||
m_normal = b.m_normal;
|
||||
m_distance = b.m_distance;
|
||||
m_node = b.m_node;
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
@@ -1,448 +0,0 @@
|
||||
//
|
||||
// Matrix4.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 "public/kraken.h"
|
||||
#include <string.h>
|
||||
|
||||
namespace kraken {
|
||||
|
||||
Matrix4::Matrix4() {
|
||||
// Default constructor - Initialize with an identity matrix
|
||||
static const float IDENTITY_MATRIX[] = {
|
||||
1.0, 0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
};
|
||||
memcpy(c, IDENTITY_MATRIX, sizeof(float) * 16);
|
||||
|
||||
}
|
||||
|
||||
Matrix4::Matrix4(float *pMat) {
|
||||
memcpy(c, pMat, sizeof(float) * 16);
|
||||
}
|
||||
|
||||
Matrix4::Matrix4(const Vector3 &new_axis_x, const Vector3 &new_axis_y, const Vector3 &new_axis_z, const Vector3 &new_transform)
|
||||
{
|
||||
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() {
|
||||
|
||||
}
|
||||
|
||||
float *Matrix4::getPointer() {
|
||||
return c;
|
||||
}
|
||||
|
||||
// Copy constructor
|
||||
Matrix4::Matrix4(const Matrix4 &m) {
|
||||
memcpy(c, m.c, sizeof(float) * 16);
|
||||
}
|
||||
|
||||
Matrix4& Matrix4::operator=(const Matrix4 &m) {
|
||||
if(this != &m) { // Prevent self-assignment.
|
||||
memcpy(c, m.c, sizeof(float) * 16);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
float& Matrix4::operator[](unsigned i) {
|
||||
return c[i];
|
||||
}
|
||||
|
||||
float Matrix4::operator[](unsigned i) const {
|
||||
return c[i];
|
||||
}
|
||||
|
||||
// Overload comparison operator
|
||||
bool Matrix4::operator==(const Matrix4 &m) const {
|
||||
return memcmp(c, m.c, sizeof(float) * 16) == 0;
|
||||
}
|
||||
|
||||
// Overload compound multiply operator
|
||||
Matrix4& Matrix4::operator*=(const Matrix4 &m) {
|
||||
float temp[16];
|
||||
|
||||
int x,y;
|
||||
|
||||
for (x=0; x < 4; x++)
|
||||
{
|
||||
for(y=0; y < 4; y++)
|
||||
{
|
||||
temp[y + (x*4)] = (c[x*4] * m.c[y]) +
|
||||
(c[(x*4)+1] * m.c[y+4]) +
|
||||
(c[(x*4)+2] * m.c[y+8]) +
|
||||
(c[(x*4)+3] * m.c[y+12]);
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(c, temp, sizeof(float) << 4);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Overload multiply operator
|
||||
Matrix4 Matrix4::operator*(const Matrix4 &m) const {
|
||||
Matrix4 ret = *this;
|
||||
ret *= m;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Generate a perspective view matrix using a field of view angle fov,
|
||||
* window aspect ratio, near and far clipping planes */
|
||||
void Matrix4::perspective(float fov, float aspect, float nearz, float farz) {
|
||||
|
||||
memset(c, 0, sizeof(float) * 16);
|
||||
|
||||
float range= tan(fov * 0.5) * nearz;
|
||||
c[0] = (2 * nearz) / ((range * aspect) - (-range * aspect));
|
||||
c[5] = (2 * nearz) / (2 * range);
|
||||
c[10] = -(farz + nearz) / (farz - nearz);
|
||||
c[11] = -1;
|
||||
c[14] = -(2 * farz * nearz) / (farz - nearz);
|
||||
/*
|
||||
float range= atan(fov / 20.0f) * nearz;
|
||||
float r = range * aspect;
|
||||
float t = range * 1.0;
|
||||
|
||||
c[0] = nearz / r;
|
||||
c[5] = nearz / t;
|
||||
c[10] = -(farz + nearz) / (farz - nearz);
|
||||
c[11] = -(2.0 * farz * nearz) / (farz - nearz);
|
||||
c[14] = -1.0;
|
||||
*/
|
||||
}
|
||||
|
||||
/* Perform translation operations on a matrix */
|
||||
void Matrix4::translate(float x, float y, float z) {
|
||||
Matrix4 newMatrix; // Create new identity matrix
|
||||
|
||||
newMatrix.c[12] = x;
|
||||
newMatrix.c[13] = y;
|
||||
newMatrix.c[14] = z;
|
||||
|
||||
*this *= newMatrix;
|
||||
}
|
||||
|
||||
void Matrix4::translate(const Vector3 &v)
|
||||
{
|
||||
translate(v.x, v.y, v.z);
|
||||
}
|
||||
|
||||
/* Rotate a matrix by an angle on a X, Y, or Z axis */
|
||||
void Matrix4::rotate(float angle, AXIS axis) {
|
||||
const int cos1[3] = { 5, 0, 0 }; // cos(angle)
|
||||
const int cos2[3] = { 10, 10, 5 }; // cos(angle)
|
||||
const int sin1[3] = { 9, 2, 4 }; // -sin(angle)
|
||||
const int sin2[3] = { 6, 8, 1 }; // sin(angle)
|
||||
|
||||
/*
|
||||
X_AXIS:
|
||||
|
||||
1, 0, 0, 0
|
||||
0, cos(angle), -sin(angle), 0
|
||||
0, sin(angle), cos(angle), 0
|
||||
0, 0, 0, 1
|
||||
|
||||
Y_AXIS:
|
||||
|
||||
cos(angle), 0, -sin(angle), 0
|
||||
0, 1, 0, 0
|
||||
sin(angle), 0, cos(angle), 0
|
||||
0, 0, 0, 1
|
||||
|
||||
Z_AXIS:
|
||||
|
||||
cos(angle), -sin(angle), 0, 0
|
||||
sin(angle), cos(angle), 0, 0
|
||||
0, 0, 1, 0
|
||||
0, 0, 0, 1
|
||||
|
||||
*/
|
||||
|
||||
Matrix4 newMatrix; // Create new identity matrix
|
||||
|
||||
newMatrix.c[cos1[axis]] = cos(angle);
|
||||
newMatrix.c[sin1[axis]] = -sin(angle);
|
||||
newMatrix.c[sin2[axis]] = -newMatrix.c[sin1[axis]];
|
||||
newMatrix.c[cos2[axis]] = newMatrix.c[cos1[axis]];
|
||||
|
||||
*this *= newMatrix;
|
||||
}
|
||||
|
||||
void Matrix4::rotate(const Quaternion &q)
|
||||
{
|
||||
*this *= q.rotationMatrix();
|
||||
}
|
||||
|
||||
/* Scale matrix by separate x, y, and z amounts */
|
||||
void Matrix4::scale(float x, float y, float z) {
|
||||
Matrix4 newMatrix; // Create new identity matrix
|
||||
|
||||
newMatrix.c[0] = x;
|
||||
newMatrix.c[5] = y;
|
||||
newMatrix.c[10] = z;
|
||||
|
||||
*this *= newMatrix;
|
||||
}
|
||||
|
||||
void Matrix4::scale(const Vector3 &v) {
|
||||
scale(v.x, v.y, v.z);
|
||||
}
|
||||
|
||||
/* Scale all dimensions equally */
|
||||
void Matrix4::scale(float s) {
|
||||
scale(s,s,s);
|
||||
}
|
||||
|
||||
// Initialize with a bias matrix
|
||||
void Matrix4::bias() {
|
||||
static const float BIAS_MATRIX[] = {
|
||||
0.5, 0.0, 0.0, 0.0,
|
||||
0.0, 0.5, 0.0, 0.0,
|
||||
0.0, 0.0, 0.5, 0.0,
|
||||
0.5, 0.5, 0.5, 1.0
|
||||
};
|
||||
memcpy(c, BIAS_MATRIX, sizeof(float) * 16);
|
||||
}
|
||||
|
||||
|
||||
/* Generate an orthographic view matrix */
|
||||
void Matrix4::ortho(float left, float right, float top, float bottom, float nearz, float farz) {
|
||||
memset(c, 0, sizeof(float) * 16);
|
||||
c[0] = 2.0f / (right - left);
|
||||
c[5] = 2.0f / (bottom - top);
|
||||
c[10] = -1.0f / (farz - nearz);
|
||||
c[11] = -nearz / (farz - nearz);
|
||||
c[15] = 1.0f;
|
||||
}
|
||||
|
||||
/* Replace matrix with its inverse */
|
||||
bool Matrix4::invert() {
|
||||
// Based on gluInvertMatrix implementation
|
||||
|
||||
float inv[16], det;
|
||||
int i;
|
||||
|
||||
inv[0] = c[5]*c[10]*c[15] - c[5]*c[11]*c[14] - c[9]*c[6]*c[15]
|
||||
+ c[9]*c[7]*c[14] + c[13]*c[6]*c[11] - c[13]*c[7]*c[10];
|
||||
inv[4] = -c[4]*c[10]*c[15] + c[4]*c[11]*c[14] + c[8]*c[6]*c[15]
|
||||
- c[8]*c[7]*c[14] - c[12]*c[6]*c[11] + c[12]*c[7]*c[10];
|
||||
inv[8] = c[4]*c[9]*c[15] - c[4]*c[11]*c[13] - c[8]*c[5]*c[15]
|
||||
+ c[8]*c[7]*c[13] + c[12]*c[5]*c[11] - c[12]*c[7]*c[9];
|
||||
inv[12] = -c[4]*c[9]*c[14] + c[4]*c[10]*c[13] + c[8]*c[5]*c[14]
|
||||
- c[8]*c[6]*c[13] - c[12]*c[5]*c[10] + c[12]*c[6]*c[9];
|
||||
inv[1] = -c[1]*c[10]*c[15] + c[1]*c[11]*c[14] + c[9]*c[2]*c[15]
|
||||
- c[9]*c[3]*c[14] - c[13]*c[2]*c[11] + c[13]*c[3]*c[10];
|
||||
inv[5] = c[0]*c[10]*c[15] - c[0]*c[11]*c[14] - c[8]*c[2]*c[15]
|
||||
+ c[8]*c[3]*c[14] + c[12]*c[2]*c[11] - c[12]*c[3]*c[10];
|
||||
inv[9] = -c[0]*c[9]*c[15] + c[0]*c[11]*c[13] + c[8]*c[1]*c[15]
|
||||
- c[8]*c[3]*c[13] - c[12]*c[1]*c[11] + c[12]*c[3]*c[9];
|
||||
inv[13] = c[0]*c[9]*c[14] - c[0]*c[10]*c[13] - c[8]*c[1]*c[14]
|
||||
+ c[8]*c[2]*c[13] + c[12]*c[1]*c[10] - c[12]*c[2]*c[9];
|
||||
inv[2] = c[1]*c[6]*c[15] - c[1]*c[7]*c[14] - c[5]*c[2]*c[15]
|
||||
+ c[5]*c[3]*c[14] + c[13]*c[2]*c[7] - c[13]*c[3]*c[6];
|
||||
inv[6] = -c[0]*c[6]*c[15] + c[0]*c[7]*c[14] + c[4]*c[2]*c[15]
|
||||
- c[4]*c[3]*c[14] - c[12]*c[2]*c[7] + c[12]*c[3]*c[6];
|
||||
inv[10] = c[0]*c[5]*c[15] - c[0]*c[7]*c[13] - c[4]*c[1]*c[15]
|
||||
+ c[4]*c[3]*c[13] + c[12]*c[1]*c[7] - c[12]*c[3]*c[5];
|
||||
inv[14] = -c[0]*c[5]*c[14] + c[0]*c[6]*c[13] + c[4]*c[1]*c[14]
|
||||
- c[4]*c[2]*c[13] - c[12]*c[1]*c[6] + c[12]*c[2]*c[5];
|
||||
inv[3] = -c[1]*c[6]*c[11] + c[1]*c[7]*c[10] + c[5]*c[2]*c[11]
|
||||
- c[5]*c[3]*c[10] - c[9]*c[2]*c[7] + c[9]*c[3]*c[6];
|
||||
inv[7] = c[0]*c[6]*c[11] - c[0]*c[7]*c[10] - c[4]*c[2]*c[11]
|
||||
+ c[4]*c[3]*c[10] + c[8]*c[2]*c[7] - c[8]*c[3]*c[6];
|
||||
inv[11] = -c[0]*c[5]*c[11] + c[0]*c[7]*c[9] + c[4]*c[1]*c[11]
|
||||
- c[4]*c[3]*c[9] - c[8]*c[1]*c[7] + c[8]*c[3]*c[5];
|
||||
inv[15] = c[0]*c[5]*c[10] - c[0]*c[6]*c[9] - c[4]*c[1]*c[10]
|
||||
+ c[4]*c[2]*c[9] + c[8]*c[1]*c[6] - c[8]*c[2]*c[5];
|
||||
|
||||
det = c[0]*inv[0] + c[1]*inv[4] + c[2]*inv[8] + c[3]*inv[12];
|
||||
|
||||
if (det == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
det = 1.0 / det;
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
c[i] = inv[i] * det;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Matrix4::transpose() {
|
||||
float trans[16];
|
||||
for(int x=0; x<4; x++) {
|
||||
for(int y=0; y<4; y++) {
|
||||
trans[x + y * 4] = c[y + x * 4];
|
||||
}
|
||||
}
|
||||
memcpy(c, trans, sizeof(float) * 16);
|
||||
}
|
||||
|
||||
/* Dot Product, returning Vector3 */
|
||||
Vector3 Matrix4::Dot(const Matrix4 &m, const Vector3 &v) {
|
||||
return Vector3(
|
||||
v.c[0] * m.c[0] + v.c[1] * m.c[4] + v.c[2] * m.c[8] + m.c[12],
|
||||
v.c[0] * m.c[1] + v.c[1] * m.c[5] + v.c[2] * m.c[9] + m.c[13],
|
||||
v.c[0] * m.c[2] + v.c[1] * m.c[6] + v.c[2] * m.c[10] + m.c[14]
|
||||
);
|
||||
}
|
||||
|
||||
Vector4 Matrix4::Dot4(const Matrix4 &m, const Vector4 &v) {
|
||||
#ifdef KRAKEN_USE_ARM_NEON
|
||||
|
||||
Vector4 d;
|
||||
asm volatile (
|
||||
"vld1.32 {d0, d1}, [%1] \n\t" //Q0 = v
|
||||
"vld1.32 {d18, d19}, [%0]! \n\t" //Q1 = m
|
||||
"vld1.32 {d20, d21}, [%0]! \n\t" //Q2 = m+4
|
||||
"vld1.32 {d22, d23}, [%0]! \n\t" //Q3 = m+8
|
||||
"vld1.32 {d24, d25}, [%0]! \n\t" //Q4 = m+12
|
||||
|
||||
"vmul.f32 q13, q9, d0[0] \n\t" //Q5 = Q1*Q0[0]
|
||||
"vmla.f32 q13, q10, d0[1] \n\t" //Q5 += Q1*Q0[1]
|
||||
"vmla.f32 q13, q11, d1[0] \n\t" //Q5 += Q2*Q0[2]
|
||||
"vmla.f32 q13, q12, d1[1] \n\t" //Q5 += Q3*Q0[3]
|
||||
|
||||
"vst1.32 {d26, d27}, [%2] \n\t" //Q4 = m+12
|
||||
: /* no output registers */
|
||||
: "r"(m.c), "r"(v.c), "r"(d.c)
|
||||
: "q0", "q9", "q10","q11", "q12", "q13", "memory"
|
||||
);
|
||||
return d;
|
||||
#else
|
||||
return Vector4(
|
||||
v.c[0] * m.c[0] + v.c[1] * m.c[4] + v.c[2] * m.c[8] + m.c[12],
|
||||
v.c[0] * m.c[1] + v.c[1] * m.c[5] + v.c[2] * m.c[9] + m.c[13],
|
||||
v.c[0] * m.c[2] + v.c[1] * m.c[6] + v.c[2] * m.c[10] + m.c[14],
|
||||
v.c[0] * m.c[3] + v.c[1] * m.c[7] + v.c[2] * m.c[11] + m.c[15]
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Dot product without including translation; useful for transforming normals and tangents
|
||||
Vector3 Matrix4::DotNoTranslate(const Matrix4 &m, const Vector3 &v)
|
||||
{
|
||||
return Vector3(
|
||||
v.x * m.c[0] + v.y * m.c[4] + v.z * m.c[8],
|
||||
v.x * m.c[1] + v.y * m.c[5] + v.z * m.c[9],
|
||||
v.x * m.c[2] + v.y * m.c[6] + v.z * m.c[10]
|
||||
);
|
||||
}
|
||||
|
||||
/* Dot Product, returning w component as if it were a Vector4 (This will be deprecated once Vector4 is implemented instead*/
|
||||
float Matrix4::DotW(const Matrix4 &m, const Vector3 &v) {
|
||||
return v.x * m.c[0*4 + 3] + v.y * m.c[1*4 + 3] + v.z * m.c[2*4 + 3] + m.c[3*4 + 3];
|
||||
}
|
||||
|
||||
/* Dot Product followed by W-divide */
|
||||
Vector3 Matrix4::DotWDiv(const Matrix4 &m, const Vector3 &v) {
|
||||
Vector4 r = Dot4(m, Vector4(v, 1.0f));
|
||||
return Vector3(r) / r.w;
|
||||
}
|
||||
|
||||
Matrix4 Matrix4::LookAt(const Vector3 &cameraPos, const Vector3 &lookAtPos, const Vector3 &upDirection)
|
||||
{
|
||||
Matrix4 matLookat;
|
||||
Vector3 lookat_z_axis = lookAtPos - cameraPos;
|
||||
lookat_z_axis.normalize();
|
||||
Vector3 lookat_x_axis = Vector3::Cross(upDirection, lookat_z_axis);
|
||||
lookat_x_axis.normalize();
|
||||
Vector3 lookat_y_axis = Vector3::Cross(lookat_z_axis, lookat_x_axis);
|
||||
|
||||
matLookat.getPointer()[0] = lookat_x_axis.x;
|
||||
matLookat.getPointer()[1] = lookat_y_axis.x;
|
||||
matLookat.getPointer()[2] = lookat_z_axis.x;
|
||||
|
||||
matLookat.getPointer()[4] = lookat_x_axis.y;
|
||||
matLookat.getPointer()[5] = lookat_y_axis.y;
|
||||
matLookat.getPointer()[6] = lookat_z_axis.y;
|
||||
|
||||
matLookat.getPointer()[8] = lookat_x_axis.z;
|
||||
matLookat.getPointer()[9] = lookat_y_axis.z;
|
||||
matLookat.getPointer()[10] = lookat_z_axis.z;
|
||||
|
||||
matLookat.getPointer()[12] = -Vector3::Dot(lookat_x_axis, cameraPos);
|
||||
matLookat.getPointer()[13] = -Vector3::Dot(lookat_y_axis, cameraPos);
|
||||
matLookat.getPointer()[14] = -Vector3::Dot(lookat_z_axis, cameraPos);
|
||||
|
||||
return matLookat;
|
||||
}
|
||||
|
||||
Matrix4 Matrix4::Invert(const Matrix4 &m)
|
||||
{
|
||||
Matrix4 matInvert = m;
|
||||
matInvert.invert();
|
||||
return matInvert;
|
||||
}
|
||||
|
||||
Matrix4 Matrix4::Transpose(const Matrix4 &m)
|
||||
{
|
||||
Matrix4 matTranspose = m;
|
||||
matTranspose.transpose();
|
||||
return matTranspose;
|
||||
}
|
||||
|
||||
Matrix4 Matrix4::Translation(const Vector3 &v)
|
||||
{
|
||||
Matrix4 m;
|
||||
m[12] = v.x;
|
||||
m[13] = v.y;
|
||||
m[14] = v.z;
|
||||
// m.translate(v);
|
||||
return m;
|
||||
}
|
||||
|
||||
Matrix4 Matrix4::Rotation(const Vector3 &v)
|
||||
{
|
||||
Matrix4 m;
|
||||
m.rotate(v.x, X_AXIS);
|
||||
m.rotate(v.y, Y_AXIS);
|
||||
m.rotate(v.z, Z_AXIS);
|
||||
return m;
|
||||
}
|
||||
|
||||
Matrix4 Matrix4::Scaling(const Vector3 &v)
|
||||
{
|
||||
Matrix4 m;
|
||||
m.scale(v);
|
||||
return m;
|
||||
}
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
@@ -1,11 +1,2 @@
|
||||
add_public_header(kraken.h)
|
||||
add_public_header(scalar.h)
|
||||
add_public_header(vector2.h)
|
||||
add_public_header(vector3.h)
|
||||
add_public_header(vector4.h)
|
||||
add_public_header(triangle3.h)
|
||||
add_public_header(quaternion.h)
|
||||
add_public_header(aabb.h)
|
||||
add_public_header(matrix4.h)
|
||||
add_public_header(hitinfo.h)
|
||||
set(KRAKEN_PUBLIC_HEADERS "${KRAKEN_PUBLIC_HEADERS}" PARENT_SCOPE)
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
//
|
||||
// KRAABB.h
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2018 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.
|
||||
//
|
||||
|
||||
// Axis aligned bounding box (AABB)
|
||||
|
||||
#ifndef KRAKEN_AABB_H
|
||||
#define KRAKEN_AABB_H
|
||||
|
||||
#include <functional> // for hash<>
|
||||
|
||||
#include "vector2.h"
|
||||
#include "vector3.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
class Matrix4;
|
||||
|
||||
class AABB {
|
||||
public:
|
||||
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);
|
||||
|
||||
Vector3 center() const;
|
||||
Vector3 size() const;
|
||||
float volume() 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 AABB & b);
|
||||
|
||||
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 AABB& b) const;
|
||||
bool operator <(const AABB& b) const;
|
||||
|
||||
static AABB Infinite();
|
||||
static AABB Zero();
|
||||
|
||||
float longest_radius() const;
|
||||
Vector3 nearestPoint(const Vector3 & v) const;
|
||||
};
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<kraken::AABB> {
|
||||
public:
|
||||
size_t operator()(const kraken::AABB &s) const
|
||||
{
|
||||
size_t h1 = hash<kraken::Vector3>()(s.min);
|
||||
size_t h2 = hash<kraken::Vector3>()(s.max);
|
||||
return h1 ^ ( h2 << 1 );
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
|
||||
#endif /* defined(KRAKEN_AABB_H) */
|
||||
@@ -1,65 +0,0 @@
|
||||
//
|
||||
// hitinfo.h
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2018 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.
|
||||
//
|
||||
|
||||
#ifndef KRAKEN_HITINFO_H
|
||||
#define KRAKEN_HITINFO_H
|
||||
|
||||
#include "vector3.h"
|
||||
|
||||
class KRNode;
|
||||
|
||||
namespace kraken {
|
||||
|
||||
class HitInfo {
|
||||
public:
|
||||
HitInfo();
|
||||
HitInfo(const Vector3 &position, const Vector3 &normal, const float distance);
|
||||
HitInfo(const Vector3 &position, const Vector3 &normal, const float distance, KRNode *node);
|
||||
~HitInfo();
|
||||
|
||||
Vector3 getPosition() const;
|
||||
Vector3 getNormal() const;
|
||||
float getDistance() const;
|
||||
KRNode *getNode() const;
|
||||
bool didHit() const;
|
||||
|
||||
HitInfo& operator =(const HitInfo& b);
|
||||
|
||||
private:
|
||||
KRNode *m_node;
|
||||
Vector3 m_position;
|
||||
Vector3 m_normal;
|
||||
float m_distance;
|
||||
};
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
#endif
|
||||
@@ -31,14 +31,5 @@
|
||||
#ifndef KRAKEN_H
|
||||
#define KRAKEN_H
|
||||
|
||||
#include "scalar.h"
|
||||
#include "vector2.h"
|
||||
#include "vector3.h"
|
||||
#include "vector4.h"
|
||||
#include "matrix4.h"
|
||||
#include "quaternion.h"
|
||||
#include "aabb.h"
|
||||
#include "triangle3.h"
|
||||
#include "hitinfo.h"
|
||||
|
||||
#endif // KRAKEN_H
|
||||
|
||||
@@ -1,136 +0,0 @@
|
||||
//
|
||||
// Matrix4.h
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2018 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 "vector3.h"
|
||||
#include "vector4.h"
|
||||
|
||||
#ifndef KRAKEN_MATRIX4_H
|
||||
#define KRAKEN_MATRIX4_H
|
||||
|
||||
namespace kraken {
|
||||
|
||||
typedef enum {
|
||||
X_AXIS,
|
||||
Y_AXIS,
|
||||
Z_AXIS
|
||||
} AXIS;
|
||||
|
||||
class Quaternion;
|
||||
|
||||
class Matrix4 {
|
||||
public:
|
||||
|
||||
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 &new_axis_x, const Vector3 &new_axis_y, const Vector3 &new_axis_z, const Vector3 &new_transform);
|
||||
|
||||
// Destructor
|
||||
~Matrix4();
|
||||
|
||||
// Copy constructor
|
||||
Matrix4(const Matrix4 &m);
|
||||
|
||||
// Overload assignment operator
|
||||
Matrix4& operator=(const Matrix4 &m);
|
||||
|
||||
// Overload comparison operator
|
||||
bool operator==(const Matrix4 &m) const;
|
||||
|
||||
// Overload compound multiply operator
|
||||
Matrix4& operator*=(const Matrix4 &m);
|
||||
|
||||
float& operator[](unsigned i);
|
||||
float operator[](unsigned i) const;
|
||||
|
||||
// Overload multiply operator
|
||||
//Matrix4& operator*(const Matrix4 &m);
|
||||
Matrix4 operator*(const Matrix4 &m) const;
|
||||
|
||||
float *getPointer();
|
||||
|
||||
void perspective(float fov, float aspect, float nearz, float farz);
|
||||
void ortho(float left, float right, float top, float bottom, float nearz, float farz);
|
||||
void translate(float x, float y, float z);
|
||||
void translate(const Vector3 &v);
|
||||
void scale(float x, float y, float z);
|
||||
void scale(const Vector3 &v);
|
||||
void scale(float s);
|
||||
void rotate(float angle, AXIS axis);
|
||||
void rotate(const Quaternion &q);
|
||||
void bias();
|
||||
bool invert();
|
||||
void transpose();
|
||||
|
||||
static Vector3 DotNoTranslate(const Matrix4 &m, const Vector3 &v); // Dot product without including translation; useful for transforming normals and tangents
|
||||
static Matrix4 Invert(const Matrix4 &m);
|
||||
static Matrix4 Transpose(const Matrix4 &m);
|
||||
static Vector3 Dot(const Matrix4 &m, const Vector3 &v);
|
||||
static Vector4 Dot4(const Matrix4 &m, const Vector4 &v);
|
||||
static float DotW(const Matrix4 &m, const Vector3 &v);
|
||||
static Vector3 DotWDiv(const Matrix4 &m, const Vector3 &v);
|
||||
|
||||
static Matrix4 LookAt(const Vector3 &cameraPos, const Vector3 &lookAtPos, const Vector3 &upDirection);
|
||||
|
||||
static Matrix4 Translation(const Vector3 &v);
|
||||
static Matrix4 Rotation(const Vector3 &v);
|
||||
static Matrix4 Scaling(const Vector3 &v);
|
||||
};
|
||||
|
||||
} // 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
|
||||
@@ -1,110 +0,0 @@
|
||||
//
|
||||
// Quaternion.h
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2018 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.
|
||||
//
|
||||
|
||||
#ifndef KRAKEN_QUATERNION_H
|
||||
#define KRAKEN_QUATERNION_H
|
||||
|
||||
#include "vector3.h"
|
||||
|
||||
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);
|
||||
Quaternion(const Vector3 &euler);
|
||||
Quaternion(const Vector3 &from_vector, const Vector3 &to_vector);
|
||||
~Quaternion();
|
||||
|
||||
Quaternion& operator =( const Quaternion& p );
|
||||
Quaternion operator +(const Quaternion &v) const;
|
||||
Quaternion operator -(const Quaternion &v) const;
|
||||
Quaternion operator +() const;
|
||||
Quaternion operator -() const;
|
||||
|
||||
Quaternion operator *(const Quaternion &v);
|
||||
Quaternion operator *(float num) const;
|
||||
Quaternion operator /(float num) const;
|
||||
|
||||
Quaternion& operator +=(const Quaternion& v);
|
||||
Quaternion& operator -=(const Quaternion& v);
|
||||
Quaternion& operator *=(const Quaternion& v);
|
||||
Quaternion& operator *=(const float& v);
|
||||
Quaternion& operator /=(const float& v);
|
||||
|
||||
friend bool operator ==(Quaternion &v1, Quaternion &v2);
|
||||
friend bool operator !=(Quaternion &v1, Quaternion &v2);
|
||||
float& operator [](unsigned i);
|
||||
float operator [](unsigned i) const;
|
||||
|
||||
void setEulerXYZ(const Vector3 &euler);
|
||||
void setEulerZYX(const Vector3 &euler);
|
||||
Vector3 eulerXYZ() const;
|
||||
Matrix4 rotationMatrix() const;
|
||||
|
||||
void normalize();
|
||||
static Quaternion Normalize(const Quaternion &v1);
|
||||
|
||||
void conjugate();
|
||||
static Quaternion Conjugate(const Quaternion &v1);
|
||||
|
||||
static Quaternion FromAngleAxis(const Vector3 &axis, float angle);
|
||||
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);
|
||||
};
|
||||
|
||||
} // 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
|
||||
@@ -1,41 +0,0 @@
|
||||
//
|
||||
// KRFloat.h
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2018 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.
|
||||
//
|
||||
|
||||
#ifndef KRAKEN_SCALAR_H
|
||||
#define KRAKEN_SCALAR_H
|
||||
|
||||
namespace kraken {
|
||||
|
||||
float SmoothStep(float a, float b, float t);
|
||||
|
||||
}; // namespace kraken
|
||||
|
||||
#endif // KRAKEN_SCALAR_H
|
||||
@@ -1,79 +0,0 @@
|
||||
//
|
||||
// KRTriangle.h
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2018 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.
|
||||
//
|
||||
|
||||
#ifndef KRAKEN_TRIANGLE3_H
|
||||
#define KRAKEN_TRIANGLE3_H
|
||||
|
||||
#include "vector3.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
class Triangle3
|
||||
{
|
||||
public:
|
||||
Vector3 vert[3];
|
||||
|
||||
Triangle3(const Triangle3 &tri);
|
||||
Triangle3(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3);
|
||||
~Triangle3();
|
||||
|
||||
Vector3 calculateNormal() const;
|
||||
|
||||
bool operator ==(const Triangle3& b) const;
|
||||
bool operator !=(const Triangle3& b) const;
|
||||
Triangle3& operator =(const Triangle3& b);
|
||||
Vector3& operator[](unsigned int i);
|
||||
Vector3 operator[](unsigned int i) const;
|
||||
|
||||
bool rayCast(const Vector3 &start, const Vector3 &dir, Vector3 &hit_point) const;
|
||||
bool sphereCast(const Vector3 &start, const Vector3 &dir, float radius, Vector3 &hit_point, float &hit_distance) const;
|
||||
|
||||
bool containsPoint(const Vector3 &p) const;
|
||||
Vector3 closestPointOnTriangle(const Vector3 &p) const;
|
||||
};
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<kraken::Triangle3> {
|
||||
public:
|
||||
size_t operator()(const kraken::Triangle3 &s) const
|
||||
{
|
||||
size_t h1 = hash<kraken::Vector3>()(s.vert[0]);
|
||||
size_t h2 = hash<kraken::Vector3>()(s.vert[1]);
|
||||
size_t h3 = hash<kraken::Vector3>()(s.vert[2]);
|
||||
return h1 ^ (h2 << 1) ^ (h3 << 2);
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#endif // KRAKEN_TRIANGLE3_H
|
||||
@@ -1,117 +0,0 @@
|
||||
//
|
||||
// vector2.h
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2018 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.
|
||||
//
|
||||
|
||||
#ifndef KRAKEN_VECTOR2_H
|
||||
#define KRAKEN_VECTOR2_H
|
||||
|
||||
#include <functional> // for hash<>
|
||||
#include <limits> // for std::numeric_limits<>
|
||||
#include <math.h> // for sqrtf
|
||||
|
||||
namespace kraken {
|
||||
|
||||
class Vector2 {
|
||||
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
float x, y;
|
||||
};
|
||||
float c[2];
|
||||
};
|
||||
|
||||
Vector2();
|
||||
Vector2(float X, float Y);
|
||||
Vector2(float v);
|
||||
Vector2(float *v);
|
||||
Vector2(const Vector2 &v);
|
||||
~Vector2();
|
||||
|
||||
// Vector2 swizzle getters
|
||||
Vector2 yx() const;
|
||||
|
||||
// Vector2 swizzle setters
|
||||
void yx(const Vector2 &v);
|
||||
|
||||
Vector2& operator =(const Vector2& b);
|
||||
Vector2 operator +(const Vector2& b) const;
|
||||
Vector2 operator -(const Vector2& b) const;
|
||||
Vector2 operator +() const;
|
||||
Vector2 operator -() const;
|
||||
Vector2 operator *(const float v) const;
|
||||
Vector2 operator /(const float v) const;
|
||||
|
||||
Vector2& operator +=(const Vector2& b);
|
||||
Vector2& operator -=(const Vector2& b);
|
||||
Vector2& operator *=(const float v);
|
||||
Vector2& operator /=(const float v);
|
||||
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
bool operator >(const Vector2& b) const;
|
||||
bool operator <(const Vector2& b) const;
|
||||
|
||||
bool operator ==(const Vector2& b) const;
|
||||
bool operator !=(const Vector2& b) const;
|
||||
|
||||
float& operator[](unsigned i);
|
||||
float operator[](unsigned i) const;
|
||||
|
||||
float sqrMagnitude() const;
|
||||
float magnitude() const;
|
||||
|
||||
void normalize();
|
||||
static Vector2 Normalize(const Vector2 &v);
|
||||
|
||||
static float Cross(const Vector2 &v1, const Vector2 &v2);
|
||||
|
||||
static float Dot(const Vector2 &v1, const Vector2 &v2);
|
||||
static Vector2 Min();
|
||||
static Vector2 Max();
|
||||
static Vector2 Zero();
|
||||
static Vector2 One();
|
||||
};
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<kraken::Vector2> {
|
||||
public:
|
||||
size_t operator()(const kraken::Vector2 &s) const
|
||||
{
|
||||
size_t h1 = hash<float>()(s.x);
|
||||
size_t h2 = hash<float>()(s.y);
|
||||
return h1 ^ (h2 << 1);
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#endif // KRAKEN_VECTOR2_H
|
||||
@@ -1,146 +0,0 @@
|
||||
//
|
||||
// Vector3.h
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2018 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.
|
||||
//
|
||||
|
||||
#ifndef KRAKEN_VECTOR3_H
|
||||
#define KRAKEN_VECTOR3_H
|
||||
|
||||
#include <functional> // for hash<>
|
||||
|
||||
#include "vector2.h"
|
||||
#include "vector4.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
class Vector3 {
|
||||
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
float x, y, z;
|
||||
};
|
||||
float c[3];
|
||||
};
|
||||
|
||||
Vector3();
|
||||
Vector3(float X, float Y, float Z);
|
||||
Vector3(float v);
|
||||
Vector3(float *v);
|
||||
Vector3(double *v);
|
||||
Vector3(const Vector3 &v);
|
||||
Vector3(const Vector4 &v);
|
||||
~Vector3();
|
||||
|
||||
// Vector2 swizzle getters
|
||||
Vector2 xx() const;
|
||||
Vector2 xy() const;
|
||||
Vector2 xz() const;
|
||||
Vector2 yx() const;
|
||||
Vector2 yy() const;
|
||||
Vector2 yz() const;
|
||||
Vector2 zx() const;
|
||||
Vector2 zy() const;
|
||||
Vector2 zz() const;
|
||||
|
||||
// Vector2 swizzle setters
|
||||
void xy(const Vector2 &v);
|
||||
void xz(const Vector2 &v);
|
||||
void yx(const Vector2 &v);
|
||||
void yz(const Vector2 &v);
|
||||
void zx(const Vector2 &v);
|
||||
void zy(const Vector2 &v);
|
||||
|
||||
Vector3& operator =(const Vector3& b);
|
||||
Vector3& operator =(const Vector4& b);
|
||||
Vector3 operator +(const Vector3& b) const;
|
||||
Vector3 operator -(const Vector3& b) const;
|
||||
Vector3 operator +() const;
|
||||
Vector3 operator -() const;
|
||||
Vector3 operator *(const float v) const;
|
||||
Vector3 operator /(const float v) const;
|
||||
|
||||
Vector3& operator +=(const Vector3& b);
|
||||
Vector3& operator -=(const Vector3& b);
|
||||
Vector3& operator *=(const float v);
|
||||
Vector3& operator /=(const float v);
|
||||
|
||||
bool operator ==(const Vector3& b) const;
|
||||
bool operator !=(const Vector3& b) const;
|
||||
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
bool operator >(const Vector3& b) const;
|
||||
bool operator <(const Vector3& b) const;
|
||||
|
||||
float& operator[](unsigned i);
|
||||
float operator[](unsigned i) const;
|
||||
|
||||
float sqrMagnitude() const; // calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function)
|
||||
float magnitude() const;
|
||||
|
||||
void scale(const Vector3 &v);
|
||||
void normalize();
|
||||
static Vector3 Normalize(const Vector3 &v);
|
||||
|
||||
static Vector3 Cross(const Vector3 &v1, const Vector3 &v2);
|
||||
|
||||
static float Dot(const Vector3 &v1, const Vector3 &v2);
|
||||
static Vector3 Min();
|
||||
static Vector3 Max();
|
||||
static const Vector3 &Zero();
|
||||
static Vector3 One();
|
||||
static Vector3 Forward();
|
||||
static Vector3 Backward();
|
||||
static Vector3 Up();
|
||||
static Vector3 Down();
|
||||
static Vector3 Left();
|
||||
static Vector3 Right();
|
||||
static Vector3 Scale(const Vector3 &v1, const Vector3 &v2);
|
||||
static Vector3 Lerp(const Vector3 &v1, const Vector3 &v2, float d);
|
||||
static Vector3 Slerp(const Vector3 &v1, const Vector3 &v2, float d);
|
||||
static void OrthoNormalize(Vector3 &normal, Vector3 &tangent); // Gram-Schmidt Orthonormalization
|
||||
};
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<kraken::Vector3> {
|
||||
public:
|
||||
size_t operator()(const kraken::Vector3 &s) const
|
||||
{
|
||||
size_t h1 = hash<float>()(s.x);
|
||||
size_t h2 = hash<float>()(s.y);
|
||||
size_t h3 = hash<float>()(s.z);
|
||||
return h1 ^ (h2 << 1) ^ (h3 << 2);
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#endif // KRAKEN_VECTOR3_H
|
||||
@@ -1,122 +0,0 @@
|
||||
//
|
||||
// Vector4.h
|
||||
// Kraken
|
||||
//
|
||||
// Copyright 2018 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.
|
||||
//
|
||||
|
||||
#ifndef KRAKEN_VECTOR4_H
|
||||
#define KRAKEN_VECTOR4_H
|
||||
|
||||
#include <functional> // for hash<>
|
||||
|
||||
namespace kraken {
|
||||
|
||||
class Vector3;
|
||||
|
||||
class Vector4 {
|
||||
|
||||
public:
|
||||
union {
|
||||
struct {
|
||||
float x, y, z, w;
|
||||
};
|
||||
float c[4];
|
||||
};
|
||||
|
||||
Vector4();
|
||||
Vector4(float X, float Y, float Z, float W);
|
||||
Vector4(float v);
|
||||
Vector4(float *v);
|
||||
Vector4(const Vector4 &v);
|
||||
Vector4(const Vector3 &v, float W);
|
||||
~Vector4();
|
||||
|
||||
|
||||
Vector4& operator =(const Vector4& b);
|
||||
Vector4 operator +(const Vector4& b) const;
|
||||
Vector4 operator -(const Vector4& b) const;
|
||||
Vector4 operator +() const;
|
||||
Vector4 operator -() const;
|
||||
Vector4 operator *(const float v) const;
|
||||
Vector4 operator /(const float v) const;
|
||||
|
||||
Vector4& operator +=(const Vector4& b);
|
||||
Vector4& operator -=(const Vector4& b);
|
||||
Vector4& operator *=(const float v);
|
||||
Vector4& operator /=(const float v);
|
||||
|
||||
bool operator ==(const Vector4& b) const;
|
||||
bool operator !=(const Vector4& b) const;
|
||||
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
bool operator >(const Vector4& b) const;
|
||||
bool operator <(const Vector4& b) const;
|
||||
|
||||
float& operator[](unsigned i);
|
||||
float operator[](unsigned i) const;
|
||||
|
||||
float sqrMagnitude() const; // calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function)
|
||||
float magnitude() const;
|
||||
|
||||
void normalize();
|
||||
static Vector4 Normalize(const Vector4 &v);
|
||||
|
||||
static float Dot(const Vector4 &v1, const Vector4 &v2);
|
||||
static Vector4 Min();
|
||||
static Vector4 Max();
|
||||
static const Vector4 &Zero();
|
||||
static Vector4 One();
|
||||
static Vector4 Forward();
|
||||
static Vector4 Backward();
|
||||
static Vector4 Up();
|
||||
static Vector4 Down();
|
||||
static Vector4 Left();
|
||||
static Vector4 Right();
|
||||
static Vector4 Lerp(const Vector4 &v1, const Vector4 &v2, float d);
|
||||
static Vector4 Slerp(const Vector4 &v1, const Vector4 &v2, float d);
|
||||
static void OrthoNormalize(Vector4 &normal, Vector4 &tangent); // Gram-Schmidt Orthonormalization
|
||||
};
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<kraken::Vector4> {
|
||||
public:
|
||||
size_t operator()(const kraken::Vector4 &s) const
|
||||
{
|
||||
size_t h1 = hash<float>()(s.x);
|
||||
size_t h2 = hash<float>()(s.y);
|
||||
size_t h3 = hash<float>()(s.z);
|
||||
size_t h4 = hash<float>()(s.w);
|
||||
return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3);
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
#endif // KRAKEN_VECTOR4_H
|
||||
@@ -1,365 +0,0 @@
|
||||
//
|
||||
// Quaternion.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 "public/kraken.h"
|
||||
|
||||
#include "KRHelpers.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
Quaternion::Quaternion() {
|
||||
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) {
|
||||
c[0] = w;
|
||||
c[1] = x;
|
||||
c[2] = y;
|
||||
c[3] = z;
|
||||
}
|
||||
|
||||
Quaternion::Quaternion(const Quaternion& p) {
|
||||
c[0] = p[0];
|
||||
c[1] = p[1];
|
||||
c[2] = p[2];
|
||||
c[3] = p[3];
|
||||
}
|
||||
|
||||
Quaternion& Quaternion::operator =( const Quaternion& p ) {
|
||||
c[0] = p[0];
|
||||
c[1] = p[1];
|
||||
c[2] = p[2];
|
||||
c[3] = p[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
Quaternion::Quaternion(const Vector3 &euler) {
|
||||
setEulerZYX(euler);
|
||||
}
|
||||
|
||||
Quaternion::Quaternion(const Vector3 &from_vector, const Vector3 &to_vector) {
|
||||
|
||||
Vector3 a = Vector3::Cross(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();
|
||||
}
|
||||
|
||||
Quaternion::~Quaternion() {
|
||||
|
||||
}
|
||||
|
||||
void Quaternion::setEulerXYZ(const Vector3 &euler)
|
||||
{
|
||||
*this = Quaternion::FromAngleAxis(Vector3(1.0f, 0.0f, 0.0f), euler.x)
|
||||
* Quaternion::FromAngleAxis(Vector3(0.0f, 1.0f, 0.0f), euler.y)
|
||||
* Quaternion::FromAngleAxis(Vector3(0.0f, 0.0f, 1.0f), euler.z);
|
||||
}
|
||||
|
||||
void Quaternion::setEulerZYX(const Vector3 &euler) {
|
||||
// ZYX Order!
|
||||
float c1 = cos(euler[0] * 0.5f);
|
||||
float c2 = cos(euler[1] * 0.5f);
|
||||
float c3 = cos(euler[2] * 0.5f);
|
||||
float s1 = sin(euler[0] * 0.5f);
|
||||
float s2 = sin(euler[1] * 0.5f);
|
||||
float s3 = sin(euler[2] * 0.5f);
|
||||
|
||||
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 c[i];
|
||||
}
|
||||
|
||||
float &Quaternion::operator [](unsigned i) {
|
||||
return c[i];
|
||||
}
|
||||
|
||||
Vector3 Quaternion::eulerXYZ() const {
|
||||
double a2 = 2 * (c[0] * c[2] - c[1] * c[3]);
|
||||
if(a2 <= -0.99999) {
|
||||
return Vector3(
|
||||
2.0 * atan2(c[1], c[0]),
|
||||
-PI * 0.5f,
|
||||
0
|
||||
);
|
||||
} else if(a2 >= 0.99999) {
|
||||
return Vector3(
|
||||
2.0 * atan2(c[1], c[0]),
|
||||
PI * 0.5f,
|
||||
0
|
||||
);
|
||||
} else {
|
||||
return Vector3(
|
||||
atan2(2 * (c[0] * c[1] + c[2] * c[3]), (1 - 2 * (c[1] * c[1] + c[2] * c[2]))),
|
||||
asin(a2),
|
||||
atan2(2 * (c[0] * c[3] + c[1] * c[2]), (1 - 2 * (c[2] * c[2] + c[3] * c[3])))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool operator ==(Quaternion &v1, Quaternion &v2) {
|
||||
return
|
||||
v1[0] == v2[0]
|
||||
&& v1[1] == v2[1]
|
||||
&& v1[2] == v2[2]
|
||||
&& v1[3] == v2[3];
|
||||
}
|
||||
|
||||
bool operator !=(Quaternion &v1, Quaternion &v2) {
|
||||
return
|
||||
v1[0] != v2[0]
|
||||
|| v1[1] != v2[1]
|
||||
|| v1[2] != v2[2]
|
||||
|| v1[3] != v2[3];
|
||||
}
|
||||
|
||||
Quaternion Quaternion::operator *(const Quaternion &v) {
|
||||
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;
|
||||
|
||||
return Quaternion(
|
||||
t0+t9-t5,
|
||||
t1+t9-t8,
|
||||
t2+t9-t7,
|
||||
t3+t9-t6
|
||||
);
|
||||
}
|
||||
|
||||
Quaternion Quaternion::operator *(float v) const {
|
||||
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(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(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(c[0] - v[0], c[1] - v[1], c[2] - v[2], c[3] - v[3]);
|
||||
}
|
||||
|
||||
Quaternion& Quaternion::operator +=(const Quaternion& v) {
|
||||
c[0] += v[0];
|
||||
c[1] += v[1];
|
||||
c[2] += v[2];
|
||||
c[3] += v[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
Quaternion& Quaternion::operator -=(const Quaternion& v) {
|
||||
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 = (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;
|
||||
|
||||
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) {
|
||||
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;
|
||||
c[0] *= inv_v;
|
||||
c[1] *= inv_v;
|
||||
c[2] *= inv_v;
|
||||
c[3] *= inv_v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Quaternion Quaternion::operator +() const {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Quaternion Quaternion::operator -() const {
|
||||
return Quaternion(-c[0], -c[1], -c[2], -c[3]);
|
||||
}
|
||||
|
||||
Quaternion Normalize(const Quaternion &v1) {
|
||||
float inv_magnitude = 1.0f / sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]);
|
||||
return Quaternion(
|
||||
v1[0] * inv_magnitude,
|
||||
v1[1] * inv_magnitude,
|
||||
v1[2] * inv_magnitude,
|
||||
v1[3] * inv_magnitude
|
||||
);
|
||||
}
|
||||
|
||||
void Quaternion::normalize() {
|
||||
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) {
|
||||
return Quaternion(v1[0], -v1[1], -v1[2], -v1[3]);
|
||||
}
|
||||
|
||||
void Quaternion::conjugate() {
|
||||
c[1] = -c[1];
|
||||
c[2] = -c[2];
|
||||
c[3] = -c[3];
|
||||
}
|
||||
|
||||
Matrix4 Quaternion::rotationMatrix() const {
|
||||
Matrix4 matRotate;
|
||||
|
||||
/*
|
||||
Vector3 euler = eulerXYZ();
|
||||
|
||||
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.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 * (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 * (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;
|
||||
}
|
||||
|
||||
|
||||
Quaternion Quaternion::FromAngleAxis(const Vector3 &axis, float angle)
|
||||
{
|
||||
float ha = angle * 0.5f;
|
||||
float sha = sin(ha);
|
||||
return Quaternion(cos(ha), axis.x * sha, axis.y * sha, axis.z * sha);
|
||||
}
|
||||
|
||||
float Quaternion::Dot(const Quaternion &v1, const Quaternion &v2)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (t <= 0.0f) {
|
||||
return a;
|
||||
} else if (t >= 1.0f) {
|
||||
return b;
|
||||
}
|
||||
|
||||
return a * (1.0f - t) + b * t;
|
||||
}
|
||||
|
||||
Quaternion Quaternion::Slerp(const Quaternion &a, const Quaternion &b, float t)
|
||||
{
|
||||
if (t <= 0.0f) {
|
||||
return a;
|
||||
}
|
||||
|
||||
if (t >= 1.0f) {
|
||||
return b;
|
||||
}
|
||||
|
||||
float coshalftheta = Dot(a, b);
|
||||
Quaternion c = a;
|
||||
|
||||
// Angle is greater than 180. We can negate the angle/quat to get the
|
||||
// shorter rotation to reach the same destination.
|
||||
if ( coshalftheta < 0.0f ) {
|
||||
coshalftheta = -coshalftheta;
|
||||
c = -c;
|
||||
}
|
||||
|
||||
if ( coshalftheta > (1.0f - std::numeric_limits<float>::epsilon())) {
|
||||
// Angle is tiny - save some computation by lerping instead.
|
||||
return Lerp(c, b, t);
|
||||
}
|
||||
|
||||
float halftheta = acos(coshalftheta);
|
||||
|
||||
return (c * sin((1.0f - t) * halftheta) + b * sin(t * halftheta)) / sin(halftheta);
|
||||
}
|
||||
|
||||
} // namespace kraken
|
||||
@@ -1,19 +0,0 @@
|
||||
//
|
||||
// KRFloat.cpp
|
||||
// Kraken
|
||||
//
|
||||
// Created by Kearwood Gilbert on 2013-05-03.
|
||||
// Copyright (c) 2013 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
#include "public/kraken.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
float 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;
|
||||
}
|
||||
|
||||
} // namespace kraken
|
||||
@@ -1,331 +0,0 @@
|
||||
//
|
||||
// KRTriangle.cpp
|
||||
// Kraken
|
||||
//
|
||||
// Created by Kearwood Gilbert on 2/8/2014.
|
||||
// Copyright (c) 2014 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
#include "public/kraken.h"
|
||||
|
||||
using namespace kraken;
|
||||
|
||||
namespace {
|
||||
bool _intersectSphere(const Vector3 &start, const Vector3 &dir, const Vector3 &sphere_center, float sphere_radius, float &distance)
|
||||
{
|
||||
// dir must be normalized
|
||||
|
||||
// From: http://archive.gamedev.net/archive/reference/articles/article1026.html
|
||||
|
||||
// TODO - Move to another class?
|
||||
Vector3 Q = sphere_center - start;
|
||||
float c = Q.magnitude();
|
||||
float v = Vector3::Dot(Q, dir);
|
||||
float d = sphere_radius * sphere_radius - (c * c - v * v);
|
||||
|
||||
|
||||
|
||||
if (d < 0.0) {
|
||||
// No intersection
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return the distance to the [first] intersecting point
|
||||
|
||||
distance = v - sqrt(d);
|
||||
if (distance < 0.0f) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
bool _sameSide(const Vector3 &p1, const Vector3 &p2, const Vector3 &a, const Vector3 &b)
|
||||
{
|
||||
// TODO - Move to Vector3 class?
|
||||
// From: http://stackoverflow.com/questions/995445/determine-if-a-3d-point-is-within-a-triangle
|
||||
|
||||
Vector3 cp1 = Vector3::Cross(b - a, p1 - a);
|
||||
Vector3 cp2 = Vector3::Cross(b - a, p2 - a);
|
||||
if (Vector3::Dot(cp1, cp2) >= 0) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector3 _closestPointOnLine(const Vector3 &a, const Vector3 &b, const Vector3 &p)
|
||||
{
|
||||
// From: http://stackoverflow.com/questions/995445/determine-if-a-3d-point-is-within-a-triangle
|
||||
|
||||
// Determine t (the length of the vector from ‘a’ to ‘p’)
|
||||
|
||||
Vector3 c = p - a;
|
||||
Vector3 V = Vector3::Normalize(b - a);
|
||||
float d = (a - b).magnitude();
|
||||
float t = Vector3::Dot(V, c);
|
||||
|
||||
// Check to see if ‘t’ is beyond the extents of the line segment
|
||||
|
||||
if (t < 0) return a;
|
||||
if (t > d) return b;
|
||||
|
||||
// Return the point between ‘a’ and ‘b’
|
||||
|
||||
return a + V * t;
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
namespace kraken {
|
||||
|
||||
Triangle3::Triangle3(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
|
||||
{
|
||||
vert[0] = v1;
|
||||
vert[1] = v2;
|
||||
vert[2] = v3;
|
||||
}
|
||||
|
||||
Triangle3::Triangle3(const Triangle3 &tri)
|
||||
{
|
||||
vert[0] = tri[0];
|
||||
vert[1] = tri[1];
|
||||
vert[3] = tri[3];
|
||||
}
|
||||
|
||||
|
||||
Triangle3::~Triangle3()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool Triangle3::operator ==(const Triangle3& b) const
|
||||
{
|
||||
return vert[0] == b[0] && vert[1] == b[1] && vert[2] == b[2];
|
||||
}
|
||||
|
||||
bool Triangle3::operator !=(const Triangle3& b) const
|
||||
{
|
||||
return vert[0] != b[0] || vert[1] != b[1] || vert[2] != b[2];
|
||||
}
|
||||
|
||||
Triangle3& Triangle3::operator =(const Triangle3& b)
|
||||
{
|
||||
|
||||
vert[0] = b[0];
|
||||
vert[1] = b[1];
|
||||
vert[3] = b[3];
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector3& Triangle3::operator[](unsigned int i)
|
||||
{
|
||||
return vert[i];
|
||||
}
|
||||
|
||||
Vector3 Triangle3::operator[](unsigned int i) const
|
||||
{
|
||||
return vert[i];
|
||||
}
|
||||
|
||||
|
||||
bool Triangle3::rayCast(const Vector3 &start, const Vector3 &dir, Vector3 &hit_point) const
|
||||
{
|
||||
// algorithm based on Dan Sunday's implementation at http://geomalgorithms.com/a06-_intersect-2.html
|
||||
const float SMALL_NUM = 0.00000001; // anything that avoids division overflow
|
||||
Vector3 u, v, n; // triangle vectors
|
||||
Vector3 w0, w; // ray vectors
|
||||
float r, a, b; // params to calc ray-plane intersect
|
||||
|
||||
// get triangle edge vectors and plane normal
|
||||
u = vert[1] - vert[0];
|
||||
v = vert[2] - vert[0];
|
||||
n = Vector3::Cross(u, v); // cross product
|
||||
if (n == Vector3::Zero()) // triangle is degenerate
|
||||
return false; // do not deal with this case
|
||||
|
||||
w0 = start - vert[0];
|
||||
a = -Vector3::Dot(n, w0);
|
||||
b = Vector3::Dot(n,dir);
|
||||
if (fabs(b) < SMALL_NUM) { // ray is parallel to triangle plane
|
||||
if (a == 0)
|
||||
return false; // ray lies in triangle plane
|
||||
else {
|
||||
return false; // ray disjoint from plane
|
||||
}
|
||||
}
|
||||
|
||||
// get intersect point of ray with triangle plane
|
||||
r = a / b;
|
||||
if (r < 0.0) // ray goes away from triangle
|
||||
return false; // => no intersect
|
||||
// for a segment, also test if (r > 1.0) => no intersect
|
||||
|
||||
|
||||
Vector3 plane_hit_point = start + dir * r; // intersect point of ray and plane
|
||||
|
||||
// is plane_hit_point inside triangle?
|
||||
float uu, uv, vv, wu, wv, D;
|
||||
uu = Vector3::Dot(u,u);
|
||||
uv = Vector3::Dot(u,v);
|
||||
vv = Vector3::Dot(v,v);
|
||||
w = plane_hit_point - vert[0];
|
||||
wu = Vector3::Dot(w,u);
|
||||
wv = Vector3::Dot(w,v);
|
||||
D = uv * uv - uu * vv;
|
||||
|
||||
// get and test parametric coords
|
||||
float s, t;
|
||||
s = (uv * wv - vv * wu) / D;
|
||||
if (s < 0.0 || s > 1.0) // plane_hit_point is outside triangle
|
||||
return false;
|
||||
t = (uv * wu - uu * wv) / D;
|
||||
if (t < 0.0 || (s + t) > 1.0) // plane_hit_point is outside triangle
|
||||
return false;
|
||||
|
||||
// plane_hit_point is inside the triangle
|
||||
hit_point = plane_hit_point;
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector3 Triangle3::calculateNormal() const
|
||||
{
|
||||
Vector3 v1 = vert[1] - vert[0];
|
||||
Vector3 v2 = vert[2] - vert[0];
|
||||
|
||||
return Vector3::Normalize(Vector3::Cross(v1, v2));
|
||||
}
|
||||
|
||||
Vector3 Triangle3::closestPointOnTriangle(const Vector3 &p) const
|
||||
{
|
||||
Vector3 a = vert[0];
|
||||
Vector3 b = vert[1];
|
||||
Vector3 c = vert[2];
|
||||
|
||||
Vector3 Rab = _closestPointOnLine(a, b, p);
|
||||
Vector3 Rbc = _closestPointOnLine(b, c, p);
|
||||
Vector3 Rca = _closestPointOnLine(c, a, p);
|
||||
|
||||
// return closest [Rab, Rbc, Rca] to p;
|
||||
float sd_Rab = (p - Rab).sqrMagnitude();
|
||||
float sd_Rbc = (p - Rbc).sqrMagnitude();
|
||||
float sd_Rca = (p - Rca).sqrMagnitude();
|
||||
|
||||
if(sd_Rab < sd_Rbc && sd_Rab < sd_Rca) {
|
||||
return Rab;
|
||||
} else if(sd_Rbc < sd_Rab && sd_Rbc < sd_Rca) {
|
||||
return Rbc;
|
||||
} else {
|
||||
return Rca;
|
||||
}
|
||||
}
|
||||
|
||||
bool Triangle3::sphereCast(const Vector3 &start, const Vector3 &dir, float radius, Vector3 &hit_point, float &hit_distance) const
|
||||
{
|
||||
// Dir must be normalized
|
||||
const float SMALL_NUM = 0.001f; // anything that avoids division overflow
|
||||
|
||||
Vector3 tri_normal = calculateNormal();
|
||||
|
||||
float d = Vector3::Dot(tri_normal, vert[0]);
|
||||
float e = Vector3::Dot(tri_normal, start) - radius;
|
||||
float cotangent_distance = e - d;
|
||||
|
||||
Vector3 plane_intersect;
|
||||
float plane_intersect_distance;
|
||||
|
||||
float denom = Vector3::Dot(tri_normal, dir);
|
||||
|
||||
if(denom > -SMALL_NUM) {
|
||||
return false; // dir is co-planar with the triangle or going in the direction of the normal; no intersection
|
||||
}
|
||||
|
||||
// Detect an embedded plane, caused by a sphere that is already intersecting the plane.
|
||||
if(cotangent_distance <= 0 && cotangent_distance >= -radius * 2.0f) {
|
||||
// Embedded plane - Sphere is already intersecting the plane.
|
||||
// Use the point closest to the origin of the sphere as the intersection
|
||||
plane_intersect = start - tri_normal * (cotangent_distance + radius);
|
||||
plane_intersect_distance = 0.0f;
|
||||
} else {
|
||||
// Sphere is not intersecting the plane
|
||||
// Determine the first point hit by the swept sphere on the triangle's plane
|
||||
|
||||
plane_intersect_distance = -(cotangent_distance / denom);
|
||||
plane_intersect = start + dir * plane_intersect_distance - tri_normal * radius;
|
||||
}
|
||||
|
||||
if(plane_intersect_distance < 0.0f) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(containsPoint(plane_intersect)) {
|
||||
// Triangle contains point
|
||||
hit_point = plane_intersect;
|
||||
hit_distance = plane_intersect_distance;
|
||||
return true;
|
||||
} else {
|
||||
// Triangle does not contain point, cast ray back to sphere from closest point on triangle edge or vertice
|
||||
Vector3 closest_point = closestPointOnTriangle(plane_intersect);
|
||||
float reverse_hit_distance;
|
||||
if(_intersectSphere(closest_point, -dir, start, radius, reverse_hit_distance)) {
|
||||
// Reverse cast hit sphere
|
||||
hit_distance = reverse_hit_distance;
|
||||
hit_point = closest_point;
|
||||
return true;
|
||||
} else {
|
||||
// Reverse cast did not hit sphere
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Triangle3::containsPoint(const Vector3 &p) const
|
||||
{
|
||||
/*
|
||||
// From: http://stackoverflow.com/questions/995445/determine-if-a-3d-point-is-within-a-triangle
|
||||
|
||||
const float SMALL_NUM = 0.00000001f; // anything that avoids division overflow
|
||||
// Vector3 A = vert[0], B = vert[1], C = vert[2];
|
||||
if (_sameSide(p, vert[0], vert[1], vert[2]) && _sameSide(p, vert[1], vert[0], vert[2]) && _sameSide(p, vert[2], vert[0], vert[1])) {
|
||||
Vector3 vc1 = Vector3::Cross(vert[0] - vert[1], vert[0] - vert[2]);
|
||||
if(fabs(Vector3::Dot(vert[0] - p, vc1)) <= SMALL_NUM) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
*/
|
||||
|
||||
// From: http://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspx
|
||||
|
||||
Vector3 A = vert[0];
|
||||
Vector3 B = vert[1];
|
||||
Vector3 C = vert[2];
|
||||
Vector3 P = p;
|
||||
|
||||
// Prepare our barycentric variables
|
||||
Vector3 u = B - A;
|
||||
Vector3 v = C - A;
|
||||
Vector3 w = P - A;
|
||||
|
||||
Vector3 vCrossW = Vector3::Cross(v, w);
|
||||
Vector3 vCrossU = Vector3::Cross(v, u);
|
||||
|
||||
// Test sign of r
|
||||
if (Vector3::Dot(vCrossW, vCrossU) < 0)
|
||||
return false;
|
||||
|
||||
Vector3 uCrossW = Vector3::Cross(u, w);
|
||||
Vector3 uCrossV = Vector3::Cross(u, v);
|
||||
|
||||
// Test sign of t
|
||||
if (Vector3::Dot(uCrossW, uCrossV) < 0)
|
||||
return false;
|
||||
|
||||
// At this point, we know that r and t and both > 0.
|
||||
// Therefore, as long as their sum is <= 1, each must be less <= 1
|
||||
float denom = uCrossV.magnitude();
|
||||
float r = vCrossW.magnitude() / denom;
|
||||
float t = uCrossW.magnitude() / denom;
|
||||
|
||||
return (r + t <= 1);
|
||||
}
|
||||
|
||||
} // namespace kraken
|
||||
@@ -1,215 +0,0 @@
|
||||
//
|
||||
// Vector2.cpp
|
||||
// KREngine
|
||||
//
|
||||
// Created by Kearwood Gilbert on 12-03-22.
|
||||
// Copyright (c) 2012 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
#include "public/kraken.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
Vector2::Vector2() {
|
||||
x = 0.0;
|
||||
y = 0.0;
|
||||
}
|
||||
|
||||
Vector2::Vector2(float X, float Y) {
|
||||
x = X;
|
||||
y = Y;
|
||||
}
|
||||
|
||||
Vector2::Vector2(float v) {
|
||||
x = v;
|
||||
y = v;
|
||||
}
|
||||
|
||||
Vector2::Vector2(float *v) {
|
||||
x = v[0];
|
||||
y = v[1];
|
||||
}
|
||||
|
||||
Vector2::Vector2(const Vector2 &v) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
}
|
||||
|
||||
|
||||
// Vector2 swizzle getters
|
||||
Vector2 Vector2::yx() const
|
||||
{
|
||||
return Vector2(y,x);
|
||||
}
|
||||
|
||||
// Vector2 swizzle setters
|
||||
void Vector2::yx(const Vector2 &v)
|
||||
{
|
||||
y = v.x;
|
||||
x = v.y;
|
||||
}
|
||||
|
||||
Vector2 Vector2::Min() {
|
||||
return Vector2(-std::numeric_limits<float>::max());
|
||||
}
|
||||
|
||||
Vector2 Vector2::Max() {
|
||||
return Vector2(std::numeric_limits<float>::max());
|
||||
}
|
||||
|
||||
Vector2 Vector2::Zero() {
|
||||
return Vector2(0.0f);
|
||||
}
|
||||
|
||||
Vector2 Vector2::One() {
|
||||
return Vector2(1.0f);
|
||||
}
|
||||
|
||||
Vector2::~Vector2() {
|
||||
|
||||
}
|
||||
|
||||
Vector2& Vector2::operator =(const Vector2& b) {
|
||||
x = b.x;
|
||||
y = b.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector2 Vector2::operator +(const Vector2& b) const {
|
||||
return Vector2(x + b.x, y + b.y);
|
||||
}
|
||||
|
||||
Vector2 Vector2::operator -(const Vector2& b) const {
|
||||
return Vector2(x - b.x, y - b.y);
|
||||
}
|
||||
|
||||
Vector2 Vector2::operator +() const {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector2 Vector2::operator -() const {
|
||||
return Vector2(-x, -y);
|
||||
}
|
||||
|
||||
Vector2 Vector2::operator *(const float v) const {
|
||||
return Vector2(x * v, y * v);
|
||||
}
|
||||
|
||||
Vector2 Vector2::operator /(const float v) const {
|
||||
float inv_v = 1.0f / v;
|
||||
return Vector2(x * inv_v, y * inv_v);
|
||||
}
|
||||
|
||||
Vector2& Vector2::operator +=(const Vector2& b) {
|
||||
x += b.x;
|
||||
y += b.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector2& Vector2::operator -=(const Vector2& b) {
|
||||
x -= b.x;
|
||||
y -= b.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vector2& Vector2::operator *=(const float v) {
|
||||
x *= v;
|
||||
y *= v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector2& Vector2::operator /=(const float v) {
|
||||
float inv_v = 1.0f / v;
|
||||
x *= inv_v;
|
||||
y *= inv_v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool Vector2::operator ==(const Vector2& b) const {
|
||||
return x == b.x && y == b.y;
|
||||
}
|
||||
|
||||
bool Vector2::operator !=(const Vector2& b) const {
|
||||
return x != b.x || y != b.y;
|
||||
}
|
||||
|
||||
bool Vector2::operator >(const Vector2& b) const
|
||||
{
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
if(x > b.x) {
|
||||
return true;
|
||||
} else if(x < b.x) {
|
||||
return false;
|
||||
} else if(y > b.y) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Vector2::operator <(const Vector2& b) const
|
||||
{
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
if(x < b.x) {
|
||||
return true;
|
||||
} else if(x > b.x) {
|
||||
return false;
|
||||
} else if(y < b.y) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
float& Vector2::operator[] (unsigned i) {
|
||||
switch(i) {
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
default:
|
||||
return y;
|
||||
}
|
||||
}
|
||||
|
||||
float Vector2::operator[](unsigned i) const {
|
||||
switch(i) {
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
default:
|
||||
return y;
|
||||
}
|
||||
}
|
||||
|
||||
void Vector2::normalize() {
|
||||
float inv_magnitude = 1.0f / sqrtf(x * x + y * y);
|
||||
x *= inv_magnitude;
|
||||
y *= inv_magnitude;
|
||||
}
|
||||
|
||||
float Vector2::sqrMagnitude() const {
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
float Vector2::magnitude() const {
|
||||
return sqrtf(x * x + y * y);
|
||||
}
|
||||
|
||||
|
||||
Vector2 Vector2::Normalize(const Vector2 &v) {
|
||||
float inv_magnitude = 1.0f / sqrtf(v.x * v.x + v.y * v.y);
|
||||
return Vector2(v.x * inv_magnitude, v.y * inv_magnitude);
|
||||
}
|
||||
|
||||
float Vector2::Cross(const Vector2 &v1, const Vector2 &v2) {
|
||||
return v1.x * v2.y - v1.y * v2.x;
|
||||
}
|
||||
|
||||
float Vector2::Dot(const Vector2 &v1, const Vector2 &v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y;
|
||||
}
|
||||
|
||||
} // namepsace kraken
|
||||
@@ -1,418 +0,0 @@
|
||||
//
|
||||
// Vector3.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 "public/kraken.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
const Vector3 Vector3_ZERO(0.0f, 0.0f, 0.0f);
|
||||
|
||||
//default constructor
|
||||
Vector3::Vector3()
|
||||
{
|
||||
x = 0.0f;
|
||||
y = 0.0f;
|
||||
z = 0.0f;
|
||||
}
|
||||
|
||||
Vector3::Vector3(const Vector3 &v) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
}
|
||||
|
||||
Vector3::Vector3(const Vector4 &v) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
}
|
||||
|
||||
Vector3::Vector3(float *v) {
|
||||
x = v[0];
|
||||
y = v[1];
|
||||
z = v[2];
|
||||
}
|
||||
|
||||
Vector3::Vector3(double *v) {
|
||||
x = (float)v[0];
|
||||
y = (float)v[1];
|
||||
z = (float)v[2];
|
||||
}
|
||||
|
||||
Vector2 Vector3::xx() const
|
||||
{
|
||||
return Vector2(x,x);
|
||||
}
|
||||
|
||||
Vector2 Vector3::xy() const
|
||||
{
|
||||
return Vector2(x,y);
|
||||
}
|
||||
|
||||
Vector2 Vector3::xz() const
|
||||
{
|
||||
return Vector2(x,z);
|
||||
}
|
||||
|
||||
Vector2 Vector3::yx() const
|
||||
{
|
||||
return Vector2(y,x);
|
||||
}
|
||||
|
||||
Vector2 Vector3::yy() const
|
||||
{
|
||||
return Vector2(y,y);
|
||||
}
|
||||
|
||||
Vector2 Vector3::yz() const
|
||||
{
|
||||
return Vector2(y,z);
|
||||
}
|
||||
|
||||
Vector2 Vector3::zx() const
|
||||
{
|
||||
return Vector2(z,x);
|
||||
}
|
||||
|
||||
Vector2 Vector3::zy() const
|
||||
{
|
||||
return Vector2(z,y);
|
||||
}
|
||||
|
||||
Vector2 Vector3::zz() const
|
||||
{
|
||||
return Vector2(z,z);
|
||||
}
|
||||
|
||||
void Vector3::xy(const Vector2 &v)
|
||||
{
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
}
|
||||
|
||||
void Vector3::xz(const Vector2 &v)
|
||||
{
|
||||
x = v.x;
|
||||
z = v.y;
|
||||
}
|
||||
|
||||
void Vector3::yx(const Vector2 &v)
|
||||
{
|
||||
y = v.x;
|
||||
x = v.y;
|
||||
}
|
||||
|
||||
void Vector3::yz(const Vector2 &v)
|
||||
{
|
||||
y = v.x;
|
||||
z = v.y;
|
||||
}
|
||||
|
||||
void Vector3::zx(const Vector2 &v)
|
||||
{
|
||||
z = v.x;
|
||||
x = v.y;
|
||||
}
|
||||
|
||||
void Vector3::zy(const Vector2 &v)
|
||||
{
|
||||
z = v.x;
|
||||
y = v.y;
|
||||
}
|
||||
|
||||
Vector3 Vector3::Min() {
|
||||
return Vector3(-std::numeric_limits<float>::max());
|
||||
}
|
||||
|
||||
Vector3 Vector3::Max() {
|
||||
return Vector3(std::numeric_limits<float>::max());
|
||||
}
|
||||
|
||||
const Vector3 &Vector3::Zero() {
|
||||
return Vector3_ZERO;
|
||||
}
|
||||
|
||||
Vector3 Vector3::One() {
|
||||
return Vector3(1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
Vector3 Vector3::Forward() {
|
||||
return Vector3(0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
Vector3 Vector3::Backward() {
|
||||
return Vector3(0.0f, 0.0f, -1.0f);
|
||||
}
|
||||
|
||||
Vector3 Vector3::Up() {
|
||||
return Vector3(0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
Vector3 Vector3::Down() {
|
||||
return Vector3(0.0f, -1.0f, 0.0f);
|
||||
}
|
||||
|
||||
Vector3 Vector3::Left() {
|
||||
return Vector3(-1.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
Vector3 Vector3::Right() {
|
||||
return Vector3(1.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
void Vector3::scale(const Vector3 &v)
|
||||
{
|
||||
x *= v.x;
|
||||
y *= v.y;
|
||||
z *= v.z;
|
||||
}
|
||||
|
||||
Vector3 Vector3::Scale(const Vector3 &v1, const Vector3 &v2)
|
||||
{
|
||||
return Vector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
|
||||
}
|
||||
|
||||
Vector3 Vector3::Lerp(const Vector3 &v1, const Vector3 &v2, float d) {
|
||||
return v1 + (v2 - v1) * d;
|
||||
}
|
||||
|
||||
Vector3 Vector3::Slerp(const Vector3 &v1, const Vector3 &v2, float d) {
|
||||
// From: http://keithmaggio.wordpress.com/2011/02/15/math-magician-lerp-slerp-and-nlerp/
|
||||
// Dot product - the cosine of the angle between 2 vectors.
|
||||
float dot = Vector3::Dot(v1, v2);
|
||||
// Clamp it to be in the range of Acos()
|
||||
if(dot < -1.0f) dot = -1.0f;
|
||||
if(dot > 1.0f) dot = 1.0f;
|
||||
// Acos(dot) returns the angle between start and end,
|
||||
// And multiplying that by percent returns the angle between
|
||||
// start and the final result.
|
||||
float theta = acos(dot)*d;
|
||||
Vector3 RelativeVec = v2 - v1*dot;
|
||||
RelativeVec.normalize(); // Orthonormal basis
|
||||
// The final result.
|
||||
return ((v1*cos(theta)) + (RelativeVec*sin(theta)));
|
||||
}
|
||||
|
||||
void Vector3::OrthoNormalize(Vector3 &normal, Vector3 &tangent) {
|
||||
// Gram-Schmidt Orthonormalization
|
||||
normal.normalize();
|
||||
Vector3 proj = normal * Dot(tangent, normal);
|
||||
tangent = tangent - proj;
|
||||
tangent.normalize();
|
||||
}
|
||||
|
||||
Vector3::Vector3(float v) {
|
||||
x = v;
|
||||
y = v;
|
||||
z = v;
|
||||
}
|
||||
|
||||
Vector3::Vector3(float X, float Y, float Z)
|
||||
{
|
||||
x = X;
|
||||
y = Y;
|
||||
z = Z;
|
||||
}
|
||||
|
||||
Vector3::~Vector3()
|
||||
{
|
||||
}
|
||||
|
||||
Vector3& Vector3::operator =(const Vector3& b) {
|
||||
x = b.x;
|
||||
y = b.y;
|
||||
z = b.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector3& Vector3::operator =(const Vector4 &b) {
|
||||
x = b.x;
|
||||
y = b.y;
|
||||
z = b.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector3 Vector3::operator +(const Vector3& b) const {
|
||||
return Vector3(x + b.x, y + b.y, z + b.z);
|
||||
}
|
||||
Vector3 Vector3::operator -(const Vector3& b) const {
|
||||
return Vector3(x - b.x, y - b.y, z - b.z);
|
||||
}
|
||||
Vector3 Vector3::operator +() const {
|
||||
return *this;
|
||||
}
|
||||
Vector3 Vector3::operator -() const {
|
||||
return Vector3(-x, -y, -z);
|
||||
}
|
||||
|
||||
Vector3 Vector3::operator *(const float v) const {
|
||||
return Vector3(x * v, y * v, z * v);
|
||||
}
|
||||
|
||||
Vector3 Vector3::operator /(const float v) const {
|
||||
float inv_v = 1.0f / v;
|
||||
return Vector3(x * inv_v, y * inv_v, z * inv_v);
|
||||
}
|
||||
|
||||
Vector3& Vector3::operator +=(const Vector3& b) {
|
||||
x += b.x;
|
||||
y += b.y;
|
||||
z += b.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector3& Vector3::operator -=(const Vector3& b) {
|
||||
x -= b.x;
|
||||
y -= b.y;
|
||||
z -= b.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector3& Vector3::operator *=(const float v) {
|
||||
x *= v;
|
||||
y *= v;
|
||||
z *= v;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector3& Vector3::operator /=(const float v) {
|
||||
float inv_v = 1.0f / v;
|
||||
x *= inv_v;
|
||||
y *= inv_v;
|
||||
z *= inv_v;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Vector3::operator ==(const Vector3& b) const {
|
||||
return x == b.x && y == b.y && z == b.z;
|
||||
|
||||
}
|
||||
bool Vector3::operator !=(const Vector3& b) const {
|
||||
return x != b.x || y != b.y || z != b.z;
|
||||
}
|
||||
|
||||
float& Vector3::operator[](unsigned i) {
|
||||
switch(i) {
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
default:
|
||||
case 2:
|
||||
return z;
|
||||
}
|
||||
}
|
||||
|
||||
float Vector3::operator[](unsigned i) const {
|
||||
switch(i) {
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
case 2:
|
||||
default:
|
||||
return z;
|
||||
}
|
||||
}
|
||||
|
||||
float Vector3::sqrMagnitude() const {
|
||||
// calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function)
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
float Vector3::magnitude() const {
|
||||
return sqrtf(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
void Vector3::normalize() {
|
||||
float inv_magnitude = 1.0f / sqrtf(x * x + y * y + z * z);
|
||||
x *= inv_magnitude;
|
||||
y *= inv_magnitude;
|
||||
z *= inv_magnitude;
|
||||
}
|
||||
Vector3 Vector3::Normalize(const Vector3 &v) {
|
||||
float inv_magnitude = 1.0f / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
|
||||
return Vector3(v.x * inv_magnitude, v.y * inv_magnitude, v.z * inv_magnitude);
|
||||
}
|
||||
|
||||
Vector3 Vector3::Cross(const Vector3 &v1, const Vector3 &v2) {
|
||||
return Vector3(v1.y * v2.z - v1.z * v2.y,
|
||||
v1.z * v2.x - v1.x * v2.z,
|
||||
v1.x * v2.y - v1.y * v2.x);
|
||||
}
|
||||
|
||||
float Vector3::Dot(const Vector3 &v1, const Vector3 &v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
|
||||
}
|
||||
|
||||
bool Vector3::operator >(const Vector3& b) const
|
||||
{
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
if(x > b.x) {
|
||||
return true;
|
||||
} else if(x < b.x) {
|
||||
return false;
|
||||
} else if(y > b.y) {
|
||||
return true;
|
||||
} else if(y < b.y) {
|
||||
return false;
|
||||
} else if(z > b.z) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Vector3::operator <(const Vector3& b) const
|
||||
{
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
if(x < b.x) {
|
||||
return true;
|
||||
} else if(x > b.x) {
|
||||
return false;
|
||||
} else if(y < b.y) {
|
||||
return true;
|
||||
} else if(y > b.y) {
|
||||
return false;
|
||||
} else if(z < b.z) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace kraken
|
||||
|
||||
@@ -1,303 +0,0 @@
|
||||
//
|
||||
// Vector4.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 "public/kraken.h"
|
||||
|
||||
namespace kraken {
|
||||
|
||||
const Vector4 Vector4_ZERO(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
//default constructor
|
||||
Vector4::Vector4()
|
||||
{
|
||||
x = 0.0f;
|
||||
y = 0.0f;
|
||||
z = 0.0f;
|
||||
w = 0.0f;
|
||||
}
|
||||
|
||||
Vector4::Vector4(const Vector4 &v) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
w = v.w;
|
||||
}
|
||||
|
||||
Vector4::Vector4(const Vector3 &v, float W) {
|
||||
x = v.x;
|
||||
y = v.y;
|
||||
z = v.z;
|
||||
w = W;
|
||||
}
|
||||
|
||||
Vector4::Vector4(float *v) {
|
||||
x = v[0];
|
||||
y = v[1];
|
||||
z = v[2];
|
||||
w = v[3];
|
||||
}
|
||||
|
||||
Vector4 Vector4::Min() {
|
||||
return Vector4(-std::numeric_limits<float>::max());
|
||||
}
|
||||
|
||||
Vector4 Vector4::Max() {
|
||||
return Vector4(std::numeric_limits<float>::max());
|
||||
}
|
||||
|
||||
const Vector4 &Vector4::Zero() {
|
||||
return Vector4_ZERO;
|
||||
}
|
||||
|
||||
Vector4 Vector4::One() {
|
||||
return Vector4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
Vector4 Vector4::Forward() {
|
||||
return Vector4(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
Vector4 Vector4::Backward() {
|
||||
return Vector4(0.0f, 0.0f, -1.0f, 1.0f);
|
||||
}
|
||||
|
||||
Vector4 Vector4::Up() {
|
||||
return Vector4(0.0f, 1.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
Vector4 Vector4::Down() {
|
||||
return Vector4(0.0f, -1.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
Vector4 Vector4::Left() {
|
||||
return Vector4(-1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
Vector4 Vector4::Right() {
|
||||
return Vector4(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
Vector4 Vector4::Lerp(const Vector4 &v1, const Vector4 &v2, float d) {
|
||||
return v1 + (v2 - v1) * d;
|
||||
}
|
||||
|
||||
Vector4 Vector4::Slerp(const Vector4 &v1, const Vector4 &v2, float d) {
|
||||
// From: http://keithmaggio.wordpress.com/2011/02/15/math-magician-lerp-slerp-and-nlerp/
|
||||
// Dot product - the cosine of the angle between 2 vectors.
|
||||
float dot = Vector4::Dot(v1, v2);
|
||||
// Clamp it to be in the range of Acos()
|
||||
if(dot < -1.0f) dot = -1.0f;
|
||||
if(dot > 1.0f) dot = 1.0f;
|
||||
// Acos(dot) returns the angle between start and end,
|
||||
// And multiplying that by percent returns the angle between
|
||||
// start and the final result.
|
||||
float theta = acos(dot)*d;
|
||||
Vector4 RelativeVec = v2 - v1*dot;
|
||||
RelativeVec.normalize(); // Orthonormal basis
|
||||
// The final result.
|
||||
return ((v1*cos(theta)) + (RelativeVec*sin(theta)));
|
||||
}
|
||||
|
||||
void Vector4::OrthoNormalize(Vector4 &normal, Vector4 &tangent) {
|
||||
// Gram-Schmidt Orthonormalization
|
||||
normal.normalize();
|
||||
Vector4 proj = normal * Dot(tangent, normal);
|
||||
tangent = tangent - proj;
|
||||
tangent.normalize();
|
||||
}
|
||||
|
||||
Vector4::Vector4(float v) {
|
||||
x = v;
|
||||
y = v;
|
||||
z = v;
|
||||
w = v;
|
||||
}
|
||||
|
||||
Vector4::Vector4(float X, float Y, float Z, float W)
|
||||
{
|
||||
x = X;
|
||||
y = Y;
|
||||
z = Z;
|
||||
w = W;
|
||||
}
|
||||
|
||||
Vector4::~Vector4()
|
||||
{
|
||||
}
|
||||
|
||||
Vector4& Vector4::operator =(const Vector4& b) {
|
||||
x = b.x;
|
||||
y = b.y;
|
||||
z = b.z;
|
||||
w = b.w;
|
||||
return *this;
|
||||
}
|
||||
Vector4 Vector4::operator +(const Vector4& b) const {
|
||||
return Vector4(x + b.x, y + b.y, z + b.z, w + b.w);
|
||||
}
|
||||
Vector4 Vector4::operator -(const Vector4& b) const {
|
||||
return Vector4(x - b.x, y - b.y, z - b.z, w - b.w);
|
||||
}
|
||||
Vector4 Vector4::operator +() const {
|
||||
return *this;
|
||||
}
|
||||
Vector4 Vector4::operator -() const {
|
||||
return Vector4(-x, -y, -z, -w);
|
||||
}
|
||||
|
||||
Vector4 Vector4::operator *(const float v) const {
|
||||
return Vector4(x * v, y * v, z * v, w * v);
|
||||
}
|
||||
|
||||
Vector4 Vector4::operator /(const float v) const {
|
||||
return Vector4(x / v, y / v, z / v, w/ v);
|
||||
}
|
||||
|
||||
Vector4& Vector4::operator +=(const Vector4& b) {
|
||||
x += b.x;
|
||||
y += b.y;
|
||||
z += b.z;
|
||||
w += b.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector4& Vector4::operator -=(const Vector4& b) {
|
||||
x -= b.x;
|
||||
y -= b.y;
|
||||
z -= b.z;
|
||||
w -= b.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector4& Vector4::operator *=(const float v) {
|
||||
x *= v;
|
||||
y *= v;
|
||||
z *= v;
|
||||
w *= v;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector4& Vector4::operator /=(const float v) {
|
||||
float inv_v = 1.0f / v;
|
||||
x *= inv_v;
|
||||
y *= inv_v;
|
||||
z *= inv_v;
|
||||
w *= inv_v;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Vector4::operator ==(const Vector4& b) const {
|
||||
return x == b.x && y == b.y && z == b.z && w == b.w;
|
||||
|
||||
}
|
||||
bool Vector4::operator !=(const Vector4& b) const {
|
||||
return x != b.x || y != b.y || z != b.z || w != b.w;
|
||||
}
|
||||
|
||||
float& Vector4::operator[](unsigned i) {
|
||||
switch(i) {
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
case 2:
|
||||
return z;
|
||||
default:
|
||||
case 3:
|
||||
return w;
|
||||
}
|
||||
}
|
||||
|
||||
float Vector4::operator[](unsigned i) const {
|
||||
switch(i) {
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
case 2:
|
||||
return z;
|
||||
default:
|
||||
case 3:
|
||||
return w;
|
||||
}
|
||||
}
|
||||
|
||||
float Vector4::sqrMagnitude() const {
|
||||
// calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function)
|
||||
return x * x + y * y + z * z + w * w;
|
||||
}
|
||||
|
||||
float Vector4::magnitude() const {
|
||||
return sqrtf(x * x + y * y + z * z + w * w);
|
||||
}
|
||||
|
||||
void Vector4::normalize() {
|
||||
float inv_magnitude = 1.0f / sqrtf(x * x + y * y + z * z + w * w);
|
||||
x *= inv_magnitude;
|
||||
y *= inv_magnitude;
|
||||
z *= inv_magnitude;
|
||||
w *= inv_magnitude;
|
||||
}
|
||||
Vector4 Vector4::Normalize(const Vector4 &v) {
|
||||
float inv_magnitude = 1.0f / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w);
|
||||
return Vector4(v.x * inv_magnitude, v.y * inv_magnitude, v.z * inv_magnitude, v.w * inv_magnitude);
|
||||
}
|
||||
|
||||
|
||||
float Vector4::Dot(const Vector4 &v1, const Vector4 &v2) {
|
||||
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
|
||||
}
|
||||
|
||||
bool Vector4::operator >(const Vector4& b) const
|
||||
{
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
if(x != b.x) return x > b.x;
|
||||
if(y != b.y) return y > b.y;
|
||||
if(z != b.z) return z > b.z;
|
||||
if(w != b.w) return w > b.w;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Vector4::operator <(const Vector4& b) const
|
||||
{
|
||||
// Comparison operators are implemented to allow insertion into sorted containers such as std::set
|
||||
if(x != b.x) return x < b.x;
|
||||
if(y != b.y) return y < b.y;
|
||||
if(z != b.z) return z < b.z;
|
||||
if(w != b.w) return w < b.w;
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace kraken
|
||||
Reference in New Issue
Block a user