/s/KRVector3/Vector3/g

This commit is contained in:
Kearwood Kip Gilbert
2017-07-29 01:24:49 -07:00
parent 8cf3c742e3
commit 95ff5243c5
71 changed files with 1197 additions and 865 deletions

View File

@@ -12,20 +12,20 @@
KRAABB::KRAABB() KRAABB::KRAABB()
{ {
min = KRVector3::Min(); min = Vector3::Min();
max = KRVector3::Max(); max = Vector3::Max();
} }
KRAABB::KRAABB(const KRVector3 &minPoint, const KRVector3 &maxPoint) KRAABB::KRAABB(const Vector3 &minPoint, const Vector3 &maxPoint)
{ {
min = minPoint; min = minPoint;
max = maxPoint; max = maxPoint;
} }
KRAABB::KRAABB(const KRVector3 &corner1, const KRVector3 &corner2, const KRMat4 &modelMatrix) KRAABB::KRAABB(const Vector3 &corner1, const Vector3 &corner2, const KRMat4 &modelMatrix)
{ {
for(int iCorner=0; iCorner<8; iCorner++) { for(int iCorner=0; iCorner<8; iCorner++) {
KRVector3 sourceCornerVertex = KRMat4::DotWDiv(modelMatrix, KRVector3( Vector3 sourceCornerVertex = KRMat4::DotWDiv(modelMatrix, Vector3(
(iCorner & 1) == 0 ? corner1.x : corner2.x, (iCorner & 1) == 0 ? corner1.x : corner2.x,
(iCorner & 2) == 0 ? corner1.y : corner2.y, (iCorner & 2) == 0 ? corner1.y : corner2.y,
(iCorner & 4) == 0 ? corner1.z : corner2.z)); (iCorner & 4) == 0 ? corner1.z : corner2.z));
@@ -68,34 +68,34 @@ bool KRAABB::operator !=(const KRAABB& b) const
return min != b.min || max != b.max; return min != b.min || max != b.max;
} }
KRVector3 KRAABB::center() const Vector3 KRAABB::center() const
{ {
return (min + max) * 0.5f; return (min + max) * 0.5f;
} }
KRVector3 KRAABB::size() const Vector3 KRAABB::size() const
{ {
return max - min; return max - min;
} }
float KRAABB::volume() const float KRAABB::volume() const
{ {
KRVector3 s = size(); Vector3 s = size();
return s.x * s.y * s.z; return s.x * s.y * s.z;
} }
void KRAABB::scale(const KRVector3 &s) void KRAABB::scale(const Vector3 &s)
{ {
KRVector3 prev_center = center(); Vector3 prev_center = center();
KRVector3 prev_size = size(); Vector3 prev_size = size();
KRVector3 new_scale = KRVector3(prev_size.x * s.x, prev_size.y * s.y, prev_size.z * s.z) * 0.5f; 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; min = prev_center - new_scale;
max = prev_center + new_scale; max = prev_center + new_scale;
} }
void KRAABB::scale(float s) void KRAABB::scale(float s)
{ {
scale(KRVector3(s)); scale(Vector3(s));
} }
bool KRAABB::operator >(const KRAABB& b) const bool KRAABB::operator >(const KRAABB& b) const
@@ -139,19 +139,19 @@ bool KRAABB::contains(const KRAABB &b) const
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; return b.min.x >= min.x && b.min.y >= min.y && b.min.z >= min.z && b.max.x <= max.x && b.max.y <= max.y && b.max.z <= max.z;
} }
bool KRAABB::contains(const KRVector3 &v) const bool KRAABB::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; return v.x >= min.x && v.x <= max.x && v.y >= min.y && v.y <= max.y && v.z >= min.z && v.z <= max.z;
} }
KRAABB KRAABB::Infinite() KRAABB KRAABB::Infinite()
{ {
return KRAABB(KRVector3::Min(), KRVector3::Max()); return KRAABB(Vector3::Min(), Vector3::Max());
} }
KRAABB KRAABB::Zero() KRAABB KRAABB::Zero()
{ {
return KRAABB(KRVector3::Zero(), KRVector3::Zero()); return KRAABB(Vector3::Zero(), Vector3::Zero());
} }
float KRAABB::longest_radius() const float KRAABB::longest_radius() const
@@ -162,9 +162,9 @@ float KRAABB::longest_radius() const
} }
bool KRAABB::intersectsLine(const KRVector3 &v1, const KRVector3 &v2) const bool KRAABB::intersectsLine(const Vector3 &v1, const Vector3 &v2) const
{ {
KRVector3 dir = KRVector3::Normalize(v2 - v1); Vector3 dir = Vector3::Normalize(v2 - v1);
float length = (v2 - v1).magnitude(); float length = (v2 - v1).magnitude();
// EZ cases: if the ray starts inside the box, or ends inside // EZ cases: if the ray starts inside the box, or ends inside
@@ -178,7 +178,7 @@ bool KRAABB::intersectsLine(const KRVector3 &v1, const KRVector3 &v2) const
return true ; return true ;
// the algorithm says, find 3 t's, // the algorithm says, find 3 t's,
KRVector3 t ; Vector3 t ;
// LARGEST t is the only one we need to test if it's on the face. // LARGEST t is the only one we need to test if it's on the face.
for(int i = 0 ; i < 3 ; i++) { for(int i = 0 ; i < 3 ; i++) {
@@ -193,7 +193,7 @@ bool KRAABB::intersectsLine(const KRVector3 &v1, const KRVector3 &v2) const
if(t[1] > t[mi]) mi = 1; if(t[1] > t[mi]) mi = 1;
if(t[2] > t[mi]) mi = 2; if(t[2] > t[mi]) mi = 2;
if(t[mi] >= 0 && t[mi] <= length) { if(t[mi] >= 0 && t[mi] <= length) {
KRVector3 pt = v1 + dir * t[mi]; Vector3 pt = v1 + dir * t[mi];
// check it's in the box in other 2 dimensions // 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 o1 = ( mi + 1 ) % 3 ; // i=0: o1=1, o2=2, i=1: o1=2,o2=0 etc.
@@ -205,7 +205,7 @@ bool KRAABB::intersectsLine(const KRVector3 &v1, const KRVector3 &v2) const
return false ; // the ray did not hit the box. return false ; // the ray did not hit the box.
} }
bool KRAABB::intersectsRay(const KRVector3 &v1, const KRVector3 &dir) const bool KRAABB::intersectsRay(const Vector3 &v1, const Vector3 &dir) const
{ {
/* /*
Fast Ray-Box Intersection Fast Ray-Box Intersection
@@ -222,8 +222,8 @@ bool KRAABB::intersectsRay(const KRVector3 &v1, const KRVector3 &dir) const
} quadrant[3]; } quadrant[3];
bool inside = true; bool inside = true;
KRVector3 maxT; Vector3 maxT;
KRVector3 coord; Vector3 coord;
double candidatePlane[3]; double candidatePlane[3];
// Find candidate planes; this loop can be avoided if rays cast all from the eye(assume perpsective view) // Find candidate planes; this loop can be avoided if rays cast all from the eye(assume perpsective view)
@@ -281,7 +281,7 @@ bool KRAABB::intersectsRay(const KRVector3 &v1, const KRVector3 &dir) const
return true; /* ray hits box */ return true; /* ray hits box */
} }
bool KRAABB::intersectsSphere(const KRVector3 &center, float radius) const bool KRAABB::intersectsSphere(const Vector3 &center, float radius) const
{ {
// Arvo's Algorithm // Arvo's Algorithm
@@ -328,7 +328,7 @@ void KRAABB::encapsulate(const KRAABB & b)
if(b.max.z > max.z) max.z = b.max.z; if(b.max.z > max.z) max.z = b.max.z;
} }
KRVector3 KRAABB::nearestPoint(const KRVector3 & v) const Vector3 KRAABB::nearestPoint(const Vector3 & v) const
{ {
return KRVector3(KRCLAMP(v.x, min.x, max.x), KRCLAMP(v.y, min.y, max.y), KRCLAMP(v.z, min.z, max.z)); return Vector3(KRCLAMP(v.x, min.x, max.x), KRCLAMP(v.y, min.y, max.y), KRCLAMP(v.z, min.z, max.z));
} }

View File

@@ -98,7 +98,7 @@ void KRAmbientZone::render(KRCamera *pCamera, std::vector<KRPointLight *> &point
KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
// Enable additive blending // Enable additive blending
GLDEBUG(glEnable(GL_BLEND)); GLDEBUG(glEnable(GL_BLEND));
@@ -139,17 +139,17 @@ void KRAmbientZone::setGradientDistance(float gradient_distance)
KRAABB KRAmbientZone::getBounds() { KRAABB KRAmbientZone::getBounds() {
// Ambient zones always have a -1, -1, -1 to 1, 1, 1 bounding box // Ambient zones always have a -1, -1, -1 to 1, 1, 1 bounding box
return KRAABB(-KRVector3::One(), KRVector3::One(), getModelMatrix()); return KRAABB(-Vector3::One(), Vector3::One(), getModelMatrix());
} }
float KRAmbientZone::getContainment(const KRVector3 &pos) float KRAmbientZone::getContainment(const Vector3 &pos)
{ {
KRAABB bounds = getBounds(); KRAABB bounds = getBounds();
if(bounds.contains(pos)) { if(bounds.contains(pos)) {
KRVector3 size = bounds.size(); Vector3 size = bounds.size();
KRVector3 diff = pos - bounds.center(); Vector3 diff = pos - bounds.center();
diff = diff * 2.0f; diff = diff * 2.0f;
diff = KRVector3(diff.x / size.x, diff.y / size.y, diff.z / size.z); diff = Vector3(diff.x / size.x, diff.y / size.y, diff.z / size.z);
float d = diff.magnitude(); float d = diff.magnitude();
if(m_gradient_distance <= 0.0f) { if(m_gradient_distance <= 0.0f) {

View File

@@ -37,7 +37,7 @@ public:
virtual KRAABB getBounds(); virtual KRAABB getBounds();
float getContainment(const KRVector3 &pos); float getContainment(const Vector3 &pos);
private: private:
std::string m_zone; std::string m_zone;

View File

@@ -1221,28 +1221,28 @@ void KRAudioManager::makeCurrentContext()
void KRAudioManager::setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix) void KRAudioManager::setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix)
{ {
setListenerOrientation( setListenerOrientation(
KRMat4::Dot(modelMatrix, KRVector3(0.0, 0.0, 0.0)), KRMat4::Dot(modelMatrix, Vector3(0.0, 0.0, 0.0)),
KRVector3::Normalize(KRMat4::Dot(modelMatrix, KRVector3(0.0, 0.0, -1.0)) - m_listener_position), Vector3::Normalize(KRMat4::Dot(modelMatrix, Vector3(0.0, 0.0, -1.0)) - m_listener_position),
KRVector3::Normalize(KRMat4::Dot(modelMatrix, KRVector3(0.0, 1.0, 0.0)) - m_listener_position) Vector3::Normalize(KRMat4::Dot(modelMatrix, Vector3(0.0, 1.0, 0.0)) - m_listener_position)
); );
} }
KRVector3 &KRAudioManager::getListenerForward() Vector3 &KRAudioManager::getListenerForward()
{ {
return m_listener_forward; return m_listener_forward;
} }
KRVector3 &KRAudioManager::getListenerPosition() Vector3 &KRAudioManager::getListenerPosition()
{ {
return m_listener_position; return m_listener_position;
} }
KRVector3 &KRAudioManager::getListenerUp() Vector3 &KRAudioManager::getListenerUp()
{ {
return m_listener_up; return m_listener_up;
} }
void KRAudioManager::setListenerOrientation(const KRVector3 &position, const KRVector3 &forward, const KRVector3 &up) void KRAudioManager::setListenerOrientation(const Vector3 &position, const Vector3 &forward, const Vector3 &up)
{ {
m_listener_position = position; m_listener_position = position;
m_listener_forward = forward; m_listener_forward = forward;
@@ -1459,14 +1459,14 @@ void KRAudioManager::startFrame(float deltaTime)
m_prev_mapped_sources.clear(); m_prev_mapped_sources.clear();
m_mapped_sources.swap(m_prev_mapped_sources); m_mapped_sources.swap(m_prev_mapped_sources);
KRVector3 listener_right = KRVector3::Cross(m_listener_forward, m_listener_up); Vector3 listener_right = Vector3::Cross(m_listener_forward, m_listener_up);
std::set<KRAudioSource *> active_sources = m_activeAudioSources; std::set<KRAudioSource *> active_sources = m_activeAudioSources;
for(std::set<KRAudioSource *>::iterator itr=active_sources.begin(); itr != active_sources.end(); itr++) { for(std::set<KRAudioSource *>::iterator itr=active_sources.begin(); itr != active_sources.end(); itr++) {
KRAudioSource *source = *itr; KRAudioSource *source = *itr;
KRVector3 source_world_position = source->getWorldTranslation(); Vector3 source_world_position = source->getWorldTranslation();
KRVector3 diff = source_world_position - m_listener_position; Vector3 diff = source_world_position - m_listener_position;
float distance = diff.magnitude(); float distance = diff.magnitude();
float gain = source->getGain() * m_global_gain / pow(KRMAX(distance / source->getReferenceDistance(), 1.0f), source->getRolloffFactor()); float gain = source->getGain() * m_global_gain / pow(KRMAX(distance / source->getReferenceDistance(), 1.0f), source->getRolloffFactor());
@@ -1475,14 +1475,14 @@ void KRAudioManager::startFrame(float deltaTime)
if(gain > 0.0f) { if(gain > 0.0f) {
KRVector3 source_listener_space = KRVector3( Vector3 source_listener_space = Vector3(
KRVector3::Dot(listener_right, diff), Vector3::Dot(listener_right, diff),
KRVector3::Dot(m_listener_up, diff), Vector3::Dot(m_listener_up, diff),
KRVector3::Dot(m_listener_forward, diff) Vector3::Dot(m_listener_forward, diff)
); );
KRVector3 source_dir = KRVector3::Normalize(source_listener_space); Vector3 source_dir = Vector3::Normalize(source_listener_space);
@@ -1699,13 +1699,13 @@ void KRAudioManager::renderITD()
float head_radius = 0.7431f; // 0.74ft = 22cm float head_radius = 0.7431f; // 0.74ft = 22cm
float half_max_itd_time = head_radius / speed_of_sound / 2.0f; // half of ITD time (Interaural time difference) when audio source is directly 90 degrees azimuth to one ear. float half_max_itd_time = head_radius / speed_of_sound / 2.0f; // half of ITD time (Interaural time difference) when audio source is directly 90 degrees azimuth to one ear.
// KRVector3 m_listener_position; // Vector3 m_listener_position;
// KRVector3 m_listener_forward; // Vector3 m_listener_forward;
// KRVector3 m_listener_up; // Vector3 m_listener_up;
KRVector3 listener_right = KRVector3::Cross(m_listener_forward, m_listener_up); Vector3 listener_right = Vector3::Cross(m_listener_forward, m_listener_up);
KRVector3 listener_right_ear = m_listener_position + listener_right * head_radius / 2.0f; Vector3 listener_right_ear = m_listener_position + listener_right * head_radius / 2.0f;
KRVector3 listener_left_ear = m_listener_position - listener_right * head_radius / 2.0f; Vector3 listener_left_ear = m_listener_position - listener_right * head_radius / 2.0f;
// Get a pointer to the dataBuffer of the AudioBufferList // Get a pointer to the dataBuffer of the AudioBufferList
@@ -1739,10 +1739,10 @@ void KRAudioManager::renderITD()
// ----====---- Render direct / HRTF audio ----====---- // ----====---- Render direct / HRTF audio ----====----
for(std::set<KRAudioSource *>::iterator itr=m_activeAudioSources.begin(); itr != m_activeAudioSources.end(); itr++) { for(std::set<KRAudioSource *>::iterator itr=m_activeAudioSources.begin(); itr != m_activeAudioSources.end(); itr++) {
KRAudioSource *source = *itr; KRAudioSource *source = *itr;
KRVector3 listener_to_source = source->getWorldTranslation() - m_listener_position; Vector3 listener_to_source = source->getWorldTranslation() - m_listener_position;
KRVector3 right_ear_to_source = source->getWorldTranslation() - listener_right_ear; Vector3 right_ear_to_source = source->getWorldTranslation() - listener_right_ear;
KRVector3 left_ear_to_source = source->getWorldTranslation() - listener_left_ear; Vector3 left_ear_to_source = source->getWorldTranslation() - listener_left_ear;
KRVector3 source_direction = KRVector3::Normalize(listener_to_source); Vector3 source_direction = Vector3::Normalize(listener_to_source);
float right_ear_distance = right_ear_to_source.magnitude(); float right_ear_distance = right_ear_to_source.magnitude();
float left_ear_distance = left_ear_to_source.magnitude(); float left_ear_distance = left_ear_to_source.magnitude();
float right_itd_time = right_ear_distance / speed_of_sound; float right_itd_time = right_ear_distance / speed_of_sound;

View File

@@ -105,11 +105,11 @@ public:
// Listener position and orientation // Listener position and orientation
KRScene *getListenerScene(); KRScene *getListenerScene();
void setListenerScene(KRScene *scene); void setListenerScene(KRScene *scene);
void setListenerOrientation(const KRVector3 &position, const KRVector3 &forward, const KRVector3 &up); void setListenerOrientation(const Vector3 &position, const Vector3 &forward, const Vector3 &up);
void setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix); void setListenerOrientationFromModelMatrix(const KRMat4 &modelMatrix);
KRVector3 &getListenerForward(); Vector3 &getListenerForward();
KRVector3 &getListenerPosition(); Vector3 &getListenerPosition();
KRVector3 &getListenerUp(); Vector3 &getListenerUp();
// Global audio gain / attenuation // Global audio gain / attenuation
@@ -166,9 +166,9 @@ private:
float m_global_ambient_gain; float m_global_ambient_gain;
float m_global_gain; float m_global_gain;
KRVector3 m_listener_position; Vector3 m_listener_position;
KRVector3 m_listener_forward; Vector3 m_listener_forward;
KRVector3 m_listener_up; Vector3 m_listener_up;
unordered_map<std::string, KRAudioSample *> m_sounds; unordered_map<std::string, KRAudioSample *> m_sounds;

View File

@@ -182,7 +182,7 @@ void KRAudioSource::render(KRCamera *pCamera, std::vector<KRPointLight *> &point
KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
// Enable additive blending // Enable additive blending
GLDEBUG(glEnable(GL_BLEND)); GLDEBUG(glEnable(GL_BLEND));

View File

@@ -36,7 +36,7 @@ void KRBone::loadXML(tinyxml2::XMLElement *e)
} }
KRAABB KRBone::getBounds() { KRAABB KRBone::getBounds() {
return KRAABB(-KRVector3::One(), KRVector3::One(), getModelMatrix()); // Only required for bone debug visualization return KRAABB(-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) 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)
@@ -63,7 +63,7 @@ void KRBone::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights
KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
std::vector<KRMesh *> sphereModels = getContext().getMeshManager()->getModel("__sphere"); std::vector<KRMesh *> sphereModels = getContext().getMeshManager()->getModel("__sphere");
if(sphereModels.size()) { if(sphereModels.size()) {
for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) { for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) {

View File

@@ -109,7 +109,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend
KRScene &scene = getScene(); KRScene &scene = getScene();
KRMat4 modelMatrix = getModelMatrix(); KRMat4 modelMatrix = getModelMatrix();
KRMat4 viewMatrix = KRMat4::LookAt(KRMat4::Dot(modelMatrix, KRVector3::Zero()), KRMat4::Dot(modelMatrix, KRVector3::Forward()), KRVector3::Normalize(KRMat4::DotNoTranslate(modelMatrix, KRVector3::Up()))); KRMat4 viewMatrix = KRMat4::LookAt(KRMat4::Dot(modelMatrix, Vector3::Zero()), KRMat4::Dot(modelMatrix, Vector3::Forward()), Vector3::Normalize(KRMat4::DotNoTranslate(modelMatrix, Vector3::Up())));
//KRMat4 viewMatrix = KRMat4::Invert(getModelMatrix()); //KRMat4 viewMatrix = KRMat4::Invert(getModelMatrix());
@@ -119,7 +119,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend
m_viewport = KRViewport(settings.getViewportSize(), viewMatrix, projectionMatrix); m_viewport = KRViewport(settings.getViewportSize(), viewMatrix, projectionMatrix);
m_viewport.setLODBias(settings.getLODBias()); m_viewport.setLODBias(settings.getLODBias());
KRVector3 vecCameraDirection = m_viewport.getCameraDirection(); Vector3 vecCameraDirection = m_viewport.getCameraDirection();
scene.updateOctree(m_viewport); scene.updateOctree(m_viewport);
@@ -312,7 +312,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend
} }
if(m_pSkyBoxTexture) { if(m_pSkyBoxTexture) {
getContext().getShaderManager()->selectShader("sky_box", *this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, m_viewport, KRMat4(), false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_OPAQUE, KRVector3::Zero(), 0.0f, KRVector4::Zero()); getContext().getShaderManager()->selectShader("sky_box", *this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, m_viewport, KRMat4(), false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_OPAQUE, Vector3::Zero(), 0.0f, KRVector4::Zero());
getContext().getTextureManager()->selectTexture(0, m_pSkyBoxTexture, 0.0f, KRTexture::TEXTURE_USAGE_SKY_CUBE); getContext().getTextureManager()->selectTexture(0, m_pSkyBoxTexture, 0.0f, KRTexture::TEXTURE_USAGE_SKY_CUBE);
@@ -480,7 +480,7 @@ void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint rend
KRMat4 matModel = KRMat4(); KRMat4 matModel = KRMat4();
matModel.scale((*itr).first.size() * 0.5f); matModel.scale((*itr).first.size() * 0.5f);
matModel.translate((*itr).first.center()); matModel.translate((*itr).first.center());
if(getContext().getShaderManager()->selectShader(*this, pVisShader, m_viewport, matModel, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader(*this, pVisShader, m_viewport, matModel, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14)); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
} }
} }
@@ -694,7 +694,7 @@ void KRCamera::renderPost()
GLDEBUG(glDisable(GL_DEPTH_TEST)); GLDEBUG(glDisable(GL_DEPTH_TEST));
KRShader *postShader = m_pContext->getShaderManager()->getShader("PostShader", this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); KRShader *postShader = m_pContext->getShaderManager()->getShader("PostShader", this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
KRVector3 rim_color; Vector3 rim_color;
getContext().getShaderManager()->selectShader(*this, postShader, m_viewport, KRMat4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f, m_fade_color); getContext().getShaderManager()->selectShader(*this, postShader, m_viewport, KRMat4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, rim_color, 0.0f, m_fade_color);
m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 0, compositeDepthTexture); m_pContext->getTextureManager()->selectTexture(GL_TEXTURE_2D, 0, compositeDepthTexture);
@@ -720,7 +720,7 @@ void KRCamera::renderPost()
// KRMat4 viewMatrix = KRMat4(); // KRMat4 viewMatrix = KRMat4();
// viewMatrix.scale(0.20, 0.20, 0.20); // viewMatrix.scale(0.20, 0.20, 0.20);
// viewMatrix.translate(-0.70, 0.70 - 0.45 * iShadow, 0.0); // viewMatrix.translate(-0.70, 0.70 - 0.45 * iShadow, 0.0);
// getContext().getShaderManager()->selectShader(blitShader, KRViewport(getViewportSize(), viewMatrix, KRMat4()), shadowViewports, KRMat4(), KRVector3(), NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); // getContext().getShaderManager()->selectShader(blitShader, KRViewport(getViewportSize(), viewMatrix, KRMat4()), shadowViewports, KRMat4(), Vector3(), NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
// m_pContext->getTextureManager()->selectTexture(1, NULL); // m_pContext->getTextureManager()->selectTexture(1, NULL);
// m_pContext->getMeshManager()->bindVBO(&getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES); // m_pContext->getMeshManager()->bindVBO(&getContext().getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES);
// m_pContext->getTextureManager()->_setActiveTexture(0); // m_pContext->getTextureManager()->_setActiveTexture(0);
@@ -879,7 +879,7 @@ void KRCamera::renderPost()
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
KRShader *fontShader = m_pContext->getShaderManager()->getShader("debug_font", this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); KRShader *fontShader = m_pContext->getShaderManager()->getShader("debug_font", this, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
getContext().getShaderManager()->selectShader(*this, fontShader, m_viewport, KRMat4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, KRVector3::Zero(), 0.0f, KRVector4::Zero()); getContext().getShaderManager()->selectShader(*this, fontShader, m_viewport, KRMat4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, KRVector4::Zero());
m_pContext->getTextureManager()->selectTexture(0, m_pContext->getTextureManager()->getTexture("font"), 0.0f, KRTexture::TEXTURE_USAGE_UI); m_pContext->getTextureManager()->selectTexture(0, m_pContext->getTextureManager()->getTexture("font"), 0.0f, KRTexture::TEXTURE_USAGE_UI);

View File

@@ -92,23 +92,23 @@ KRAABB KRCollider::getBounds() {
} }
} }
bool KRCollider::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) bool KRCollider::lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask)
{ {
if(layer_mask & m_layer_mask ) { // Only test if layer masks have a common bit set if(layer_mask & m_layer_mask ) { // Only test if layer masks have a common bit set
loadModel(); loadModel();
if(m_models.size()) { if(m_models.size()) {
if(getBounds().intersectsLine(v0, v1)) { if(getBounds().intersectsLine(v0, v1)) {
KRVector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0); Vector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0);
KRVector3 v1_model_space = KRMat4::Dot(getInverseModelMatrix(), v1); Vector3 v1_model_space = KRMat4::Dot(getInverseModelMatrix(), v1);
KRHitInfo hitinfo_model_space; KRHitInfo hitinfo_model_space;
if(hitinfo.didHit()) { if(hitinfo.didHit()) {
KRVector3 hit_position_model_space = KRMat4::Dot(getInverseModelMatrix(), hitinfo.getPosition()); Vector3 hit_position_model_space = KRMat4::Dot(getInverseModelMatrix(), hitinfo.getPosition());
hitinfo_model_space = KRHitInfo(hit_position_model_space, KRMat4::DotNoTranslate(getInverseModelMatrix(), hitinfo.getNormal()), (hit_position_model_space - v0_model_space).magnitude(), hitinfo.getNode()); hitinfo_model_space = KRHitInfo(hit_position_model_space, KRMat4::DotNoTranslate(getInverseModelMatrix(), hitinfo.getNormal()), (hit_position_model_space - v0_model_space).magnitude(), hitinfo.getNode());
} }
if(m_models[0]->lineCast(v0_model_space, v1_model_space, hitinfo_model_space)) { if(m_models[0]->lineCast(v0_model_space, v1_model_space, hitinfo_model_space)) {
KRVector3 hit_position_world_space = KRMat4::Dot(getModelMatrix(), hitinfo_model_space.getPosition()); Vector3 hit_position_world_space = KRMat4::Dot(getModelMatrix(), hitinfo_model_space.getPosition());
hitinfo = KRHitInfo(hit_position_world_space, KRVector3::Normalize(KRMat4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), (hit_position_world_space - v0).magnitude(), this); hitinfo = KRHitInfo(hit_position_world_space, Vector3::Normalize(KRMat4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), (hit_position_world_space - v0).magnitude(), this);
return true; return true;
} }
} }
@@ -117,23 +117,23 @@ bool KRCollider::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &h
return false; return false;
} }
bool KRCollider::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) bool KRCollider::rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask)
{ {
if(layer_mask & m_layer_mask) { // Only test if layer masks have a common bit set if(layer_mask & m_layer_mask) { // Only test if layer masks have a common bit set
loadModel(); loadModel();
if(m_models.size()) { if(m_models.size()) {
if(getBounds().intersectsRay(v0, dir)) { if(getBounds().intersectsRay(v0, dir)) {
KRVector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0); Vector3 v0_model_space = KRMat4::Dot(getInverseModelMatrix(), v0);
KRVector3 dir_model_space = KRVector3::Normalize(KRMat4::DotNoTranslate(getInverseModelMatrix(), dir)); Vector3 dir_model_space = Vector3::Normalize(KRMat4::DotNoTranslate(getInverseModelMatrix(), dir));
KRHitInfo hitinfo_model_space; KRHitInfo hitinfo_model_space;
if(hitinfo.didHit()) { if(hitinfo.didHit()) {
KRVector3 hit_position_model_space = KRMat4::Dot(getInverseModelMatrix(), hitinfo.getPosition()); Vector3 hit_position_model_space = KRMat4::Dot(getInverseModelMatrix(), hitinfo.getPosition());
hitinfo_model_space = KRHitInfo(hit_position_model_space, KRVector3::Normalize(KRMat4::DotNoTranslate(getInverseModelMatrix(), hitinfo.getNormal())), (hit_position_model_space - v0_model_space).magnitude(), hitinfo.getNode()); hitinfo_model_space = KRHitInfo(hit_position_model_space, Vector3::Normalize(KRMat4::DotNoTranslate(getInverseModelMatrix(), hitinfo.getNormal())), (hit_position_model_space - v0_model_space).magnitude(), hitinfo.getNode());
} }
if(m_models[0]->rayCast(v0_model_space, dir_model_space, hitinfo_model_space)) { if(m_models[0]->rayCast(v0_model_space, dir_model_space, hitinfo_model_space)) {
KRVector3 hit_position_world_space = KRMat4::Dot(getModelMatrix(), hitinfo_model_space.getPosition()); Vector3 hit_position_world_space = KRMat4::Dot(getModelMatrix(), hitinfo_model_space.getPosition());
hitinfo = KRHitInfo(hit_position_world_space, KRVector3::Normalize(KRMat4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), (hit_position_world_space - v0).magnitude(), this); hitinfo = KRHitInfo(hit_position_world_space, Vector3::Normalize(KRMat4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), (hit_position_world_space - v0).magnitude(), this);
return true; return true;
} }
} }
@@ -142,14 +142,14 @@ bool KRCollider::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &h
return false; return false;
} }
bool KRCollider::sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask) bool KRCollider::sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask)
{ {
if(layer_mask & m_layer_mask) { // Only test if layer masks have a common bit set if(layer_mask & m_layer_mask) { // Only test if layer masks have a common bit set
loadModel(); loadModel();
if(m_models.size()) { if(m_models.size()) {
KRAABB sphereCastBounds = KRAABB( // TODO - Need to cache this; perhaps encasulate within a "spherecast" class to be passed through these functions KRAABB sphereCastBounds = KRAABB( // TODO - Need to cache this; perhaps encasulate within a "spherecast" class to be passed through these functions
KRVector3(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius), Vector3(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius),
KRVector3(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius) Vector3(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius)
); );
if(getBounds().intersects(sphereCastBounds)) { if(getBounds().intersects(sphereCastBounds)) {
@@ -198,7 +198,7 @@ void KRCollider::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_li
KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
// Enable additive blending // Enable additive blending
GLDEBUG(glEnable(GL_BLEND)); GLDEBUG(glEnable(GL_BLEND));

View File

@@ -57,9 +57,9 @@ public:
virtual void loadXML(tinyxml2::XMLElement *e); virtual void loadXML(tinyxml2::XMLElement *e);
virtual KRAABB getBounds(); virtual KRAABB getBounds();
bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); bool lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask);
bool rayCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); bool rayCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask);
bool sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask); bool sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask);
unsigned int getLayerMask(); unsigned int getLayerMask();
void setLayerMask(unsigned int layer_mask); void setLayerMask(unsigned int layer_mask);

View File

@@ -28,12 +28,12 @@ std::string KRDirectionalLight::getElementName() {
return "directional_light"; return "directional_light";
} }
KRVector3 KRDirectionalLight::getWorldLightDirection() { Vector3 KRDirectionalLight::getWorldLightDirection() {
return KRMat4::Dot(getWorldRotation().rotationMatrix(), getLocalLightDirection()); return KRMat4::Dot(getWorldRotation().rotationMatrix(), getLocalLightDirection());
} }
KRVector3 KRDirectionalLight::getLocalLightDirection() { Vector3 KRDirectionalLight::getLocalLightDirection() {
return KRVector3::Up(); //&KRF HACK changed from KRVector3::Forward(); - to compensate for the way Maya handles post rotation. return Vector3::Up(); //&KRF HACK changed from Vector3::Forward(); - to compensate for the way Maya handles post rotation.
} }
@@ -52,13 +52,13 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
float max_depth = 1.0f; float max_depth = 1.0f;
*/ */
KRAABB worldSpacefrustrumSliceBounds = KRAABB(KRVector3(-1.0f, -1.0f, -1.0f), KRVector3(1.0f, 1.0f, 1.0f), KRMat4::Invert(viewport.getViewProjectionMatrix())); KRAABB worldSpacefrustrumSliceBounds = KRAABB(Vector3(-1.0f, -1.0f, -1.0f), Vector3(1.0f, 1.0f, 1.0f), KRMat4::Invert(viewport.getViewProjectionMatrix()));
worldSpacefrustrumSliceBounds.scale(KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE); worldSpacefrustrumSliceBounds.scale(KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE);
KRVector3 shadowLook = -KRVector3::Normalize(getWorldLightDirection()); Vector3 shadowLook = -Vector3::Normalize(getWorldLightDirection());
KRVector3 shadowUp(0.0, 1.0, 0.0); Vector3 shadowUp(0.0, 1.0, 0.0);
if(KRVector3::Dot(shadowUp, shadowLook) > 0.99f) shadowUp = KRVector3(0.0, 0.0, 1.0); // Ensure shadow look direction is not parallel with the shadowUp direction 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
// KRMat4 matShadowView = KRMat4::LookAt(viewport.getCameraPosition() - shadowLook, viewport.getCameraPosition(), shadowUp); // KRMat4 matShadowView = KRMat4::LookAt(viewport.getCameraPosition() - shadowLook, viewport.getCameraPosition(), shadowUp);
// KRMat4 matShadowProjection = KRMat4(); // KRMat4 matShadowProjection = KRMat4();
@@ -76,8 +76,8 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
matShadowProjection *= matBias; matShadowProjection *= matBias;
KRViewport newShadowViewport = KRViewport(Vector2(KRENGINE_SHADOW_MAP_WIDTH, KRENGINE_SHADOW_MAP_HEIGHT), matShadowView, matShadowProjection); KRViewport newShadowViewport = KRViewport(Vector2(KRENGINE_SHADOW_MAP_WIDTH, KRENGINE_SHADOW_MAP_HEIGHT), matShadowView, matShadowProjection);
KRAABB prevShadowBounds = KRAABB(-KRVector3::One(), KRVector3::One(), KRMat4::Invert(m_shadowViewports[iShadow].getViewProjectionMatrix())); KRAABB prevShadowBounds = KRAABB(-Vector3::One(), Vector3::One(), KRMat4::Invert(m_shadowViewports[iShadow].getViewProjectionMatrix()));
KRAABB minimumShadowBounds = KRAABB(-KRVector3::One(), KRVector3::One(), KRMat4::Invert(newShadowViewport.getViewProjectionMatrix())); KRAABB minimumShadowBounds = KRAABB(-Vector3::One(), Vector3::One(), KRMat4::Invert(newShadowViewport.getViewProjectionMatrix()));
minimumShadowBounds.scale(1.0f / KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE); 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 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; m_shadowViewports[iShadow] = newShadowViewport;
@@ -105,12 +105,12 @@ void KRDirectionalLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &
matModelViewInverseTranspose.transpose(); matModelViewInverseTranspose.transpose();
matModelViewInverseTranspose.invert(); matModelViewInverseTranspose.invert();
KRVector3 light_direction_view_space = getWorldLightDirection(); Vector3 light_direction_view_space = getWorldLightDirection();
light_direction_view_space = KRMat4::Dot(matModelViewInverseTranspose, light_direction_view_space); light_direction_view_space = KRMat4::Dot(matModelViewInverseTranspose, light_direction_view_space);
light_direction_view_space.normalize(); light_direction_view_space.normalize();
KRShader *pShader = getContext().getShaderManager()->getShader("light_directional", pCamera, std::vector<KRPointLight *>(), this_light, std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pShader = getContext().getShaderManager()->getShader("light_directional", pCamera, std::vector<KRPointLight *>(), this_light, std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), std::vector<KRPointLight *>(), this_light, std::vector<KRSpotLight *>(), 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), std::vector<KRPointLight *>(), this_light, std::vector<KRSpotLight *>(), 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE, light_direction_view_space); pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE, light_direction_view_space);
pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color); pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color);

View File

@@ -19,8 +19,8 @@ public:
virtual ~KRDirectionalLight(); virtual ~KRDirectionalLight();
virtual std::string getElementName(); virtual std::string getElementName();
KRVector3 getLocalLightDirection(); Vector3 getLocalLightDirection();
KRVector3 getWorldLightDirection(); Vector3 getWorldLightDirection();
virtual void render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass); virtual void render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass);
virtual KRAABB getBounds(); virtual KRAABB getBounds();

View File

@@ -31,7 +31,7 @@
// #include "KRTextureManager.h" // #include "KRTextureManager.h"
#include "KRMat4.h" #include "KRMat4.h"
#include "KRVector3.h" #include "Vector3.h"
#include "KRMesh.h" #include "KRMesh.h"
#include "KRScene.h" #include "KRScene.h"
#include "KRContext.h" #include "KRContext.h"

View File

@@ -9,7 +9,7 @@ void SetUniform(GLint location, const Vector2 &v)
if (location != -1) GLDEBUG(glUniform2f(location, v.x, v.y)); if (location != -1) GLDEBUG(glUniform2f(location, v.x, v.y));
} }
void SetUniform(GLint location, const KRVector3 &v) void SetUniform(GLint location, const Vector3 &v)
{ {
if (location != -1) GLDEBUG(glUniform3f(location, v.x, v.y, v.z)); if (location != -1) GLDEBUG(glUniform3f(location, v.x, v.y, v.z));
} }
@@ -24,7 +24,7 @@ void SetUniform(GLint location, const KRMat4 &v)
if (location != -1) GLDEBUG(glUniformMatrix4fv(location, 1, GL_FALSE, v.c)); if (location != -1) GLDEBUG(glUniformMatrix4fv(location, 1, GL_FALSE, v.c));
} }
void setXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, const KRVector3 &value, const KRVector3 &default_value) void setXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, const Vector3 &value, const Vector3 &default_value)
{ {
// TODO - Increase number of digits after the decimal in floating point format (6 -> 12?) // TODO - Increase number of digits after the decimal in floating point format (6 -> 12?)
// FINDME, TODO - This needs optimization... // FINDME, TODO - This needs optimization...
@@ -35,9 +35,9 @@ void setXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, cons
} }
} }
const KRVector3 getXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, const KRVector3 &default_value) const Vector3 getXMLAttribute(const std::string &base_name, tinyxml2::XMLElement *e, const Vector3 &default_value)
{ {
KRVector3 value; Vector3 value;
if (e->QueryFloatAttribute((base_name + "_x").c_str(), &value.x) == tinyxml2::XML_SUCCESS if (e->QueryFloatAttribute((base_name + "_x").c_str(), &value.x) == tinyxml2::XML_SUCCESS
&& e->QueryFloatAttribute((base_name + "_y").c_str(), &value.y) == tinyxml2::XML_SUCCESS && e->QueryFloatAttribute((base_name + "_y").c_str(), &value.y) == tinyxml2::XML_SUCCESS
&& e->QueryFloatAttribute((base_name + "_z").c_str(), &value.z) == tinyxml2::XML_SUCCESS) { && e->QueryFloatAttribute((base_name + "_z").c_str(), &value.z) == tinyxml2::XML_SUCCESS) {

View File

@@ -18,12 +18,12 @@ float const D2R = PI * 2 / 360;
namespace kraken { namespace kraken {
void SetUniform(GLint location, const Vector2 &v); void SetUniform(GLint location, const Vector2 &v);
void SetUniform(GLint location, const KRVector3 &v); void SetUniform(GLint location, const Vector3 &v);
void SetUniform(GLint location, const KRVector4 &v); void SetUniform(GLint location, const KRVector4 &v);
void SetUniform(GLint location, const KRMat4 &v); void SetUniform(GLint location, const KRMat4 &v);
void setXMLAttribute(const std::string &base_name, ::tinyxml2::XMLElement *e, const KRVector3 &value, const KRVector3 &default_value); void setXMLAttribute(const std::string &base_name, ::tinyxml2::XMLElement *e, const Vector3 &value, const Vector3 &default_value);
const KRVector3 getXMLAttribute(const std::string &base_name, ::tinyxml2::XMLElement *e, const KRVector3 &default_value); const Vector3 getXMLAttribute(const std::string &base_name, ::tinyxml2::XMLElement *e, const Vector3 &default_value);
} // namespace kraken } // namespace kraken
#endif #endif

View File

@@ -34,13 +34,13 @@
KRHitInfo::KRHitInfo() KRHitInfo::KRHitInfo()
{ {
m_position = KRVector3::Zero(); m_position = Vector3::Zero();
m_normal = KRVector3::Zero(); m_normal = Vector3::Zero();
m_distance = 0.0f; m_distance = 0.0f;
m_node = NULL; m_node = NULL;
} }
KRHitInfo::KRHitInfo(const KRVector3 &position, const KRVector3 &normal, const float distance, KRNode *node) KRHitInfo::KRHitInfo(const Vector3 &position, const Vector3 &normal, const float distance, KRNode *node)
{ {
m_position = position; m_position = position;
m_normal = normal; m_normal = normal;
@@ -48,7 +48,7 @@ KRHitInfo::KRHitInfo(const KRVector3 &position, const KRVector3 &normal, const f
m_node = node; m_node = node;
} }
KRHitInfo::KRHitInfo(const KRVector3 &position, const KRVector3 &normal, const float distance) KRHitInfo::KRHitInfo(const Vector3 &position, const Vector3 &normal, const float distance)
{ {
m_position = position; m_position = position;
m_normal = normal; m_normal = normal;
@@ -63,15 +63,15 @@ KRHitInfo::~KRHitInfo()
bool KRHitInfo::didHit() const bool KRHitInfo::didHit() const
{ {
return m_normal != KRVector3::Zero(); return m_normal != Vector3::Zero();
} }
KRVector3 KRHitInfo::getPosition() const Vector3 KRHitInfo::getPosition() const
{ {
return m_position; return m_position;
} }
KRVector3 KRHitInfo::getNormal() const Vector3 KRHitInfo::getNormal() const
{ {
return m_normal; return m_normal;
} }

View File

@@ -41,12 +41,12 @@ class KRNode;
class KRHitInfo { class KRHitInfo {
public: public:
KRHitInfo(); KRHitInfo();
KRHitInfo(const KRVector3 &position, const KRVector3 &normal, const float distance); KRHitInfo(const Vector3 &position, const Vector3 &normal, const float distance);
KRHitInfo(const KRVector3 &position, const KRVector3 &normal, const float distance, KRNode *node); KRHitInfo(const Vector3 &position, const Vector3 &normal, const float distance, KRNode *node);
~KRHitInfo(); ~KRHitInfo();
KRVector3 getPosition() const; Vector3 getPosition() const;
KRVector3 getNormal() const; Vector3 getNormal() const;
float getDistance() const; float getDistance() const;
KRNode *getNode() const; KRNode *getNode() const;
bool didHit() const; bool didHit() const;
@@ -55,8 +55,8 @@ public:
private: private:
KRNode *m_node; KRNode *m_node;
KRVector3 m_position; Vector3 m_position;
KRVector3 m_normal; Vector3 m_normal;
float m_distance; float m_distance;
}; };

View File

@@ -14,7 +14,7 @@ KRLODGroup::KRLODGroup(KRScene &scene, std::string name) : KRNode(scene, name)
{ {
m_min_distance = 0.0f; m_min_distance = 0.0f;
m_max_distance = 0.0f; m_max_distance = 0.0f;
m_reference = KRAABB(KRVector3::Zero(), KRVector3::Zero()); m_reference = KRAABB(Vector3::Zero(), Vector3::Zero());
m_use_world_units = true; m_use_world_units = true;
} }
@@ -71,7 +71,7 @@ void KRLODGroup::loadXML(tinyxml2::XMLElement *e)
z = 0.0f; z = 0.0f;
} }
m_reference.min = KRVector3(x,y,z); m_reference.min = Vector3(x,y,z);
x=0.0f; y=0.0f; z=0.0f; x=0.0f; y=0.0f; z=0.0f;
if(e->QueryFloatAttribute("reference_max_x", &x) != tinyxml2::XML_SUCCESS) { 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) { if(e->QueryFloatAttribute("reference_max_z", &z) != tinyxml2::XML_SUCCESS) {
z = 0.0f; z = 0.0f;
} }
m_reference.max = KRVector3(x,y,z); m_reference.max = Vector3(x,y,z);
m_use_world_units = true; m_use_world_units = true;
if(e->QueryBoolAttribute("use_world_units", &m_use_world_units) != tinyxml2::XML_SUCCESS) { if(e->QueryBoolAttribute("use_world_units", &m_use_world_units) != tinyxml2::XML_SUCCESS) {
@@ -114,19 +114,19 @@ KRNode::LodVisibility KRLODGroup::calcLODVisibility(const KRViewport &viewport)
float sqr_distance; float sqr_distance;
float sqr_prestream_distance; float sqr_prestream_distance;
KRVector3 world_camera_position = viewport.getCameraPosition(); Vector3 world_camera_position = viewport.getCameraPosition();
KRVector3 local_camera_position = worldToLocal(world_camera_position); Vector3 local_camera_position = worldToLocal(world_camera_position);
KRVector3 local_reference_point = m_reference.nearestPoint(local_camera_position); Vector3 local_reference_point = m_reference.nearestPoint(local_camera_position);
if(m_use_world_units) { if(m_use_world_units) {
KRVector3 world_reference_point = localToWorld(local_reference_point); Vector3 world_reference_point = localToWorld(local_reference_point);
sqr_distance = (world_camera_position - world_reference_point).sqrMagnitude() * (lod_bias * lod_bias); sqr_distance = (world_camera_position - world_reference_point).sqrMagnitude() * (lod_bias * lod_bias);
sqr_prestream_distance = getContext().KRENGINE_PRESTREAM_DISTANCE * getContext().KRENGINE_PRESTREAM_DISTANCE; sqr_prestream_distance = getContext().KRENGINE_PRESTREAM_DISTANCE * getContext().KRENGINE_PRESTREAM_DISTANCE;
} else { } else {
sqr_distance = (local_camera_position - local_reference_point).sqrMagnitude() * (lod_bias * lod_bias); sqr_distance = (local_camera_position - local_reference_point).sqrMagnitude() * (lod_bias * lod_bias);
KRVector3 world_reference_point = localToWorld(local_reference_point); Vector3 world_reference_point = localToWorld(local_reference_point);
sqr_prestream_distance = worldToLocal(KRVector3::Normalize(world_reference_point - world_camera_position) * getContext().KRENGINE_PRESTREAM_DISTANCE).sqrMagnitude(); // TODO, FINDME - Optimize with precalc? sqr_prestream_distance = worldToLocal(Vector3::Normalize(world_reference_point - world_camera_position) * getContext().KRENGINE_PRESTREAM_DISTANCE).sqrMagnitude(); // TODO, FINDME - Optimize with precalc?
} }

View File

@@ -26,7 +26,7 @@ KRLight::KRLight(KRScene &scene, std::string name) : KRNode(scene, name)
{ {
m_intensity = 1.0f; m_intensity = 1.0f;
m_dust_particle_intensity = 1.0f; m_dust_particle_intensity = 1.0f;
m_color = KRVector3::One(); m_color = Vector3::One();
m_flareTexture = ""; m_flareTexture = "";
m_pFlareTexture = NULL; m_pFlareTexture = NULL;
m_flareSize = 0.0; m_flareSize = 0.0;
@@ -86,7 +86,7 @@ void KRLight::loadXML(tinyxml2::XMLElement *e) {
if(e->QueryFloatAttribute("color_b", &z) != tinyxml2::XML_SUCCESS) { if(e->QueryFloatAttribute("color_b", &z) != tinyxml2::XML_SUCCESS) {
z = 1.0; z = 1.0;
} }
m_color = KRVector3(x,y,z); m_color = Vector3(x,y,z);
if(e->QueryFloatAttribute("intensity", &m_intensity) != tinyxml2::XML_SUCCESS) { if(e->QueryFloatAttribute("intensity", &m_intensity) != tinyxml2::XML_SUCCESS) {
m_intensity = 100.0; m_intensity = 100.0;
@@ -156,11 +156,11 @@ float KRLight::getIntensity() {
return m_intensity; return m_intensity;
} }
const KRVector3 &KRLight::getColor() { const Vector3 &KRLight::getColor() {
return m_color; return m_color;
} }
void KRLight::setColor(const KRVector3 &color) { void KRLight::setColor(const Vector3 &color) {
m_color = color; m_color = color;
} }
@@ -220,10 +220,10 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_light
KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("dust_particle", pCamera, this_point_light, this_directional_light, this_spot_light, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("dust_particle", pCamera, this_point_light, this_directional_light, this_spot_light, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, particleModelMatrix, this_point_light, this_directional_light, this_spot_light, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, particleModelMatrix, this_point_light, this_directional_light, this_spot_light, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color * pCamera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity); pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color * pCamera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity);
pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_PARTICLE_ORIGIN, KRMat4::DotWDiv(KRMat4::Invert(particleModelMatrix), KRVector3::Zero())); pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_PARTICLE_ORIGIN, KRMat4::DotWDiv(KRMat4::Invert(particleModelMatrix), Vector3::Zero()));
pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_dust_particle_size); pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_dust_particle_size);
KRDataBlock particle_index_data; KRDataBlock particle_index_data;
@@ -256,7 +256,7 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_light
KRShader *pFogShader = m_pContext->getShaderManager()->getShader(shader_name, pCamera, this_point_light, this_directional_light, this_spot_light, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_ADDITIVE_PARTICLES); KRShader *pFogShader = m_pContext->getShaderManager()->getShader(shader_name, pCamera, this_point_light, this_directional_light, this_spot_light, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_ADDITIVE_PARTICLES);
if(getContext().getShaderManager()->selectShader(*pCamera, pFogShader, viewport, KRMat4(), this_point_light, this_directional_light, this_spot_light, 0, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader(*pCamera, pFogShader, viewport, KRMat4(), this_point_light, this_directional_light, this_spot_light, 0, KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
int slice_count = (int)(pCamera->settings.volumetric_environment_quality * 495.0) + 5; int slice_count = (int)(pCamera->settings.volumetric_environment_quality * 495.0) + 5;
float slice_near = -pCamera->settings.getPerspectiveNearZ(); float slice_near = -pCamera->settings.getPerspectiveNearZ();
@@ -284,7 +284,7 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_light
occlusion_test_sphere_matrix *= m_parentNode->getModelMatrix(); occlusion_test_sphere_matrix *= m_parentNode->getModelMatrix();
} }
if(getContext().getShaderManager()->selectShader("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, occlusion_test_sphere_matrix, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, occlusion_test_sphere_matrix, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
GLDEBUG(glGenQueriesEXT(1, &m_occlusionQuery)); GLDEBUG(glGenQueriesEXT(1, &m_occlusionQuery));
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
@@ -332,7 +332,7 @@ void KRLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_light
// Render light flare on transparency pass // Render light flare on transparency pass
KRShader *pShader = getContext().getShaderManager()->getShader("flare", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pShader = getContext().getShaderManager()->getShader("flare", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA, 1.0f); pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA, 1.0f);
pShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_flareSize); pShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, m_flareSize);
m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture, 0.0f, KRTexture::TEXTURE_USAGE_LIGHT_FLARE); m_pContext->getTextureManager()->selectTexture(0, m_pFlareTexture, 0.0f, KRTexture::TEXTURE_USAGE_LIGHT_FLARE);
@@ -449,7 +449,7 @@ void KRLight::renderShadowBuffers(KRCamera *pCamera)
// Use shader program // Use shader program
KRShader *shadowShader = m_pContext->getShaderManager()->getShader("ShadowShader", pCamera, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); KRShader *shadowShader = m_pContext->getShaderManager()->getShader("ShadowShader", pCamera, std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
getContext().getShaderManager()->selectShader(*pCamera, shadowShader, m_shadowViewports[iShadow], KRMat4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_SHADOWMAP, KRVector3::Zero(), 0.0f, KRVector4::Zero()); getContext().getShaderManager()->selectShader(*pCamera, shadowShader, m_shadowViewports[iShadow], KRMat4(), std::vector<KRPointLight *>(), std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, KRNode::RENDER_PASS_SHADOWMAP, Vector3::Zero(), 0.0f, KRVector4::Zero());
getScene().render(pCamera, m_shadowViewports[iShadow].getVisibleBounds(), m_shadowViewports[iShadow], KRNode::RENDER_PASS_SHADOWMAP, true); getScene().render(pCamera, m_shadowViewports[iShadow].getVisibleBounds(), m_shadowViewports[iShadow], KRNode::RENDER_PASS_SHADOWMAP, true);

View File

@@ -34,8 +34,8 @@ public:
float getIntensity(); float getIntensity();
void setDecayStart(float decayStart); void setDecayStart(float decayStart);
float getDecayStart(); float getDecayStart();
const KRVector3 &getColor(); const Vector3 &getColor();
void setColor(const KRVector3 &color); void setColor(const Vector3 &color);
void setFlareTexture(std::string flare_texture); void setFlareTexture(std::string flare_texture);
void setFlareSize(float flare_size); void setFlareSize(float flare_size);
@@ -54,7 +54,7 @@ protected:
float m_intensity; float m_intensity;
float m_decayStart; float m_decayStart;
KRVector3 m_color; Vector3 m_color;
std::string m_flareTexture; std::string m_flareTexture;
KRTexture *m_pFlareTexture; KRTexture *m_pFlareTexture;

View File

@@ -49,7 +49,7 @@ KRMat4::KRMat4(float *pMat) {
memcpy(c, pMat, sizeof(float) * 16); memcpy(c, pMat, sizeof(float) * 16);
} }
KRMat4::KRMat4(const KRVector3 &axis_x, const KRVector3 &axis_y, const KRVector3 &axis_z, const KRVector3 &trans) KRMat4::KRMat4(const Vector3 &axis_x, const Vector3 &axis_y, const Vector3 &axis_z, const Vector3 &trans)
{ {
c[0] = axis_x.x; c[1] = axis_x.y; c[2] = axis_x.z; c[3] = 0.0f; c[0] = axis_x.x; c[1] = axis_x.y; c[2] = axis_x.z; c[3] = 0.0f;
c[4] = axis_y.x; c[5] = axis_y.y; c[6] = axis_y.z; c[7] = 0.0f; c[4] = axis_y.x; c[5] = axis_y.y; c[6] = axis_y.z; c[7] = 0.0f;
@@ -155,7 +155,7 @@ void KRMat4::translate(float x, float y, float z) {
*this *= newMatrix; *this *= newMatrix;
} }
void KRMat4::translate(const KRVector3 &v) void KRMat4::translate(const Vector3 &v)
{ {
translate(v.x, v.y, v.z); translate(v.x, v.y, v.z);
} }
@@ -217,7 +217,7 @@ void KRMat4::scale(float x, float y, float z) {
*this *= newMatrix; *this *= newMatrix;
} }
void KRMat4::scale(const KRVector3 &v) { void KRMat4::scale(const Vector3 &v) {
scale(v.x, v.y, v.z); scale(v.x, v.y, v.z);
} }
@@ -313,9 +313,9 @@ void KRMat4::transpose() {
memcpy(c, trans, sizeof(float) * 16); memcpy(c, trans, sizeof(float) * 16);
} }
/* Dot Product, returning KRVector3 */ /* Dot Product, returning Vector3 */
KRVector3 KRMat4::Dot(const KRMat4 &m, const KRVector3 &v) { Vector3 KRMat4::Dot(const KRMat4 &m, const Vector3 &v) {
return KRVector3( 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[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[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[2] + v.c[1] * m.c[6] + v.c[2] * m.c[10] + m.c[14]
@@ -355,9 +355,9 @@ KRVector4 KRMat4::Dot4(const KRMat4 &m, const KRVector4 &v) {
} }
// Dot product without including translation; useful for transforming normals and tangents // Dot product without including translation; useful for transforming normals and tangents
KRVector3 KRMat4::DotNoTranslate(const KRMat4 &m, const KRVector3 &v) Vector3 KRMat4::DotNoTranslate(const KRMat4 &m, const Vector3 &v)
{ {
return KRVector3( return Vector3(
v.x * m.c[0] + v.y * m.c[4] + v.z * m.c[8], 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[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] v.x * m.c[2] + v.y * m.c[6] + v.z * m.c[10]
@@ -365,24 +365,24 @@ KRVector3 KRMat4::DotNoTranslate(const KRMat4 &m, const KRVector3 &v)
} }
/* Dot Product, returning w component as if it were a KRVector4 (This will be deprecated once KRVector4 is implemented instead*/ /* Dot Product, returning w component as if it were a KRVector4 (This will be deprecated once KRVector4 is implemented instead*/
float KRMat4::DotW(const KRMat4 &m, const KRVector3 &v) { float KRMat4::DotW(const KRMat4 &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]; 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 */ /* Dot Product followed by W-divide */
KRVector3 KRMat4::DotWDiv(const KRMat4 &m, const KRVector3 &v) { Vector3 KRMat4::DotWDiv(const KRMat4 &m, const Vector3 &v) {
KRVector4 r = Dot4(m, KRVector4(v, 1.0f)); KRVector4 r = Dot4(m, KRVector4(v, 1.0f));
return KRVector3(r) / r.w; return Vector3(r) / r.w;
} }
KRMat4 KRMat4::LookAt(const KRVector3 &cameraPos, const KRVector3 &lookAtPos, const KRVector3 &upDirection) KRMat4 KRMat4::LookAt(const Vector3 &cameraPos, const Vector3 &lookAtPos, const Vector3 &upDirection)
{ {
KRMat4 matLookat; KRMat4 matLookat;
KRVector3 lookat_z_axis = lookAtPos - cameraPos; Vector3 lookat_z_axis = lookAtPos - cameraPos;
lookat_z_axis.normalize(); lookat_z_axis.normalize();
KRVector3 lookat_x_axis = KRVector3::Cross(upDirection, lookat_z_axis); Vector3 lookat_x_axis = Vector3::Cross(upDirection, lookat_z_axis);
lookat_x_axis.normalize(); lookat_x_axis.normalize();
KRVector3 lookat_y_axis = KRVector3::Cross(lookat_z_axis, lookat_x_axis); Vector3 lookat_y_axis = Vector3::Cross(lookat_z_axis, lookat_x_axis);
matLookat.getPointer()[0] = lookat_x_axis.x; matLookat.getPointer()[0] = lookat_x_axis.x;
matLookat.getPointer()[1] = lookat_y_axis.x; matLookat.getPointer()[1] = lookat_y_axis.x;
@@ -396,9 +396,9 @@ KRMat4 KRMat4::LookAt(const KRVector3 &cameraPos, const KRVector3 &lookAtPos, co
matLookat.getPointer()[9] = lookat_y_axis.z; matLookat.getPointer()[9] = lookat_y_axis.z;
matLookat.getPointer()[10] = lookat_z_axis.z; matLookat.getPointer()[10] = lookat_z_axis.z;
matLookat.getPointer()[12] = -KRVector3::Dot(lookat_x_axis, cameraPos); matLookat.getPointer()[12] = -Vector3::Dot(lookat_x_axis, cameraPos);
matLookat.getPointer()[13] = -KRVector3::Dot(lookat_y_axis, cameraPos); matLookat.getPointer()[13] = -Vector3::Dot(lookat_y_axis, cameraPos);
matLookat.getPointer()[14] = -KRVector3::Dot(lookat_z_axis, cameraPos); matLookat.getPointer()[14] = -Vector3::Dot(lookat_z_axis, cameraPos);
return matLookat; return matLookat;
} }
@@ -417,7 +417,7 @@ KRMat4 KRMat4::Transpose(const KRMat4 &m)
return matTranspose; return matTranspose;
} }
KRMat4 KRMat4::Translation(const KRVector3 &v) KRMat4 KRMat4::Translation(const Vector3 &v)
{ {
KRMat4 m; KRMat4 m;
m[12] = v.x; m[12] = v.x;
@@ -427,7 +427,7 @@ KRMat4 KRMat4::Translation(const KRVector3 &v)
return m; return m;
} }
KRMat4 KRMat4::Rotation(const KRVector3 &v) KRMat4 KRMat4::Rotation(const Vector3 &v)
{ {
KRMat4 m; KRMat4 m;
m.rotate(v.x, X_AXIS); m.rotate(v.x, X_AXIS);
@@ -436,7 +436,7 @@ KRMat4 KRMat4::Rotation(const KRVector3 &v)
return m; return m;
} }
KRMat4 KRMat4::Scaling(const KRVector3 &v) KRMat4 KRMat4::Scaling(const Vector3 &v)
{ {
KRMat4 m; KRMat4 m;
m.scale(v); m.scale(v);

View File

@@ -44,10 +44,10 @@ KRMaterial::KRMaterial(KRContext &context, const char *szName) : KRResource(cont
m_pNormalMap = NULL; m_pNormalMap = NULL;
m_pReflectionMap = NULL; m_pReflectionMap = NULL;
m_pReflectionCube = NULL; m_pReflectionCube = NULL;
m_ambientColor = KRVector3::Zero(); m_ambientColor = Vector3::Zero();
m_diffuseColor = KRVector3::One(); m_diffuseColor = Vector3::One();
m_specularColor = KRVector3::One(); m_specularColor = Vector3::One();
m_reflectionColor = KRVector3::Zero(); m_reflectionColor = Vector3::Zero();
m_tr = (GLfloat)1.0f; m_tr = (GLfloat)1.0f;
m_ns = (GLfloat)0.0f; m_ns = (GLfloat)0.0f;
m_ambientMap = ""; m_ambientMap = "";
@@ -186,19 +186,19 @@ KRMaterial::alpha_mode_type KRMaterial::getAlphaMode() {
return m_alpha_mode; return m_alpha_mode;
} }
void KRMaterial::setAmbient(const KRVector3 &c) { void KRMaterial::setAmbient(const Vector3 &c) {
m_ambientColor = c; m_ambientColor = c;
} }
void KRMaterial::setDiffuse(const KRVector3 &c) { void KRMaterial::setDiffuse(const Vector3 &c) {
m_diffuseColor = c; m_diffuseColor = c;
} }
void KRMaterial::setSpecular(const KRVector3 &c) { void KRMaterial::setSpecular(const Vector3 &c) {
m_specularColor = c; m_specularColor = c;
} }
void KRMaterial::setReflection(const KRVector3 &c) { void KRMaterial::setReflection(const Vector3 &c) {
m_reflectionColor = c; m_reflectionColor = c;
} }
@@ -302,7 +302,7 @@ void KRMaterial::getTextures()
} }
} }
bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const std::vector<KRBone *> &bones, const std::vector<KRMat4> &bind_poses, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const KRVector3 &rim_color, float rim_power, float lod_coverage) { bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const std::vector<KRBone *> &bones, const std::vector<KRMat4> &bind_poses, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const Vector3 &rim_color, float rim_power, float lod_coverage) {
bool bLightMap = pLightMap && pCamera->settings.bEnableLightMap; bool bLightMap = pLightMap && pCamera->settings.bEnableLightMap;
getTextures(); getTextures();
@@ -310,7 +310,7 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_ligh
Vector2 default_scale = Vector2::One(); Vector2 default_scale = Vector2::One();
Vector2 default_offset = Vector2::Zero(); Vector2 default_offset = Vector2::Zero();
bool bHasReflection = m_reflectionColor != KRVector3::Zero(); bool bHasReflection = m_reflectionColor != Vector3::Zero();
bool bDiffuseMap = m_pDiffuseMap != NULL && pCamera->settings.bEnableDiffuseMap; bool bDiffuseMap = m_pDiffuseMap != NULL && pCamera->settings.bEnableDiffuseMap;
bool bNormalMap = m_pNormalMap != NULL && pCamera->settings.bEnableNormalMap; bool bNormalMap = m_pNormalMap != NULL && pCamera->settings.bEnableNormalMap;
bool bSpecMap = m_pSpecularMap != NULL && pCamera->settings.bEnableSpecMap; bool bSpecMap = m_pSpecularMap != NULL && pCamera->settings.bEnableSpecMap;
@@ -334,12 +334,12 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_ligh
for(int bone_index=0; bone_index < bones.size(); bone_index++) { for(int bone_index=0; bone_index < bones.size(); bone_index++) {
KRBone *bone = bones[bone_index]; KRBone *bone = bones[bone_index];
// KRVector3 initialRotation = bone->getInitialLocalRotation(); // Vector3 initialRotation = bone->getInitialLocalRotation();
// KRVector3 rotation = bone->getLocalRotation(); // Vector3 rotation = bone->getLocalRotation();
// KRVector3 initialTranslation = bone->getInitialLocalTranslation(); // Vector3 initialTranslation = bone->getInitialLocalTranslation();
// KRVector3 translation = bone->getLocalTranslation(); // Vector3 translation = bone->getLocalTranslation();
// KRVector3 initialScale = bone->getInitialLocalScale(); // Vector3 initialScale = bone->getInitialLocalScale();
// KRVector3 scale = bone->getLocalScale(); // Vector3 scale = bone->getLocalScale();
// //
//printf("%s - delta rotation: %.4f %.4f %.4f\n", bone->getName().c_str(), (rotation.x - initialRotation.x) * 180.0 / M_PI, (rotation.y - initialRotation.y) * 180.0 / M_PI, (rotation.z - initialRotation.z) * 180.0 / M_PI); //printf("%s - delta rotation: %.4f %.4f %.4f\n", bone->getName().c_str(), (rotation.x - initialRotation.x) * 180.0 / M_PI, (rotation.y - initialRotation.y) * 180.0 / M_PI, (rotation.z - initialRotation.z) * 180.0 / M_PI);
//printf("%s - delta translation: %.4f %.4f %.4f\n", bone->getName().c_str(), translation.x - initialTranslation.x, translation.y - initialTranslation.y, translation.z - initialTranslation.z); //printf("%s - delta translation: %.4f %.4f %.4f\n", bone->getName().c_str(), translation.x - initialTranslation.x, translation.y - initialTranslation.y, translation.z - initialTranslation.z);
@@ -365,14 +365,14 @@ bool KRMaterial::bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_ligh
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) { if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
// We pre-multiply the light color with the material color in the forward renderer // We pre-multiply the light color with the material color in the forward renderer
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, KRVector3(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(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 { } else {
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, m_diffuseColor); pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_DIFFUSE, m_diffuseColor);
} }
if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) { if(renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE) {
// We pre-multiply the light color with the material color in the forward renderer // We pre-multiply the light color with the material color in the forward renderer
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR, KRVector3(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(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 { } else {
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR, m_specularColor); pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_SPECULAR, m_specularColor);
} }

View File

@@ -69,10 +69,10 @@ public:
void setReflectionMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset); void setReflectionMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset);
void setReflectionCube(std::string texture_name); void setReflectionCube(std::string texture_name);
void setNormalMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset); void setNormalMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset);
void setAmbient(const KRVector3 &c); void setAmbient(const Vector3 &c);
void setDiffuse(const KRVector3 &c); void setDiffuse(const Vector3 &c);
void setSpecular(const KRVector3 &c); void setSpecular(const Vector3 &c);
void setReflection(const KRVector3 &c); void setReflection(const Vector3 &c);
void setTransparency(GLfloat a); void setTransparency(GLfloat a);
void setShininess(GLfloat s); void setShininess(GLfloat s);
void setAlphaMode(alpha_mode_type blend_mode); void setAlphaMode(alpha_mode_type blend_mode);
@@ -82,7 +82,7 @@ public:
bool isTransparent(); bool isTransparent();
const std::string &getName() const; const std::string &getName() const;
bool bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const std::vector<KRBone *> &bones, const std::vector<KRMat4> &bind_poses, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const KRVector3 &rim_color, float rim_power, float lod_coverage = 0.0f); bool bind(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const std::vector<KRBone *> &bones, const std::vector<KRMat4> &bind_poses, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const Vector3 &rim_color, float rim_power, float lod_coverage = 0.0f);
bool needsVertexTangents(); bool needsVertexTangents();
@@ -116,10 +116,10 @@ private:
Vector2 m_normalMapScale; Vector2 m_normalMapScale;
Vector2 m_normalMapOffset; Vector2 m_normalMapOffset;
KRVector3 m_ambientColor; // Ambient rgb Vector3 m_ambientColor; // Ambient rgb
KRVector3 m_diffuseColor; // Diffuse rgb Vector3 m_diffuseColor; // Diffuse rgb
KRVector3 m_specularColor; // Specular rgb Vector3 m_specularColor; // Specular rgb
KRVector3 m_reflectionColor; // Reflection rgb Vector3 m_reflectionColor; // Reflection rgb
//GLfloat m_ka_r, m_ka_g, m_ka_b; // Ambient rgb //GLfloat m_ka_r, m_ka_g, m_ka_b; // Ambient rgb
//GLfloat m_kd_r, m_kd_g, m_kd_b; // Diffuse rgb //GLfloat m_kd_r, m_kd_g, m_kd_b; // Diffuse rgb

View File

@@ -162,49 +162,49 @@ bool KRMaterialManager::load(const char *szName, KRDataBlock *data) {
char *pScan2 = szSymbol[1]; char *pScan2 = szSymbol[1];
float r = strtof(pScan2, &pScan2); float r = strtof(pScan2, &pScan2);
if(cSymbols == 2) { if(cSymbols == 2) {
pMaterial->setAmbient(KRVector3(r, r, r)); pMaterial->setAmbient(Vector3(r, r, r));
} else if(cSymbols == 4) { } else if(cSymbols == 4) {
pScan2 = szSymbol[2]; pScan2 = szSymbol[2];
float g = strtof(pScan2, &pScan2); float g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3]; pScan2 = szSymbol[3];
float b = strtof(pScan2, &pScan2); float b = strtof(pScan2, &pScan2);
pMaterial->setAmbient(KRVector3(r, g, b)); pMaterial->setAmbient(Vector3(r, g, b));
} }
} else if(strcmp(szSymbol[0], "kd") == 0) { } else if(strcmp(szSymbol[0], "kd") == 0) {
char *pScan2 = szSymbol[1]; char *pScan2 = szSymbol[1];
float r = strtof(pScan2, &pScan2); float r = strtof(pScan2, &pScan2);
if(cSymbols == 2) { if(cSymbols == 2) {
pMaterial->setDiffuse(KRVector3(r, r, r)); pMaterial->setDiffuse(Vector3(r, r, r));
} else if(cSymbols == 4) { } else if(cSymbols == 4) {
pScan2 = szSymbol[2]; pScan2 = szSymbol[2];
float g = strtof(pScan2, &pScan2); float g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3]; pScan2 = szSymbol[3];
float b = strtof(pScan2, &pScan2); float b = strtof(pScan2, &pScan2);
pMaterial->setDiffuse(KRVector3(r, g, b)); pMaterial->setDiffuse(Vector3(r, g, b));
} }
} else if(strcmp(szSymbol[0], "ks") == 0) { } else if(strcmp(szSymbol[0], "ks") == 0) {
char *pScan2 = szSymbol[1]; char *pScan2 = szSymbol[1];
float r = strtof(pScan2, &pScan2); float r = strtof(pScan2, &pScan2);
if(cSymbols == 2) { if(cSymbols == 2) {
pMaterial->setSpecular(KRVector3(r, r, r)); pMaterial->setSpecular(Vector3(r, r, r));
} else if(cSymbols == 4) { } else if(cSymbols == 4) {
pScan2 = szSymbol[2]; pScan2 = szSymbol[2];
float g = strtof(pScan2, &pScan2); float g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3]; pScan2 = szSymbol[3];
float b = strtof(pScan2, &pScan2); float b = strtof(pScan2, &pScan2);
pMaterial->setSpecular(KRVector3(r, g, b)); pMaterial->setSpecular(Vector3(r, g, b));
} }
} else if(strcmp(szSymbol[0], "kr") == 0) { } else if(strcmp(szSymbol[0], "kr") == 0) {
char *pScan2 = szSymbol[1]; char *pScan2 = szSymbol[1];
float r = strtof(pScan2, &pScan2); float r = strtof(pScan2, &pScan2);
if(cSymbols == 2) { if(cSymbols == 2) {
pMaterial->setReflection(KRVector3(r, r, r)); pMaterial->setReflection(Vector3(r, r, r));
} else if(cSymbols == 4) { } else if(cSymbols == 4) {
pScan2 = szSymbol[2]; pScan2 = szSymbol[2];
float g = strtof(pScan2, &pScan2); float g = strtof(pScan2, &pScan2);
pScan2 = szSymbol[3]; pScan2 = szSymbol[3];
float b = strtof(pScan2, &pScan2); float b = strtof(pScan2, &pScan2);
pMaterial->setReflection(KRVector3(r, g, b)); pMaterial->setReflection(Vector3(r, g, b));
} }
} else if(strcmp(szSymbol[0], "tr") == 0) { } else if(strcmp(szSymbol[0], "tr") == 0) {
char *pScan2 = szSymbol[1]; char *pScan2 = szSymbol[1];

View File

@@ -159,8 +159,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 = 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_pIndexBaseData->lock();
m_minPoint = KRVector3(ph.minx, ph.miny, ph.minz); m_minPoint = Vector3(ph.minx, ph.miny, ph.minz);
m_maxPoint = KRVector3(ph.maxx, ph.maxy, ph.maxz); m_maxPoint = Vector3(ph.maxx, ph.maxy, ph.maxz);
updateAttributeOffsets(); updateAttributeOffsets();
} }
@@ -254,7 +254,7 @@ kraken_stream_level KRMesh::getStreamLevel()
return stream_level; return stream_level;
} }
void KRMesh::render(const std::string &object_name, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector<KRBone *> &bones, const KRVector3 &rim_color, float rim_power, float lod_coverage) { void KRMesh::render(const std::string &object_name, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector<KRBone *> &bones, const Vector3 &rim_color, float rim_power, float lod_coverage) {
//fprintf(stderr, "Rendering model: %s\n", m_name.c_str()); //fprintf(stderr, "Rendering model: %s\n", m_name.c_str());
if(renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_PARTICLE_OCCLUSION && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) { if(renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_PARTICLE_OCCLUSION && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) {
@@ -532,7 +532,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool
bool use_short_uvb = true; bool use_short_uvb = true;
if(use_short_vertexes) { if(use_short_vertexes) {
for(std::vector<KRVector3>::const_iterator itr=mi.vertices.begin(); itr != mi.vertices.end(); itr++) { for(std::vector<Vector3>::const_iterator itr=mi.vertices.begin(); itr != mi.vertices.end(); itr++) {
if(fabsf((*itr).x) > 1.0f || fabsf((*itr).y) > 1.0f || fabsf((*itr).z) > 1.0f) { if(fabsf((*itr).x) > 1.0f || fabsf((*itr).y) > 1.0f || fabsf((*itr).z) > 1.0f) {
use_short_vertexes = false; use_short_vertexes = false;
} }
@@ -638,7 +638,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool
memset(getVertexData(), 0, m_vertex_size * mi.vertices.size()); memset(getVertexData(), 0, m_vertex_size * mi.vertices.size());
for(int iVertex=0; iVertex < mi.vertices.size(); iVertex++) { for(int iVertex=0; iVertex < mi.vertices.size(); iVertex++) {
KRVector3 source_vertex = mi.vertices[iVertex]; Vector3 source_vertex = mi.vertices[iVertex];
setVertexPosition(iVertex, source_vertex); setVertexPosition(iVertex, source_vertex);
if(mi.bone_names.size()) { if(mi.bone_names.size()) {
for(int bone_weight_index=0; bone_weight_index<KRENGINE_MAX_BONE_WEIGHTS_PER_VERTEX; bone_weight_index++) { for(int bone_weight_index=0; bone_weight_index<KRENGINE_MAX_BONE_WEIGHTS_PER_VERTEX; bone_weight_index++) {
@@ -665,10 +665,10 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool
setVertexUVB(iVertex, mi.uvb[iVertex]); setVertexUVB(iVertex, mi.uvb[iVertex]);
} }
if(mi.normals.size() > iVertex) { if(mi.normals.size() > iVertex) {
setVertexNormal(iVertex, KRVector3::Normalize(mi.normals[iVertex])); setVertexNormal(iVertex, Vector3::Normalize(mi.normals[iVertex]));
} }
if(mi.tangents.size() > iVertex) { if(mi.tangents.size() > iVertex) {
setVertexTangent(iVertex, KRVector3::Normalize(mi.tangents[iVertex])); setVertexTangent(iVertex, Vector3::Normalize(mi.tangents[iVertex]));
} }
} }
@@ -697,19 +697,19 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool
if(calculate_normals || calculate_tangents) { if(calculate_normals || calculate_tangents) {
// NOTE: This will not work properly if the vertices are already indexed // NOTE: This will not work properly if the vertices are already indexed
for(int iVertex=0; iVertex < mi.vertices.size(); iVertex+= 3) { for(int iVertex=0; iVertex < mi.vertices.size(); iVertex+= 3) {
KRVector3 p1 = getVertexPosition(iVertex); Vector3 p1 = getVertexPosition(iVertex);
KRVector3 p2 = getVertexPosition(iVertex+1); Vector3 p2 = getVertexPosition(iVertex+1);
KRVector3 p3 = getVertexPosition(iVertex+2); Vector3 p3 = getVertexPosition(iVertex+2);
KRVector3 v1 = p2 - p1; Vector3 v1 = p2 - p1;
KRVector3 v2 = p3 - p1; Vector3 v2 = p3 - p1;
// -- Calculate normal if missing -- // -- Calculate normal if missing --
if(calculate_normals) { if(calculate_normals) {
KRVector3 first_normal = getVertexNormal(iVertex); Vector3 first_normal = getVertexNormal(iVertex);
if(first_normal.x == 0.0f && first_normal.y == 0.0f && first_normal.z == 0.0f) { if(first_normal.x == 0.0f && first_normal.y == 0.0f && first_normal.z == 0.0f) {
// Note - We don't take into consideration smoothing groups or smoothing angles when generating normals; all generated normals represent flat shaded polygons // Note - We don't take into consideration smoothing groups or smoothing angles when generating normals; all generated normals represent flat shaded polygons
KRVector3 normal = KRVector3::Cross(v1, v2); Vector3 normal = Vector3::Cross(v1, v2);
normal.normalize(); normal.normalize();
setVertexNormal(iVertex, normal); setVertexNormal(iVertex, normal);
@@ -720,7 +720,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool
// -- Calculate tangent vector for normal mapping -- // -- Calculate tangent vector for normal mapping --
if(calculate_tangents) { if(calculate_tangents) {
KRVector3 first_tangent = getVertexTangent(iVertex); Vector3 first_tangent = getVertexTangent(iVertex);
if(first_tangent.x == 0.0f && first_tangent.y == 0.0f && first_tangent.z == 0.0f) { if(first_tangent.x == 0.0f && first_tangent.y == 0.0f && first_tangent.z == 0.0f) {
Vector2 uv0 = getVertexUVA(iVertex); Vector2 uv0 = getVertexUVA(iVertex);
@@ -731,7 +731,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool
Vector2 st2 = Vector2(uv2.x - uv0.x, uv2.y - uv0.y); Vector2 st2 = Vector2(uv2.x - uv0.x, uv2.y - uv0.y);
double coef = 1/ (st1.x * st2.y - st2.x * st1.y); double coef = 1/ (st1.x * st2.y - st2.x * st1.y);
KRVector3 tangent( Vector3 tangent(
coef * ((v1.x * st2.y) + (v2.x * -st1.y)), coef * ((v1.x * st2.y) + (v2.x * -st1.y)),
coef * ((v1.y * st2.y) + (v2.y * -st1.y)), coef * ((v1.y * st2.y) + (v2.y * -st1.y)),
coef * ((v1.z * st2.y) + (v2.z * -st1.y)) coef * ((v1.z * st2.y) + (v2.z * -st1.y))
@@ -762,11 +762,11 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool
optimize(); optimize();
} }
KRVector3 KRMesh::getMinPoint() const { Vector3 KRMesh::getMinPoint() const {
return m_minPoint; return m_minPoint;
} }
KRVector3 KRMesh::getMaxPoint() const { Vector3 KRMesh::getMaxPoint() const {
return m_maxPoint; return m_maxPoint;
} }
@@ -857,39 +857,39 @@ int KRMesh::getVertexCount(int submesh) const
return getSubmesh(submesh)->vertex_count; return getSubmesh(submesh)->vertex_count;
} }
KRVector3 KRMesh::getVertexPosition(int index) const Vector3 KRMesh::getVertexPosition(int index) const
{ {
if(has_vertex_attribute(KRENGINE_ATTRIB_VERTEX_SHORT)) { if(has_vertex_attribute(KRENGINE_ATTRIB_VERTEX_SHORT)) {
short *v = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX_SHORT]); short *v = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX_SHORT]);
return KRVector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f); return Vector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f);
} else if(has_vertex_attribute(KRENGINE_ATTRIB_VERTEX)) { } else if(has_vertex_attribute(KRENGINE_ATTRIB_VERTEX)) {
return KRVector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX])); return Vector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX]));
} else { } else {
return KRVector3::Zero(); return Vector3::Zero();
} }
} }
KRVector3 KRMesh::getVertexNormal(int index) const Vector3 KRMesh::getVertexNormal(int index) const
{ {
if(has_vertex_attribute(KRENGINE_ATTRIB_NORMAL_SHORT)) { if(has_vertex_attribute(KRENGINE_ATTRIB_NORMAL_SHORT)) {
short *v = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL_SHORT]); short *v = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL_SHORT]);
return KRVector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f); return Vector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f);
} else if(has_vertex_attribute(KRENGINE_ATTRIB_NORMAL)) { } else if(has_vertex_attribute(KRENGINE_ATTRIB_NORMAL)) {
return KRVector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL])); return Vector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL]));
} else { } else {
return KRVector3::Zero(); return Vector3::Zero();
} }
} }
KRVector3 KRMesh::getVertexTangent(int index) const Vector3 KRMesh::getVertexTangent(int index) const
{ {
if(has_vertex_attribute(KRENGINE_ATTRIB_TANGENT_SHORT)) { if(has_vertex_attribute(KRENGINE_ATTRIB_TANGENT_SHORT)) {
short *v = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT_SHORT]); short *v = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT_SHORT]);
return KRVector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f); return Vector3((float)v[0] / 32767.0f, (float)v[1] / 32767.0f, (float)v[2] / 32767.0f);
} else if(has_vertex_attribute(KRENGINE_ATTRIB_TANGENT)) { } else if(has_vertex_attribute(KRENGINE_ATTRIB_TANGENT)) {
return KRVector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT])); return Vector3((float *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT]));
} else { } else {
return KRVector3::Zero(); return Vector3::Zero();
} }
} }
@@ -917,7 +917,7 @@ Vector2 KRMesh::getVertexUVB(int index) const
} }
} }
void KRMesh::setVertexPosition(int index, const KRVector3 &v) void KRMesh::setVertexPosition(int index, const Vector3 &v)
{ {
if(has_vertex_attribute(KRENGINE_ATTRIB_VERTEX_SHORT)) { if(has_vertex_attribute(KRENGINE_ATTRIB_VERTEX_SHORT)) {
short *vert = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX_SHORT]); short *vert = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_VERTEX_SHORT]);
@@ -932,7 +932,7 @@ void KRMesh::setVertexPosition(int index, const KRVector3 &v)
} }
} }
void KRMesh::setVertexNormal(int index, const KRVector3 &v) void KRMesh::setVertexNormal(int index, const Vector3 &v)
{ {
if(has_vertex_attribute(KRENGINE_ATTRIB_NORMAL_SHORT)) { if(has_vertex_attribute(KRENGINE_ATTRIB_NORMAL_SHORT)) {
short *vert = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL_SHORT]); short *vert = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_NORMAL_SHORT]);
@@ -947,7 +947,7 @@ void KRMesh::setVertexNormal(int index, const KRVector3 &v)
} }
} }
void KRMesh::setVertexTangent(int index, const KRVector3 & v) void KRMesh::setVertexTangent(int index, const Vector3 & v)
{ {
if(has_vertex_attribute(KRENGINE_ATTRIB_TANGENT_SHORT)) { if(has_vertex_attribute(KRENGINE_ATTRIB_TANGENT_SHORT)) {
short *vert = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT_SHORT]); short *vert = (short *)(getVertexData(index) + m_vertex_attribute_offset[KRENGINE_ATTRIB_TANGENT_SHORT]);
@@ -1104,9 +1104,9 @@ KRMesh::model_format_t KRMesh::getModelFormat() const
return f; return f;
} }
bool KRMesh::rayCast(const KRVector3 &start, const KRVector3 &dir, const KRTriangle3 &tri, const KRVector3 &tri_n0, const KRVector3 &tri_n1, const KRVector3 &tri_n2, KRHitInfo &hitinfo) bool KRMesh::rayCast(const Vector3 &start, const Vector3 &dir, const KRTriangle3 &tri, const Vector3 &tri_n0, const Vector3 &tri_n1, const Vector3 &tri_n2, KRHitInfo &hitinfo)
{ {
KRVector3 hit_point; Vector3 hit_point;
if(tri.rayCast(start, dir, hit_point)) { if(tri.rayCast(start, dir, hit_point)) {
// ---===--- hit_point is in triangle ---===--- // ---===--- hit_point is in triangle ---===---
@@ -1122,7 +1122,7 @@ bool KRMesh::rayCast(const KRVector3 &start, const KRVector3 &dir, const KRTrian
distance_v0 /= distance_total; distance_v0 /= distance_total;
distance_v1 /= distance_total; distance_v1 /= distance_total;
distance_v2 /= distance_total; distance_v2 /= distance_total;
KRVector3 normal = KRVector3::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.0 - distance_v0) + tri_n1 * (1.0 - distance_v1) + tri_n2 * (1.0 - distance_v2));
hitinfo = KRHitInfo(hit_point, normal, new_hit_distance); hitinfo = KRHitInfo(hit_point, normal, new_hit_distance);
return true; return true;
@@ -1138,7 +1138,7 @@ bool KRMesh::rayCast(const KRVector3 &start, const KRVector3 &dir, const KRTrian
} }
bool KRMesh::rayCast(const KRVector3 &start, const KRVector3 &dir, KRHitInfo &hitinfo) const bool KRMesh::rayCast(const Vector3 &start, const Vector3 &dir, KRHitInfo &hitinfo) const
{ {
m_pData->lock(); m_pData->lock();
bool hit_found = false; bool hit_found = false;
@@ -1184,7 +1184,7 @@ bool KRMesh::rayCast(const KRVector3 &start, const KRVector3 &dir, KRHitInfo &hi
} }
bool KRMesh::sphereCast(const KRMat4 &model_to_world, const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo) const bool KRMesh::sphereCast(const KRMat4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo) const
{ {
m_pData->lock(); m_pData->lock();
@@ -1236,13 +1236,13 @@ bool KRMesh::sphereCast(const KRMat4 &model_to_world, const KRVector3 &v0, const
return hit_found; return hit_found;
} }
bool KRMesh::sphereCast(const KRMat4 &model_to_world, const KRVector3 &v0, const KRVector3 &v1, float radius, const KRTriangle3 &tri, KRHitInfo &hitinfo) bool KRMesh::sphereCast(const KRMat4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, const KRTriangle3 &tri, KRHitInfo &hitinfo)
{ {
KRVector3 dir = KRVector3::Normalize(v1 - v0); Vector3 dir = Vector3::Normalize(v1 - v0);
KRVector3 start = v0; Vector3 start = v0;
KRVector3 new_hit_point; Vector3 new_hit_point;
float new_hit_distance; float new_hit_distance;
KRTriangle3 world_tri = KRTriangle3(KRMat4::Dot(model_to_world, tri[0]), KRMat4::Dot(model_to_world, tri[1]), KRMat4::Dot(model_to_world, tri[2])); KRTriangle3 world_tri = KRTriangle3(KRMat4::Dot(model_to_world, tri[0]), KRMat4::Dot(model_to_world, tri[1]), KRMat4::Dot(model_to_world, tri[2]));
@@ -1259,7 +1259,7 @@ bool KRMesh::sphereCast(const KRMat4 &model_to_world, const KRVector3 &v0, const
distance_v0 /= distance_total; distance_v0 /= distance_total;
distance_v1 /= distance_total; distance_v1 /= distance_total;
distance_v2 /= distance_total; distance_v2 /= distance_total;
KRVector3 normal = KRVector3::Normalize(KRMat4::DotNoTranslate(model_to_world, (tri_n0 * (1.0 - distance_v0) + tri_n1 * (1.0 - distance_v1) + tri_n2 * (1.0 - distance_v2)))); Vector3 normal = Vector3::Normalize(KRMat4::DotNoTranslate(model_to_world, (tri_n0 * (1.0 - distance_v0) + tri_n1 * (1.0 - distance_v1) + tri_n2 * (1.0 - distance_v2))));
*/ */
hitinfo = KRHitInfo(new_hit_point, world_tri.calculateNormal(), new_hit_distance); hitinfo = KRHitInfo(new_hit_point, world_tri.calculateNormal(), new_hit_distance);
return true; return true;
@@ -1269,11 +1269,11 @@ bool KRMesh::sphereCast(const KRMat4 &model_to_world, const KRVector3 &v0, const
return false; return false;
} }
bool KRMesh::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo) const bool KRMesh::lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo) const
{ {
m_pData->lock(); m_pData->lock();
KRHitInfo new_hitinfo; KRHitInfo new_hitinfo;
KRVector3 dir = KRVector3::Normalize(v1 - v0); Vector3 dir = Vector3::Normalize(v1 - v0);
if(rayCast(v0, dir, new_hitinfo)) { if(rayCast(v0, dir, new_hitinfo)) {
if((new_hitinfo.getPosition() - v0).sqrMagnitude() <= (v1 - v0).sqrMagnitude()) { if((new_hitinfo.getPosition() - v0).sqrMagnitude() <= (v1 - v0).sqrMagnitude()) {
// The hit was between v1 and v2 // The hit was between v1 and v2
@@ -1333,11 +1333,11 @@ void KRMesh::convertToIndexed()
for(int i=0; i < vertex_count; i++) { for(int i=0; i < vertex_count; i++) {
KRVector3 vertex_position = getVertexPosition(source_index); Vector3 vertex_position = getVertexPosition(source_index);
Vector2 vertex_uva = getVertexUVA(source_index); Vector2 vertex_uva = getVertexUVA(source_index);
Vector2 vertex_uvb = getVertexUVB(source_index); Vector2 vertex_uvb = getVertexUVB(source_index);
KRVector3 vertex_normal = getVertexNormal(source_index); Vector3 vertex_normal = getVertexNormal(source_index);
KRVector3 vertex_tangent = getVertexTangent(source_index); Vector3 vertex_tangent = getVertexTangent(source_index);
std::vector<int> vertex_bone_indexes; std::vector<int> vertex_bone_indexes;
if(has_vertex_attribute(KRENGINE_ATTRIB_BONEINDEXES)) { if(has_vertex_attribute(KRENGINE_ATTRIB_BONEINDEXES)) {
vertex_bone_indexes.push_back(getBoneIndex(source_index, 0)); vertex_bone_indexes.push_back(getBoneIndex(source_index, 0));

View File

@@ -96,13 +96,13 @@ public:
typedef struct { typedef struct {
model_format_t format; model_format_t format;
std::vector<KRVector3> vertices; std::vector<Vector3> vertices;
std::vector<__uint16_t> vertex_indexes; std::vector<__uint16_t> vertex_indexes;
std::vector<std::pair<int, int> > vertex_index_bases; std::vector<std::pair<int, int> > vertex_index_bases;
std::vector<Vector2> uva; std::vector<Vector2> uva;
std::vector<Vector2> uvb; std::vector<Vector2> uvb;
std::vector<KRVector3> normals; std::vector<Vector3> normals;
std::vector<KRVector3> tangents; std::vector<Vector3> tangents;
std::vector<int> submesh_starts; std::vector<int> submesh_starts;
std::vector<int> submesh_lengths; std::vector<int> submesh_lengths;
std::vector<std::string> material_names; std::vector<std::string> material_names;
@@ -112,7 +112,7 @@ public:
std::vector<std::vector<float> > bone_weights; std::vector<std::vector<float> > bone_weights;
} mesh_info; } mesh_info;
void render(const std::string &object_name, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector<KRBone *> &bones, const KRVector3 &rim_color, float rim_power, float lod_coverage = 0.0f); void render(const std::string &object_name, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, const KRMat4 &matModel, KRTexture *pLightMap, KRNode::RenderPass renderPass, const std::vector<KRBone *> &bones, const Vector3 &rim_color, float rim_power, float lod_coverage = 0.0f);
std::string m_lodBaseName; std::string m_lodBaseName;
@@ -131,8 +131,8 @@ public:
GLfloat getMaxDimension(); GLfloat getMaxDimension();
KRVector3 getMinPoint() const; Vector3 getMinPoint() const;
KRVector3 getMaxPoint() const; Vector3 getMaxPoint() const;
class Submesh { class Submesh {
public: public:
@@ -185,17 +185,17 @@ public:
int getSubmeshCount() const; int getSubmeshCount() const;
int getVertexCount(int submesh) const; int getVertexCount(int submesh) const;
int getTriangleVertexIndex(int submesh, int index) const; int getTriangleVertexIndex(int submesh, int index) const;
KRVector3 getVertexPosition(int index) const; Vector3 getVertexPosition(int index) const;
KRVector3 getVertexNormal(int index) const; Vector3 getVertexNormal(int index) const;
KRVector3 getVertexTangent(int index) const; Vector3 getVertexTangent(int index) const;
Vector2 getVertexUVA(int index) const; Vector2 getVertexUVA(int index) const;
Vector2 getVertexUVB(int index) const; Vector2 getVertexUVB(int index) const;
int getBoneIndex(int index, int weight_index) const; int getBoneIndex(int index, int weight_index) const;
float getBoneWeight(int index, int weight_index) const; float getBoneWeight(int index, int weight_index) const;
void setVertexPosition(int index, const KRVector3 &v); void setVertexPosition(int index, const Vector3 &v);
void setVertexNormal(int index, const KRVector3 &v); void setVertexNormal(int index, const Vector3 &v);
void setVertexTangent(int index, const KRVector3 & v); void setVertexTangent(int index, const Vector3 & v);
void setVertexUVA(int index, const Vector2 &v); void setVertexUVA(int index, const Vector2 &v);
void setVertexUVB(int index, const Vector2 &v); void setVertexUVB(int index, const Vector2 &v);
void setBoneIndex(int index, int weight_index, int bone_index); void setBoneIndex(int index, int weight_index, int bone_index);
@@ -211,9 +211,9 @@ public:
model_format_t getModelFormat() const; model_format_t getModelFormat() const;
bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo) const; bool lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo) const;
bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo) const; bool rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo) const;
bool sphereCast(const KRMat4 &model_to_world, const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo) const; bool sphereCast(const KRMat4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo) const;
static int GetLODCoverage(const std::string &name); static int GetLODCoverage(const std::string &name);
@@ -230,8 +230,8 @@ private:
void getSubmeshes(); void getSubmeshes();
void getMaterials(); void getMaterials();
static bool rayCast(const KRVector3 &start, const KRVector3 &dir, const KRTriangle3 &tri, const KRVector3 &tri_n0, const KRVector3 &tri_n1, const KRVector3 &tri_n2, KRHitInfo &hitinfo); static bool rayCast(const Vector3 &start, const Vector3 &dir, const KRTriangle3 &tri, const Vector3 &tri_n0, const Vector3 &tri_n1, const Vector3 &tri_n2, KRHitInfo &hitinfo);
static bool sphereCast(const KRMat4 &model_to_world, const KRVector3 &v0, const KRVector3 &v1, float radius, const KRTriangle3 &tri, KRHitInfo &hitinfo); static bool sphereCast(const KRMat4 &model_to_world, const Vector3 &v0, const Vector3 &v1, float radius, const KRTriangle3 &tri, KRHitInfo &hitinfo);
int m_lodCoverage; // This LOD level is activated when the bounding box of the model will cover less than this percent of the screen (100 = highest detail model) int m_lodCoverage; // This LOD level is activated when the bounding box of the model will cover less than this percent of the screen (100 = highest detail model)
vector<KRMaterial *> m_materials; vector<KRMaterial *> m_materials;
@@ -240,7 +240,7 @@ private:
bool m_hasTransparency; bool m_hasTransparency;
KRVector3 m_minPoint, m_maxPoint; Vector3 m_minPoint, m_maxPoint;

View File

@@ -38,20 +38,20 @@ KRMeshCube::KRMeshCube(KRContext &context) : KRMesh(context, "__cube")
KRMesh::mesh_info mi; KRMesh::mesh_info mi;
mi.vertices.push_back(KRVector3(1.0, 1.0, 1.0)); mi.vertices.push_back(Vector3(1.0, 1.0, 1.0));
mi.vertices.push_back(KRVector3(-1.0, 1.0, 1.0)); mi.vertices.push_back(Vector3(-1.0, 1.0, 1.0));
mi.vertices.push_back(KRVector3(1.0,-1.0, 1.0)); mi.vertices.push_back(Vector3(1.0,-1.0, 1.0));
mi.vertices.push_back(KRVector3(-1.0,-1.0, 1.0)); mi.vertices.push_back(Vector3(-1.0,-1.0, 1.0));
mi.vertices.push_back(KRVector3(-1.0,-1.0,-1.0)); mi.vertices.push_back(Vector3(-1.0,-1.0,-1.0));
mi.vertices.push_back(KRVector3(-1.0, 1.0, 1.0)); mi.vertices.push_back(Vector3(-1.0, 1.0, 1.0));
mi.vertices.push_back(KRVector3(-1.0, 1.0,-1.0)); mi.vertices.push_back(Vector3(-1.0, 1.0,-1.0));
mi.vertices.push_back(KRVector3(1.0, 1.0, 1.0)); mi.vertices.push_back(Vector3(1.0, 1.0, 1.0));
mi.vertices.push_back(KRVector3(1.0, 1.0,-1.0)); mi.vertices.push_back(Vector3(1.0, 1.0,-1.0));
mi.vertices.push_back(KRVector3(1.0,-1.0, 1.0)); mi.vertices.push_back(Vector3(1.0,-1.0, 1.0));
mi.vertices.push_back(KRVector3(1.0,-1.0,-1.0)); mi.vertices.push_back(Vector3(1.0,-1.0,-1.0));
mi.vertices.push_back(KRVector3(-1.0,-1.0,-1.0)); mi.vertices.push_back(Vector3(-1.0,-1.0,-1.0));
mi.vertices.push_back(KRVector3(1.0, 1.0,-1.0)); mi.vertices.push_back(Vector3(1.0, 1.0,-1.0));
mi.vertices.push_back(KRVector3(-1.0, 1.0,-1.0)); mi.vertices.push_back(Vector3(-1.0, 1.0,-1.0));
mi.submesh_starts.push_back(0); mi.submesh_starts.push_back(0);

View File

@@ -127,7 +127,7 @@ public:
GLfloat x; GLfloat x;
GLfloat y; GLfloat y;
GLfloat z; GLfloat z;
} KRVector3D; } Vector3D;
typedef struct { typedef struct {
GLfloat u; GLfloat u;
@@ -135,12 +135,12 @@ public:
} TexCoord; } TexCoord;
typedef struct { typedef struct {
KRVector3D vertex; Vector3D vertex;
TexCoord uva; TexCoord uva;
} RandomParticleVertexData; } RandomParticleVertexData;
typedef struct { typedef struct {
KRVector3D vertex; Vector3D vertex;
} VolumetricLightingVertexData; } VolumetricLightingVertexData;

View File

@@ -38,10 +38,10 @@ KRMeshQuad::KRMeshQuad(KRContext &context) : KRMesh(context, "__quad")
KRMesh::mesh_info mi; KRMesh::mesh_info mi;
mi.vertices.push_back(KRVector3(-1.0f, -1.0f, 0.0f)); mi.vertices.push_back(Vector3(-1.0f, -1.0f, 0.0f));
mi.vertices.push_back(KRVector3(1.0f, -1.0f, 0.0f)); mi.vertices.push_back(Vector3(1.0f, -1.0f, 0.0f));
mi.vertices.push_back(KRVector3(-1.0f, 1.0f, 0.0f)); mi.vertices.push_back(Vector3(-1.0f, 1.0f, 0.0f));
mi.vertices.push_back(KRVector3(1.0f, 1.0f, 0.0f)); mi.vertices.push_back(Vector3(1.0f, 1.0f, 0.0f));
mi.uva.push_back(Vector2(0.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(1.0f, 0.0f));

View File

@@ -52,25 +52,25 @@ KRMeshSphere::KRMeshSphere(KRContext &context) : KRMesh(context, "__sphere")
~Facet3() { ~Facet3() {
} }
KRVector3 p1; Vector3 p1;
KRVector3 p2; Vector3 p2;
KRVector3 p3; Vector3 p3;
}; };
std::vector<Facet3> f = std::vector<Facet3>(facet_count); std::vector<Facet3> f = std::vector<Facet3>(facet_count);
int i,it; int i,it;
float a; float a;
KRVector3 p[6] = { Vector3 p[6] = {
KRVector3(0,0,1), Vector3(0,0,1),
KRVector3(0,0,-1), Vector3(0,0,-1),
KRVector3(-1,-1,0), Vector3(-1,-1,0),
KRVector3(1,-1,0), Vector3(1,-1,0),
KRVector3(1,1,0), Vector3(1,1,0),
KRVector3(-1,1,0) Vector3(-1,1,0)
}; };
KRVector3 pa,pb,pc; Vector3 pa,pb,pc;
int nt = 0,ntold; int nt = 0,ntold;
/* Create the level 0 object */ /* Create the level 0 object */

View File

@@ -35,7 +35,7 @@
#include "KRContext.h" #include "KRContext.h"
#include "KRMesh.h" #include "KRMesh.h"
KRModel::KRModel(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera, KRVector3 rim_color, float rim_power) : KRNode(scene, instance_name) { KRModel::KRModel(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera, Vector3 rim_color, float rim_power) : KRNode(scene, instance_name) {
m_lightMap = light_map; m_lightMap = light_map;
m_pLightMap = NULL; m_pLightMap = NULL;
m_model_name = model_name; m_model_name = model_name;
@@ -79,12 +79,12 @@ tinyxml2::XMLElement *KRModel::saveXML( tinyxml2::XMLNode *parent)
e->SetAttribute("lod_min_coverage", m_min_lod_coverage); e->SetAttribute("lod_min_coverage", m_min_lod_coverage);
e->SetAttribute("receives_shadow", m_receivesShadow ? "true" : "false"); e->SetAttribute("receives_shadow", m_receivesShadow ? "true" : "false");
e->SetAttribute("faces_camera", m_faces_camera ? "true" : "false"); e->SetAttribute("faces_camera", m_faces_camera ? "true" : "false");
kraken::setXMLAttribute("rim_color", e, m_rim_color, KRVector3::Zero()); kraken::setXMLAttribute("rim_color", e, m_rim_color, Vector3::Zero());
e->SetAttribute("rim_power", m_rim_power); e->SetAttribute("rim_power", m_rim_power);
return e; return e;
} }
void KRModel::setRimColor(const KRVector3 &rim_color) void KRModel::setRimColor(const Vector3 &rim_color)
{ {
m_rim_color = rim_color; m_rim_color = rim_color;
} }
@@ -94,7 +94,7 @@ void KRModel::setRimPower(float rim_power)
m_rim_power = rim_power; m_rim_power = rim_power;
} }
KRVector3 KRModel::getRimColor() Vector3 KRModel::getRimColor()
{ {
return m_rim_color; return m_rim_color;
} }
@@ -198,9 +198,9 @@ void KRModel::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_light
KRMat4 matModel = getModelMatrix(); KRMat4 matModel = getModelMatrix();
if(m_faces_camera) { if(m_faces_camera) {
KRVector3 model_center = KRMat4::Dot(matModel, KRVector3::Zero()); Vector3 model_center = KRMat4::Dot(matModel, Vector3::Zero());
KRVector3 camera_pos = viewport.getCameraPosition(); Vector3 camera_pos = viewport.getCameraPosition();
matModel = KRQuaternion(KRVector3::Forward(), KRVector3::Normalize(camera_pos - model_center)).rotationMatrix() * matModel; matModel = KRQuaternion(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); 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);
@@ -247,7 +247,7 @@ KRAABB KRModel::getBounds() {
if(m_faces_camera) { if(m_faces_camera) {
KRAABB normal_bounds = KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix()); KRAABB normal_bounds = KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
float max_dimension = normal_bounds.longest_radius(); float max_dimension = normal_bounds.longest_radius();
return KRAABB(normal_bounds.center()-KRVector3(max_dimension), normal_bounds.center() + KRVector3(max_dimension)); return KRAABB(normal_bounds.center()-Vector3(max_dimension), normal_bounds.center() + Vector3(max_dimension));
} else { } else {
if(!(m_boundsCachedMat == getModelMatrix())) { if(!(m_boundsCachedMat == getModelMatrix())) {

View File

@@ -47,7 +47,7 @@
class KRModel : public KRNode { class KRModel : public KRNode {
public: public:
KRModel(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera, KRVector3 rim_color = KRVector3::Zero(), float rim_power = 0.0f); KRModel(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera, Vector3 rim_color = Vector3::Zero(), float rim_power = 0.0f);
virtual ~KRModel(); virtual ~KRModel();
virtual std::string getElementName(); virtual std::string getElementName();
@@ -57,9 +57,9 @@ public:
virtual KRAABB getBounds(); virtual KRAABB getBounds();
void setRimColor(const KRVector3 &rim_color); void setRimColor(const Vector3 &rim_color);
void setRimPower(float rim_power); void setRimPower(float rim_power);
KRVector3 getRimColor(); Vector3 getRimColor();
float getRimPower(); float getRimPower();
void setLightMap(const std::string &name); void setLightMap(const std::string &name);
@@ -88,7 +88,7 @@ private:
KRAABB m_boundsCached; KRAABB m_boundsCached;
KRVector3 m_rim_color; Vector3 m_rim_color;
float m_rim_power; float m_rim_power;
}; };

View File

@@ -28,28 +28,28 @@
KRNode::KRNode(KRScene &scene, std::string name) : KRContextObject(scene.getContext()) KRNode::KRNode(KRScene &scene, std::string name) : KRContextObject(scene.getContext())
{ {
m_name = name; m_name = name;
m_localScale = KRVector3::One(); m_localScale = Vector3::One();
m_localRotation = KRVector3::Zero(); m_localRotation = Vector3::Zero();
m_localTranslation = KRVector3::Zero(); m_localTranslation = Vector3::Zero();
m_initialLocalTranslation = m_localTranslation; m_initialLocalTranslation = m_localTranslation;
m_initialLocalScale = m_localScale; m_initialLocalScale = m_localScale;
m_initialLocalRotation = m_localRotation; m_initialLocalRotation = m_localRotation;
m_rotationOffset = KRVector3::Zero(); m_rotationOffset = Vector3::Zero();
m_scalingOffset = KRVector3::Zero(); m_scalingOffset = Vector3::Zero();
m_rotationPivot = KRVector3::Zero(); m_rotationPivot = Vector3::Zero();
m_scalingPivot = KRVector3::Zero(); m_scalingPivot = Vector3::Zero();
m_preRotation = KRVector3::Zero(); m_preRotation = Vector3::Zero();
m_postRotation = KRVector3::Zero(); m_postRotation = Vector3::Zero();
m_initialRotationOffset = KRVector3::Zero(); m_initialRotationOffset = Vector3::Zero();
m_initialScalingOffset = KRVector3::Zero(); m_initialScalingOffset = Vector3::Zero();
m_initialRotationPivot = KRVector3::Zero(); m_initialRotationPivot = Vector3::Zero();
m_initialScalingPivot = KRVector3::Zero(); m_initialScalingPivot = Vector3::Zero();
m_initialPreRotation = KRVector3::Zero(); m_initialPreRotation = Vector3::Zero();
m_initialPostRotation = KRVector3::Zero(); m_initialPostRotation = Vector3::Zero();
m_parentNode = NULL; m_parentNode = NULL;
m_pScene = &scene; m_pScene = &scene;
@@ -123,15 +123,15 @@ tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) {
tinyxml2::XMLElement *e = doc->NewElement(getElementName().c_str()); tinyxml2::XMLElement *e = doc->NewElement(getElementName().c_str());
tinyxml2::XMLNode *n = parent->InsertEndChild(e); tinyxml2::XMLNode *n = parent->InsertEndChild(e);
e->SetAttribute("name", m_name.c_str()); e->SetAttribute("name", m_name.c_str());
kraken::setXMLAttribute("translate", e, m_localTranslation, KRVector3::Zero()); kraken::setXMLAttribute("translate", e, m_localTranslation, Vector3::Zero());
kraken::setXMLAttribute("scale", e, m_localScale, KRVector3::One()); kraken::setXMLAttribute("scale", e, m_localScale, Vector3::One());
kraken::setXMLAttribute("rotate", e, (m_localRotation * (180.0f / M_PI)), KRVector3::Zero()); kraken::setXMLAttribute("rotate", e, (m_localRotation * (180.0f / M_PI)), Vector3::Zero());
kraken::setXMLAttribute("rotate_offset", e, m_rotationOffset, KRVector3::Zero()); kraken::setXMLAttribute("rotate_offset", e, m_rotationOffset, Vector3::Zero());
kraken::setXMLAttribute("scale_offset", e, m_scalingOffset, KRVector3::Zero()); kraken::setXMLAttribute("scale_offset", e, m_scalingOffset, Vector3::Zero());
kraken::setXMLAttribute("rotate_pivot", e, m_rotationPivot, KRVector3::Zero()); kraken::setXMLAttribute("rotate_pivot", e, m_rotationPivot, Vector3::Zero());
kraken::setXMLAttribute("scale_pivot", e, m_scalingPivot, KRVector3::Zero()); kraken::setXMLAttribute("scale_pivot", e, m_scalingPivot, Vector3::Zero());
kraken::setXMLAttribute("pre_rotate", e, (m_preRotation * (180.0f / M_PI)), KRVector3::Zero()); kraken::setXMLAttribute("pre_rotate", e, (m_preRotation * (180.0f / M_PI)), Vector3::Zero());
kraken::setXMLAttribute("post_rotate", e, (m_postRotation * (180.0f / M_PI)), KRVector3::Zero()); kraken::setXMLAttribute("post_rotate", e, (m_postRotation * (180.0f / M_PI)), Vector3::Zero());
for(std::set<KRNode *>::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) { for(std::set<KRNode *>::iterator itr=m_childNodes.begin(); itr != m_childNodes.end(); ++itr) {
KRNode *child = (*itr); KRNode *child = (*itr);
@@ -142,19 +142,19 @@ tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) {
void KRNode::loadXML(tinyxml2::XMLElement *e) { void KRNode::loadXML(tinyxml2::XMLElement *e) {
m_name = e->Attribute("name"); m_name = e->Attribute("name");
m_localTranslation = kraken::getXMLAttribute("translate", e, KRVector3::Zero()); m_localTranslation = kraken::getXMLAttribute("translate", e, Vector3::Zero());
m_localScale = kraken::getXMLAttribute("scale", e, KRVector3::One()); m_localScale = kraken::getXMLAttribute("scale", e, Vector3::One());
m_localRotation = kraken::getXMLAttribute("rotate", e, KRVector3::Zero()); m_localRotation = kraken::getXMLAttribute("rotate", e, Vector3::Zero());
m_localRotation *= M_PI / 180.0f; // Convert degrees to radians m_localRotation *= M_PI / 180.0f; // Convert degrees to radians
m_preRotation = kraken::getXMLAttribute("pre_rotate", e, KRVector3::Zero()); m_preRotation = kraken::getXMLAttribute("pre_rotate", e, Vector3::Zero());
m_preRotation *= M_PI / 180.0f; // Convert degrees to radians m_preRotation *= M_PI / 180.0f; // Convert degrees to radians
m_postRotation = kraken::getXMLAttribute("post_rotate", e, KRVector3::Zero()); m_postRotation = kraken::getXMLAttribute("post_rotate", e, Vector3::Zero());
m_postRotation *= M_PI / 180.0f; // Convert degrees to radians m_postRotation *= M_PI / 180.0f; // Convert degrees to radians
m_rotationOffset = kraken::getXMLAttribute("rotate_offset", e, KRVector3::Zero()); m_rotationOffset = kraken::getXMLAttribute("rotate_offset", e, Vector3::Zero());
m_scalingOffset = kraken::getXMLAttribute("scale_offset", e, KRVector3::Zero()); m_scalingOffset = kraken::getXMLAttribute("scale_offset", e, Vector3::Zero());
m_rotationPivot = kraken::getXMLAttribute("rotate_pivot", e, KRVector3::Zero()); m_rotationPivot = kraken::getXMLAttribute("rotate_pivot", e, Vector3::Zero());
m_scalingPivot = kraken::getXMLAttribute("scale_pivot", e, KRVector3::Zero()); m_scalingPivot = kraken::getXMLAttribute("scale_pivot", e, Vector3::Zero());
m_initialLocalTranslation = m_localTranslation; m_initialLocalTranslation = m_localTranslation;
m_initialLocalScale = m_localScale; m_initialLocalScale = m_localScale;
@@ -191,7 +191,7 @@ void KRNode::loadXML(tinyxml2::XMLElement *e) {
} }
} }
void KRNode::setLocalTranslation(const KRVector3 &v, bool set_original) { void KRNode::setLocalTranslation(const Vector3 &v, bool set_original) {
m_localTranslation = v; m_localTranslation = v;
if(set_original) { if(set_original) {
m_initialLocalTranslation = v; m_initialLocalTranslation = v;
@@ -200,7 +200,7 @@ void KRNode::setLocalTranslation(const KRVector3 &v, bool set_original) {
invalidateModelMatrix(); invalidateModelMatrix();
} }
void KRNode::setWorldTranslation(const KRVector3 &v) void KRNode::setWorldTranslation(const Vector3 &v)
{ {
if(m_parentNode) { if(m_parentNode) {
setLocalTranslation(KRMat4::Dot(m_parentNode->getInverseModelMatrix(), v)); setLocalTranslation(KRMat4::Dot(m_parentNode->getInverseModelMatrix(), v));
@@ -210,21 +210,21 @@ void KRNode::setWorldTranslation(const KRVector3 &v)
} }
void KRNode::setWorldRotation(const KRVector3 &v) void KRNode::setWorldRotation(const Vector3 &v)
{ {
if(m_parentNode) { if(m_parentNode) {
setLocalRotation((KRQuaternion(v) * -m_parentNode->getWorldRotation()).eulerXYZ()); setLocalRotation((KRQuaternion(v) * -m_parentNode->getWorldRotation()).eulerXYZ());
setPreRotation(KRVector3::Zero()); setPreRotation(Vector3::Zero());
setPostRotation(KRVector3::Zero()); setPostRotation(Vector3::Zero());
} else { } else {
setLocalRotation(v); setLocalRotation(v);
setPreRotation(KRVector3::Zero()); setPreRotation(Vector3::Zero());
setPostRotation(KRVector3::Zero()); setPostRotation(Vector3::Zero());
} }
} }
void KRNode::setWorldScale(const KRVector3 &v) void KRNode::setWorldScale(const Vector3 &v)
{ {
if(m_parentNode) { if(m_parentNode) {
setLocalScale(KRMat4::DotNoTranslate(m_parentNode->getInverseModelMatrix(), v)); setLocalScale(KRMat4::DotNoTranslate(m_parentNode->getInverseModelMatrix(), v));
@@ -233,7 +233,7 @@ void KRNode::setWorldScale(const KRVector3 &v)
} }
} }
void KRNode::setLocalScale(const KRVector3 &v, bool set_original) { void KRNode::setLocalScale(const Vector3 &v, bool set_original) {
m_localScale = v; m_localScale = v;
if(set_original) { if(set_original) {
m_initialLocalScale = v; m_initialLocalScale = v;
@@ -242,7 +242,7 @@ void KRNode::setLocalScale(const KRVector3 &v, bool set_original) {
invalidateModelMatrix(); invalidateModelMatrix();
} }
void KRNode::setLocalRotation(const KRVector3 &v, bool set_original) { void KRNode::setLocalRotation(const Vector3 &v, bool set_original) {
m_localRotation = v; m_localRotation = v;
if(set_original) { if(set_original) {
m_initialLocalRotation = v; m_initialLocalRotation = v;
@@ -252,7 +252,7 @@ void KRNode::setLocalRotation(const KRVector3 &v, bool set_original) {
} }
void KRNode::setRotationOffset(const KRVector3 &v, bool set_original) void KRNode::setRotationOffset(const Vector3 &v, bool set_original)
{ {
m_rotationOffset = v; m_rotationOffset = v;
if(set_original) { if(set_original) {
@@ -262,7 +262,7 @@ void KRNode::setRotationOffset(const KRVector3 &v, bool set_original)
invalidateModelMatrix(); invalidateModelMatrix();
} }
void KRNode::setScalingOffset(const KRVector3 &v, bool set_original) void KRNode::setScalingOffset(const Vector3 &v, bool set_original)
{ {
m_scalingOffset = v; m_scalingOffset = v;
if(set_original) { if(set_original) {
@@ -272,7 +272,7 @@ void KRNode::setScalingOffset(const KRVector3 &v, bool set_original)
invalidateModelMatrix(); invalidateModelMatrix();
} }
void KRNode::setRotationPivot(const KRVector3 &v, bool set_original) void KRNode::setRotationPivot(const Vector3 &v, bool set_original)
{ {
m_rotationPivot = v; m_rotationPivot = v;
if(set_original) { if(set_original) {
@@ -281,7 +281,7 @@ void KRNode::setRotationPivot(const KRVector3 &v, bool set_original)
} }
invalidateModelMatrix(); invalidateModelMatrix();
} }
void KRNode::setScalingPivot(const KRVector3 &v, bool set_original) void KRNode::setScalingPivot(const Vector3 &v, bool set_original)
{ {
m_scalingPivot = v; m_scalingPivot = v;
if(set_original) { if(set_original) {
@@ -290,7 +290,7 @@ void KRNode::setScalingPivot(const KRVector3 &v, bool set_original)
} }
invalidateModelMatrix(); invalidateModelMatrix();
} }
void KRNode::setPreRotation(const KRVector3 &v, bool set_original) void KRNode::setPreRotation(const Vector3 &v, bool set_original)
{ {
m_preRotation = v; m_preRotation = v;
if(set_original) { if(set_original) {
@@ -299,7 +299,7 @@ void KRNode::setPreRotation(const KRVector3 &v, bool set_original)
} }
invalidateModelMatrix(); invalidateModelMatrix();
} }
void KRNode::setPostRotation(const KRVector3 &v, bool set_original) void KRNode::setPostRotation(const Vector3 &v, bool set_original)
{ {
m_postRotation = v; m_postRotation = v;
if(set_original) { if(set_original) {
@@ -309,80 +309,80 @@ void KRNode::setPostRotation(const KRVector3 &v, bool set_original)
invalidateModelMatrix(); invalidateModelMatrix();
} }
const KRVector3 &KRNode::getRotationOffset() const Vector3 &KRNode::getRotationOffset()
{ {
return m_rotationOffset; return m_rotationOffset;
} }
const KRVector3 &KRNode::getScalingOffset() const Vector3 &KRNode::getScalingOffset()
{ {
return m_scalingOffset; return m_scalingOffset;
} }
const KRVector3 &KRNode::getRotationPivot() const Vector3 &KRNode::getRotationPivot()
{ {
return m_rotationPivot; return m_rotationPivot;
} }
const KRVector3 &KRNode::getScalingPivot() const Vector3 &KRNode::getScalingPivot()
{ {
return m_scalingPivot; return m_scalingPivot;
} }
const KRVector3 &KRNode::getPreRotation() const Vector3 &KRNode::getPreRotation()
{ {
return m_preRotation; return m_preRotation;
} }
const KRVector3 &KRNode::getPostRotation() const Vector3 &KRNode::getPostRotation()
{ {
return m_postRotation; return m_postRotation;
} }
const KRVector3 &KRNode::getInitialRotationOffset() const Vector3 &KRNode::getInitialRotationOffset()
{ {
return m_initialRotationOffset; return m_initialRotationOffset;
} }
const KRVector3 &KRNode::getInitialScalingOffset() const Vector3 &KRNode::getInitialScalingOffset()
{ {
return m_initialScalingOffset; return m_initialScalingOffset;
} }
const KRVector3 &KRNode::getInitialRotationPivot() const Vector3 &KRNode::getInitialRotationPivot()
{ {
return m_initialRotationPivot; return m_initialRotationPivot;
} }
const KRVector3 &KRNode::getInitialScalingPivot() const Vector3 &KRNode::getInitialScalingPivot()
{ {
return m_initialScalingPivot; return m_initialScalingPivot;
} }
const KRVector3 &KRNode::getInitialPreRotation() const Vector3 &KRNode::getInitialPreRotation()
{ {
return m_initialPreRotation; return m_initialPreRotation;
} }
const KRVector3 &KRNode::getInitialPostRotation() const Vector3 &KRNode::getInitialPostRotation()
{ {
return m_initialPostRotation; return m_initialPostRotation;
} }
const KRVector3 &KRNode::getLocalTranslation() { const Vector3 &KRNode::getLocalTranslation() {
return m_localTranslation; return m_localTranslation;
} }
const KRVector3 &KRNode::getLocalScale() { const Vector3 &KRNode::getLocalScale() {
return m_localScale; return m_localScale;
} }
const KRVector3 &KRNode::getLocalRotation() { const Vector3 &KRNode::getLocalRotation() {
return m_localRotation; return m_localRotation;
} }
const KRVector3 &KRNode::getInitialLocalTranslation() { const Vector3 &KRNode::getInitialLocalTranslation() {
return m_initialLocalTranslation; return m_initialLocalTranslation;
} }
const KRVector3 &KRNode::getInitialLocalScale() { const Vector3 &KRNode::getInitialLocalScale() {
return m_initialLocalScale; return m_initialLocalScale;
} }
const KRVector3 &KRNode::getInitialLocalRotation() { const Vector3 &KRNode::getInitialLocalRotation() {
return m_initialLocalRotation; return m_initialLocalRotation;
} }
const KRVector3 KRNode::getWorldTranslation() { const Vector3 KRNode::getWorldTranslation() {
return localToWorld(KRVector3::Zero()); return localToWorld(Vector3::Zero());
} }
const KRVector3 KRNode::getWorldScale() { const Vector3 KRNode::getWorldScale() {
return KRMat4::DotNoTranslate(getModelMatrix(), m_localScale); return KRMat4::DotNoTranslate(getModelMatrix(), m_localScale);
} }
@@ -427,8 +427,8 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) {
if(e->QueryFloatAttribute("rim_power", &rim_power) != tinyxml2::XML_SUCCESS) { if(e->QueryFloatAttribute("rim_power", &rim_power) != tinyxml2::XML_SUCCESS) {
rim_power = 0.0f; rim_power = 0.0f;
} }
KRVector3 rim_color = KRVector3::Zero(); Vector3 rim_color = Vector3::Zero();
rim_color = kraken::getXMLAttribute("rim_color", e, KRVector3::Zero()); rim_color = kraken::getXMLAttribute("rim_color", e, Vector3::Zero());
new_node = new KRModel(scene, szName, e->Attribute("mesh"), e->Attribute("light_map"), lod_min_coverage, receives_shadow, faces_camera, rim_color, rim_power); new_node = new KRModel(scene, szName, e->Attribute("mesh"), e->Attribute("light_map"), lod_min_coverage, receives_shadow, faces_camera, rim_color, rim_power);
} else if(strcmp(szElementName, "collider") == 0) { } else if(strcmp(szElementName, "collider") == 0) {
new_node = new KRCollider(scene, szName, e->Attribute("mesh"), 65535, 1.0f); new_node = new KRCollider(scene, szName, e->Attribute("mesh"), 65535, 1.0f);
@@ -768,87 +768,87 @@ void KRNode::SetAttribute(node_attribute_type attrib, float v)
//printf("%s - ", m_name.c_str()); //printf("%s - ", m_name.c_str());
switch(attrib) { switch(attrib) {
case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_X: case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_X:
setLocalTranslation(KRVector3(v, m_localTranslation.y, m_localTranslation.z)); setLocalTranslation(Vector3(v, m_localTranslation.y, m_localTranslation.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_Y: case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_Y:
setLocalTranslation(KRVector3(m_localTranslation.x, v, m_localTranslation.z)); setLocalTranslation(Vector3(m_localTranslation.x, v, m_localTranslation.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_Z: case KRENGINE_NODE_ATTRIBUTE_TRANSLATE_Z:
setLocalTranslation(KRVector3(m_localTranslation.x, m_localTranslation.y, v)); setLocalTranslation(Vector3(m_localTranslation.x, m_localTranslation.y, v));
break; break;
case KRENGINE_NODE_ATTRIBUTE_SCALE_X: case KRENGINE_NODE_ATTRIBUTE_SCALE_X:
setLocalScale(KRVector3(v, m_localScale.y, m_localScale.z)); setLocalScale(Vector3(v, m_localScale.y, m_localScale.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_SCALE_Y: case KRENGINE_NODE_ATTRIBUTE_SCALE_Y:
setLocalScale(KRVector3(m_localScale.x, v, m_localScale.z)); setLocalScale(Vector3(m_localScale.x, v, m_localScale.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_SCALE_Z: case KRENGINE_NODE_ATTRIBUTE_SCALE_Z:
setLocalScale(KRVector3(m_localScale.x, m_localScale.y, v)); setLocalScale(Vector3(m_localScale.x, m_localScale.y, v));
break; break;
case KRENGINE_NODE_ATTRIBUTE_ROTATE_X: case KRENGINE_NODE_ATTRIBUTE_ROTATE_X:
setLocalRotation(KRVector3(v * DEGREES_TO_RAD, m_localRotation.y, m_localRotation.z)); setLocalRotation(Vector3(v * DEGREES_TO_RAD, m_localRotation.y, m_localRotation.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_ROTATE_Y: case KRENGINE_NODE_ATTRIBUTE_ROTATE_Y:
setLocalRotation(KRVector3(m_localRotation.x, v * DEGREES_TO_RAD, m_localRotation.z)); setLocalRotation(Vector3(m_localRotation.x, v * DEGREES_TO_RAD, m_localRotation.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_ROTATE_Z: case KRENGINE_NODE_ATTRIBUTE_ROTATE_Z:
setLocalRotation(KRVector3(m_localRotation.x, m_localRotation.y, v * DEGREES_TO_RAD)); setLocalRotation(Vector3(m_localRotation.x, m_localRotation.y, v * DEGREES_TO_RAD));
break; break;
case KRENGINE_NODE_ATTRIBUTE_PRE_ROTATION_X: case KRENGINE_NODE_ATTRIBUTE_PRE_ROTATION_X:
setPreRotation(KRVector3(v * DEGREES_TO_RAD, m_preRotation.y, m_preRotation.z)); setPreRotation(Vector3(v * DEGREES_TO_RAD, m_preRotation.y, m_preRotation.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_PRE_ROTATION_Y: case KRENGINE_NODE_ATTRIBUTE_PRE_ROTATION_Y:
setPreRotation(KRVector3(m_preRotation.x, v * DEGREES_TO_RAD, m_preRotation.z)); setPreRotation(Vector3(m_preRotation.x, v * DEGREES_TO_RAD, m_preRotation.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_PRE_ROTATION_Z: case KRENGINE_NODE_ATTRIBUTE_PRE_ROTATION_Z:
setPreRotation(KRVector3(m_preRotation.x, m_preRotation.y, v * DEGREES_TO_RAD)); setPreRotation(Vector3(m_preRotation.x, m_preRotation.y, v * DEGREES_TO_RAD));
break; break;
case KRENGINE_NODE_ATTRIBUTE_POST_ROTATION_X: case KRENGINE_NODE_ATTRIBUTE_POST_ROTATION_X:
setPostRotation(KRVector3(v * DEGREES_TO_RAD, m_postRotation.y, m_postRotation.z)); setPostRotation(Vector3(v * DEGREES_TO_RAD, m_postRotation.y, m_postRotation.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_POST_ROTATION_Y: case KRENGINE_NODE_ATTRIBUTE_POST_ROTATION_Y:
setPostRotation(KRVector3(m_postRotation.x, v * DEGREES_TO_RAD, m_postRotation.z)); setPostRotation(Vector3(m_postRotation.x, v * DEGREES_TO_RAD, m_postRotation.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_POST_ROTATION_Z: case KRENGINE_NODE_ATTRIBUTE_POST_ROTATION_Z:
setPostRotation(KRVector3(m_postRotation.x, m_postRotation.y, v * DEGREES_TO_RAD)); setPostRotation(Vector3(m_postRotation.x, m_postRotation.y, v * DEGREES_TO_RAD));
break; break;
case KRENGINE_NODE_ATTRIBUTE_ROTATION_PIVOT_X: case KRENGINE_NODE_ATTRIBUTE_ROTATION_PIVOT_X:
setRotationPivot(KRVector3(v, m_rotationPivot.y, m_rotationPivot.z)); setRotationPivot(Vector3(v, m_rotationPivot.y, m_rotationPivot.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_ROTATION_PIVOT_Y: case KRENGINE_NODE_ATTRIBUTE_ROTATION_PIVOT_Y:
setRotationPivot(KRVector3(m_rotationPivot.x, v, m_rotationPivot.z)); setRotationPivot(Vector3(m_rotationPivot.x, v, m_rotationPivot.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_ROTATION_PIVOT_Z: case KRENGINE_NODE_ATTRIBUTE_ROTATION_PIVOT_Z:
setRotationPivot(KRVector3(m_rotationPivot.x, m_rotationPivot.y, v)); setRotationPivot(Vector3(m_rotationPivot.x, m_rotationPivot.y, v));
break; break;
case KRENGINE_NODE_ATTRIBUTE_SCALE_PIVOT_X: case KRENGINE_NODE_ATTRIBUTE_SCALE_PIVOT_X:
setScalingPivot(KRVector3(v, m_scalingPivot.y, m_scalingPivot.z)); setScalingPivot(Vector3(v, m_scalingPivot.y, m_scalingPivot.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_SCALE_PIVOT_Y: case KRENGINE_NODE_ATTRIBUTE_SCALE_PIVOT_Y:
setScalingPivot(KRVector3(m_scalingPivot.x, v, m_scalingPivot.z)); setScalingPivot(Vector3(m_scalingPivot.x, v, m_scalingPivot.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_SCALE_PIVOT_Z: case KRENGINE_NODE_ATTRIBUTE_SCALE_PIVOT_Z:
setScalingPivot(KRVector3(m_scalingPivot.x, m_scalingPivot.y, v)); setScalingPivot(Vector3(m_scalingPivot.x, m_scalingPivot.y, v));
break; break;
case KRENGINE_NODE_ATTRIBUTE_ROTATE_OFFSET_X: case KRENGINE_NODE_ATTRIBUTE_ROTATE_OFFSET_X:
setRotationOffset(KRVector3(v, m_rotationOffset.y, m_rotationOffset.z)); setRotationOffset(Vector3(v, m_rotationOffset.y, m_rotationOffset.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_ROTATE_OFFSET_Y: case KRENGINE_NODE_ATTRIBUTE_ROTATE_OFFSET_Y:
setRotationOffset(KRVector3(m_rotationOffset.x, v, m_rotationOffset.z)); setRotationOffset(Vector3(m_rotationOffset.x, v, m_rotationOffset.z));
break; break;
case KRENGINE_NODE_ATTRIBUTE_ROTATE_OFFSET_Z: case KRENGINE_NODE_ATTRIBUTE_ROTATE_OFFSET_Z:
setRotationOffset(KRVector3(m_rotationOffset.x, m_rotationOffset.y, v)); setRotationOffset(Vector3(m_rotationOffset.x, m_rotationOffset.y, v));
break; break;
case KRENGINE_NODE_SCALE_OFFSET_X: case KRENGINE_NODE_SCALE_OFFSET_X:
setScalingOffset(KRVector3(v, m_scalingOffset.y, m_scalingOffset.z)); setScalingOffset(Vector3(v, m_scalingOffset.y, m_scalingOffset.z));
break; break;
case KRENGINE_NODE_SCALE_OFFSET_Y: case KRENGINE_NODE_SCALE_OFFSET_Y:
setScalingOffset(KRVector3(m_scalingOffset.x, v, m_scalingOffset.z)); setScalingOffset(Vector3(m_scalingOffset.x, v, m_scalingOffset.z));
break; break;
case KRENGINE_NODE_SCALE_OFFSET_Z: case KRENGINE_NODE_SCALE_OFFSET_Z:
setScalingOffset(KRVector3(m_scalingOffset.x, m_scalingOffset.y, v)); setScalingOffset(Vector3(m_scalingOffset.x, m_scalingOffset.y, v));
break; break;
} }
} }
@@ -917,12 +917,12 @@ KRNode::LodVisibility KRNode::getLODVisibility()
return m_lod_visible; return m_lod_visible;
} }
const KRVector3 KRNode::localToWorld(const KRVector3 &local_point) const Vector3 KRNode::localToWorld(const Vector3 &local_point)
{ {
return KRMat4::Dot(getModelMatrix(), local_point); return KRMat4::Dot(getModelMatrix(), local_point);
} }
const KRVector3 KRNode::worldToLocal(const KRVector3 &world_point) const Vector3 KRNode::worldToLocal(const Vector3 &world_point)
{ {
return KRMat4::Dot(getInverseModelMatrix(), world_point); return KRMat4::Dot(getInverseModelMatrix(), world_point);
} }

View File

@@ -74,54 +74,54 @@ public:
const std::set<KRNode *> &getChildren(); const std::set<KRNode *> &getChildren();
KRNode *getParent(); KRNode *getParent();
void setLocalTranslation(const KRVector3 &v, bool set_original = false); void setLocalTranslation(const Vector3 &v, bool set_original = false);
void setLocalScale(const KRVector3 &v, bool set_original = false); void setLocalScale(const Vector3 &v, bool set_original = false);
void setLocalRotation(const KRVector3 &v, bool set_original = false); void setLocalRotation(const Vector3 &v, bool set_original = false);
void setRotationOffset(const KRVector3 &v, bool set_original = false); void setRotationOffset(const Vector3 &v, bool set_original = false);
void setScalingOffset(const KRVector3 &v, bool set_original = false); void setScalingOffset(const Vector3 &v, bool set_original = false);
void setRotationPivot(const KRVector3 &v, bool set_original = false); void setRotationPivot(const Vector3 &v, bool set_original = false);
void setScalingPivot(const KRVector3 &v, bool set_original = false); void setScalingPivot(const Vector3 &v, bool set_original = false);
void setPreRotation(const KRVector3 &v, bool set_original = false); void setPreRotation(const Vector3 &v, bool set_original = false);
void setPostRotation(const KRVector3 &v, bool set_original = false); void setPostRotation(const Vector3 &v, bool set_original = false);
const KRVector3 &getRotationOffset(); const Vector3 &getRotationOffset();
const KRVector3 &getScalingOffset(); const Vector3 &getScalingOffset();
const KRVector3 &getRotationPivot(); const Vector3 &getRotationPivot();
const KRVector3 &getScalingPivot(); const Vector3 &getScalingPivot();
const KRVector3 &getPreRotation(); const Vector3 &getPreRotation();
const KRVector3 &getPostRotation(); const Vector3 &getPostRotation();
const KRVector3 &getInitialRotationOffset(); const Vector3 &getInitialRotationOffset();
const KRVector3 &getInitialScalingOffset(); const Vector3 &getInitialScalingOffset();
const KRVector3 &getInitialRotationPivot(); const Vector3 &getInitialRotationPivot();
const KRVector3 &getInitialScalingPivot(); const Vector3 &getInitialScalingPivot();
const KRVector3 &getInitialPreRotation(); const Vector3 &getInitialPreRotation();
const KRVector3 &getInitialPostRotation(); const Vector3 &getInitialPostRotation();
const KRVector3 &getLocalTranslation(); const Vector3 &getLocalTranslation();
const KRVector3 &getLocalScale(); const Vector3 &getLocalScale();
const KRVector3 &getLocalRotation(); const Vector3 &getLocalRotation();
const KRVector3 &getInitialLocalTranslation(); const Vector3 &getInitialLocalTranslation();
const KRVector3 &getInitialLocalScale(); const Vector3 &getInitialLocalScale();
const KRVector3 &getInitialLocalRotation(); const Vector3 &getInitialLocalRotation();
const KRVector3 getWorldTranslation(); const Vector3 getWorldTranslation();
const KRVector3 getWorldScale(); const Vector3 getWorldScale();
const KRQuaternion getWorldRotation(); const KRQuaternion getWorldRotation();
const KRQuaternion getBindPoseWorldRotation(); const KRQuaternion getBindPoseWorldRotation();
const KRQuaternion getActivePoseWorldRotation(); const KRQuaternion getActivePoseWorldRotation();
const KRVector3 localToWorld(const KRVector3 &local_point); const Vector3 localToWorld(const Vector3 &local_point);
const KRVector3 worldToLocal(const KRVector3 &world_point); const Vector3 worldToLocal(const Vector3 &world_point);
void setWorldTranslation(const KRVector3 &v); void setWorldTranslation(const Vector3 &v);
void setWorldScale(const KRVector3 &v); void setWorldScale(const Vector3 &v);
void setWorldRotation(const KRVector3 &v); void setWorldRotation(const Vector3 &v);
virtual KRAABB getBounds(); virtual KRAABB getBounds();
void invalidateBounds() const; void invalidateBounds() const;
@@ -186,27 +186,27 @@ public:
virtual void setLODVisibility(LodVisibility lod_visibility); virtual void setLODVisibility(LodVisibility lod_visibility);
protected: protected:
KRVector3 m_localTranslation; Vector3 m_localTranslation;
KRVector3 m_localScale; Vector3 m_localScale;
KRVector3 m_localRotation; Vector3 m_localRotation;
KRVector3 m_rotationOffset; Vector3 m_rotationOffset;
KRVector3 m_scalingOffset; Vector3 m_scalingOffset;
KRVector3 m_rotationPivot; Vector3 m_rotationPivot;
KRVector3 m_scalingPivot; Vector3 m_scalingPivot;
KRVector3 m_preRotation; Vector3 m_preRotation;
KRVector3 m_postRotation; Vector3 m_postRotation;
KRVector3 m_initialLocalTranslation; Vector3 m_initialLocalTranslation;
KRVector3 m_initialLocalScale; Vector3 m_initialLocalScale;
KRVector3 m_initialLocalRotation; Vector3 m_initialLocalRotation;
KRVector3 m_initialRotationOffset; Vector3 m_initialRotationOffset;
KRVector3 m_initialScalingOffset; Vector3 m_initialScalingOffset;
KRVector3 m_initialRotationPivot; Vector3 m_initialRotationPivot;
KRVector3 m_initialScalingPivot; Vector3 m_initialScalingPivot;
KRVector3 m_initialPreRotation; Vector3 m_initialPreRotation;
KRVector3 m_initialPostRotation; Vector3 m_initialPostRotation;
LodVisibility m_lod_visible; LodVisibility m_lod_visible;

View File

@@ -41,7 +41,7 @@ void KROctree::add(KRNode *pNode)
bool bInsideRoot = false; bool bInsideRoot = false;
while(!bInsideRoot) { while(!bInsideRoot) {
KRAABB rootBounds = m_pRootNode->getBounds(); KRAABB rootBounds = m_pRootNode->getBounds();
KRVector3 rootSize = rootBounds.size(); Vector3 rootSize = rootBounds.size();
if(nodeBounds.min.x < rootBounds.min.x || nodeBounds.min.y < rootBounds.min.y || nodeBounds.min.z < rootBounds.min.z) { if(nodeBounds.min.x < rootBounds.min.x || nodeBounds.min.y < rootBounds.min.y || nodeBounds.min.z < rootBounds.min.z) {
m_pRootNode = new KROctreeNode(NULL, KRAABB(rootBounds.min - rootSize, rootBounds.max), 7, m_pRootNode); m_pRootNode = new KROctreeNode(NULL, KRAABB(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) { } else if(nodeBounds.max.x > rootBounds.max.x || nodeBounds.max.y > rootBounds.max.y || nodeBounds.max.z > rootBounds.max.z) {
@@ -97,7 +97,7 @@ std::set<KRNode *> &KROctree::getOuterSceneNodes()
} }
bool KROctree::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) bool KROctree::lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask)
{ {
bool hit_found = false; bool hit_found = false;
std::vector<KRCollider *> outer_colliders; std::vector<KRCollider *> outer_colliders;
@@ -118,7 +118,7 @@ bool KROctree::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hit
return hit_found; return hit_found;
} }
bool KROctree::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) bool KROctree::rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask)
{ {
bool hit_found = false; bool hit_found = false;
for(std::set<KRNode *>::iterator outer_nodes_itr=m_outerSceneNodes.begin(); outer_nodes_itr != m_outerSceneNodes.end(); outer_nodes_itr++) { for(std::set<KRNode *>::iterator outer_nodes_itr=m_outerSceneNodes.begin(); outer_nodes_itr != m_outerSceneNodes.end(); outer_nodes_itr++) {
@@ -133,7 +133,7 @@ bool KROctree::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hit
return hit_found; return hit_found;
} }
bool KROctree::sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask) bool KROctree::sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask)
{ {
bool hit_found = false; bool hit_found = false;
std::vector<KRCollider *> outer_colliders; std::vector<KRCollider *> outer_colliders;

View File

@@ -27,9 +27,9 @@ public:
KROctreeNode *getRootNode(); KROctreeNode *getRootNode();
std::set<KRNode *> &getOuterSceneNodes(); std::set<KRNode *> &getOuterSceneNodes();
bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); bool lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask);
bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask); bool rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask);
bool sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask); bool sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask);
private: private:
KROctreeNode *m_pRootNode; KROctreeNode *m_pRootNode;

View File

@@ -97,14 +97,14 @@ void KROctreeNode::add(KRNode *pNode)
KRAABB KROctreeNode::getChildBounds(int iChild) KRAABB KROctreeNode::getChildBounds(int iChild)
{ {
KRVector3 center = m_bounds.center(); Vector3 center = m_bounds.center();
return KRAABB( return KRAABB(
KRVector3( Vector3(
(iChild & 1) == 0 ? m_bounds.min.x : center.x, (iChild & 1) == 0 ? m_bounds.min.x : center.x,
(iChild & 2) == 0 ? m_bounds.min.y : center.y, (iChild & 2) == 0 ? m_bounds.min.y : center.y,
(iChild & 4) == 0 ? m_bounds.min.z : center.z), (iChild & 4) == 0 ? m_bounds.min.z : center.z),
KRVector3( Vector3(
(iChild & 1) == 0 ? center.x : m_bounds.max.x, (iChild & 1) == 0 ? center.x : m_bounds.max.x,
(iChild & 2) == 0 ? center.y : m_bounds.max.y, (iChild & 2) == 0 ? center.y : m_bounds.max.y,
(iChild & 4) == 0 ? center.z : m_bounds.max.z) (iChild & 4) == 0 ? center.z : m_bounds.max.z)
@@ -196,7 +196,7 @@ std::set<KRNode *> &KROctreeNode::getSceneNodes()
} }
bool KROctreeNode::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) bool KROctreeNode::lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask)
{ {
bool hit_found = false; bool hit_found = false;
if(hitinfo.didHit() && v1 != hitinfo.getPosition()) { if(hitinfo.didHit() && v1 != hitinfo.getPosition()) {
@@ -224,7 +224,7 @@ bool KROctreeNode::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo
return hit_found; return hit_found;
} }
bool KROctreeNode::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) bool KROctreeNode::rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask)
{ {
bool hit_found = false; bool hit_found = false;
if(hitinfo.didHit()) { if(hitinfo.didHit()) {
@@ -252,7 +252,7 @@ bool KROctreeNode::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo
return hit_found; return hit_found;
} }
bool KROctreeNode::sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask) bool KROctreeNode::sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask)
{ {
bool hit_found = false; bool hit_found = false;
/* /*
@@ -264,7 +264,7 @@ bool KROctreeNode::sphereCast(const KRVector3 &v0, const KRVector3 &v1, float ra
} else { } else {
*/ */
KRAABB swept_bounds = KRAABB(KRVector3(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius), KRVector3(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius)); KRAABB swept_bounds = KRAABB(Vector3(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius), Vector3(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius));
// FINDME, TODO - Investigate AABB - swept sphere intersections or OBB - AABB intersections: "if(getBounds().intersectsSweptSphere(v0, v1, radius)) {" // FINDME, TODO - Investigate AABB - swept sphere intersections or OBB - AABB intersections: "if(getBounds().intersectsSweptSphere(v0, v1, radius)) {"
if(getBounds().intersects(swept_bounds)) { if(getBounds().intersects(swept_bounds)) {

View File

@@ -47,9 +47,9 @@ public:
bool m_occlusionTested; bool m_occlusionTested;
bool m_activeQuery; bool m_activeQuery;
bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); bool lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask);
bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask); bool rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask);
bool sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask); bool sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask);
private: private:

View File

@@ -41,7 +41,7 @@ tinyxml2::XMLElement *KRParticleSystemNewtonian::saveXML( tinyxml2::XMLNode *par
KRAABB KRParticleSystemNewtonian::getBounds() KRAABB KRParticleSystemNewtonian::getBounds()
{ {
return KRAABB(-KRVector3::One(), KRVector3::One(), getModelMatrix()); return KRAABB(-Vector3::One(), Vector3::One(), getModelMatrix());
} }
void KRParticleSystemNewtonian::physicsUpdate(float deltaTime) void KRParticleSystemNewtonian::physicsUpdate(float deltaTime)
@@ -76,8 +76,8 @@ void KRParticleSystemNewtonian::render(KRCamera *pCamera, std::vector<KRPointLig
KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("dust_particle", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("dust_particle", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
KRVector3 rim_color; KRVector4 fade_color; Vector3 rim_color; KRVector4 fade_color;
if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader(*pCamera, pParticleShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, 1.0f); pParticleShader->setUniform(KRShader::KRENGINE_UNIFORM_FLARE_SIZE, 1.0f);
KRDataBlock index_data; KRDataBlock index_data;

View File

@@ -36,7 +36,7 @@ KRAABB KRPointLight::getBounds() {
if(influence_radius < m_flareOcclusionSize) { if(influence_radius < m_flareOcclusionSize) {
influence_radius = m_flareOcclusionSize; influence_radius = m_flareOcclusionSize;
} }
return KRAABB(KRVector3(-influence_radius), KRVector3(influence_radius), getModelMatrix()); return KRAABB(Vector3(-influence_radius), Vector3(influence_radius), getModelMatrix());
} }
void KRPointLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass) 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)
@@ -53,7 +53,7 @@ void KRPointLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_
std::vector<KRPointLight *> this_light; std::vector<KRPointLight *> this_light;
this_light.push_back(this); this_light.push_back(this);
KRVector3 light_position = getLocalTranslation(); Vector3 light_position = getLocalTranslation();
float influence_radius = m_decayStart - sqrt(m_intensity * 0.01f) / sqrt(KRLIGHT_MIN_INFLUENCE); float influence_radius = m_decayStart - sqrt(m_intensity * 0.01f) / sqrt(KRLIGHT_MIN_INFLUENCE);
@@ -63,12 +63,12 @@ void KRPointLight::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_
if(viewport.visible(getBounds())) { // Cull out any lights not within the view frustrum if(viewport.visible(getBounds())) { // Cull out any lights not within the view frustrum
KRVector3 view_light_position = KRMat4::Dot(viewport.getViewMatrix(), light_position); Vector3 view_light_position = KRMat4::Dot(viewport.getViewMatrix(), light_position);
bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->settings.getPerspectiveNearZ()) * (influence_radius + pCamera->settings.getPerspectiveNearZ()); bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->settings.getPerspectiveNearZ()) * (influence_radius + pCamera->settings.getPerspectiveNearZ());
KRShader *pShader = getContext().getShaderManager()->getShader(bVisualize ? "visualize_overlay" : (bInsideLight ? "light_point_inside" : "light_point"), pCamera, this_light, std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pShader = getContext().getShaderManager()->getShader(bVisualize ? "visualize_overlay" : (bInsideLight ? "light_point_inside" : "light_point"), pCamera, this_light, std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, this_light, std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, this_light, std::vector<KRDirectionalLight *>(), std::vector<KRSpotLight *>(), 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color); pShader->setUniform(KRShader::KRENGINE_UNIFORM_LIGHT_COLOR, m_color);
@@ -146,25 +146,25 @@ void KRPointLight::generateMesh() {
~Facet3() { ~Facet3() {
} }
KRVector3 p1; Vector3 p1;
KRVector3 p2; Vector3 p2;
KRVector3 p3; Vector3 p3;
}; };
std::vector<Facet3> f = std::vector<Facet3>(facet_count); std::vector<Facet3> f = std::vector<Facet3>(facet_count);
int i,it; int i,it;
float a; float a;
KRVector3 p[6] = { Vector3 p[6] = {
KRVector3(0,0,1), Vector3(0,0,1),
KRVector3(0,0,-1), Vector3(0,0,-1),
KRVector3(-1,-1,0), Vector3(-1,-1,0),
KRVector3(1,-1,0), Vector3(1,-1,0),
KRVector3(1,1,0), Vector3(1,1,0),
KRVector3(-1,1,0) Vector3(-1,1,0)
}; };
KRVector3 pa,pb,pc; Vector3 pa,pb,pc;
int nt = 0,ntold; int nt = 0,ntold;
/* Create the level 0 object */ /* Create the level 0 object */

View File

@@ -64,17 +64,17 @@ KRQuaternion& KRQuaternion::operator =( const KRQuaternion& p ) {
return *this; return *this;
} }
KRQuaternion::KRQuaternion(const KRVector3 &euler) { KRQuaternion::KRQuaternion(const Vector3 &euler) {
setEulerZYX(euler); setEulerZYX(euler);
} }
KRQuaternion::KRQuaternion(const KRVector3 &from_vector, const KRVector3 &to_vector) { KRQuaternion::KRQuaternion(const Vector3 &from_vector, const Vector3 &to_vector) {
KRVector3 a = KRVector3::Cross(from_vector, to_vector); Vector3 a = Vector3::Cross(from_vector, to_vector);
m_val[0] = a[0]; m_val[0] = a[0];
m_val[1] = a[1]; m_val[1] = a[1];
m_val[2] = a[2]; m_val[2] = a[2];
m_val[3] = sqrt(from_vector.sqrMagnitude() * to_vector.sqrMagnitude()) + KRVector3::Dot(from_vector, to_vector); m_val[3] = sqrt(from_vector.sqrMagnitude() * to_vector.sqrMagnitude()) + Vector3::Dot(from_vector, to_vector);
normalize(); normalize();
} }
@@ -82,14 +82,14 @@ KRQuaternion::~KRQuaternion() {
} }
void KRQuaternion::setEulerXYZ(const KRVector3 &euler) void KRQuaternion::setEulerXYZ(const Vector3 &euler)
{ {
*this = KRQuaternion::FromAngleAxis(KRVector3(1.0f, 0.0f, 0.0f), euler.x) *this = KRQuaternion::FromAngleAxis(Vector3(1.0f, 0.0f, 0.0f), euler.x)
* KRQuaternion::FromAngleAxis(KRVector3(0.0f, 1.0f, 0.0f), euler.y) * KRQuaternion::FromAngleAxis(Vector3(0.0f, 1.0f, 0.0f), euler.y)
* KRQuaternion::FromAngleAxis(KRVector3(0.0f, 0.0f, 1.0f), euler.z); * KRQuaternion::FromAngleAxis(Vector3(0.0f, 0.0f, 1.0f), euler.z);
} }
void KRQuaternion::setEulerZYX(const KRVector3 &euler) { void KRQuaternion::setEulerZYX(const Vector3 &euler) {
// ZYX Order! // ZYX Order!
float c1 = cos(euler[0] * 0.5f); float c1 = cos(euler[0] * 0.5f);
float c2 = cos(euler[1] * 0.5f); float c2 = cos(euler[1] * 0.5f);
@@ -112,22 +112,22 @@ float &KRQuaternion::operator [](unsigned i) {
return m_val[i]; return m_val[i];
} }
KRVector3 KRQuaternion::eulerXYZ() const { Vector3 KRQuaternion::eulerXYZ() const {
double a2 = 2 * (m_val[0] * m_val[2] - m_val[1] * m_val[3]); double a2 = 2 * (m_val[0] * m_val[2] - m_val[1] * m_val[3]);
if(a2 <= -0.99999) { if(a2 <= -0.99999) {
return KRVector3( return Vector3(
2.0 * atan2(m_val[1], m_val[0]), 2.0 * atan2(m_val[1], m_val[0]),
-PI * 0.5f, -PI * 0.5f,
0 0
); );
} else if(a2 >= 0.99999) { } else if(a2 >= 0.99999) {
return KRVector3( return Vector3(
2.0 * atan2(m_val[1], m_val[0]), 2.0 * atan2(m_val[1], m_val[0]),
PI * 0.5f, PI * 0.5f,
0 0
); );
} else { } else {
return KRVector3( return Vector3(
atan2(2 * (m_val[0] * m_val[1] + m_val[2] * m_val[3]), (1 - 2 * (m_val[1] * m_val[1] + m_val[2] * m_val[2]))), atan2(2 * (m_val[0] * m_val[1] + m_val[2] * m_val[3]), (1 - 2 * (m_val[1] * m_val[1] + m_val[2] * m_val[2]))),
asin(a2), asin(a2),
atan2(2 * (m_val[0] * m_val[3] + m_val[1] * m_val[2]), (1 - 2 * (m_val[2] * m_val[2] + m_val[3] * m_val[3]))) atan2(2 * (m_val[0] * m_val[3] + m_val[1] * m_val[2]), (1 - 2 * (m_val[2] * m_val[2] + m_val[3] * m_val[3])))
@@ -283,7 +283,7 @@ KRMat4 KRQuaternion::rotationMatrix() const {
KRMat4 matRotate; KRMat4 matRotate;
/* /*
KRVector3 euler = eulerXYZ(); Vector3 euler = eulerXYZ();
matRotate.rotate(euler.x, X_AXIS); matRotate.rotate(euler.x, X_AXIS);
matRotate.rotate(euler.y, Y_AXIS); matRotate.rotate(euler.y, Y_AXIS);
@@ -309,7 +309,7 @@ KRMat4 KRQuaternion::rotationMatrix() const {
} }
KRQuaternion KRQuaternion::FromAngleAxis(const KRVector3 &axis, float angle) KRQuaternion KRQuaternion::FromAngleAxis(const Vector3 &axis, float angle)
{ {
float ha = angle * 0.5f; float ha = angle * 0.5f;
float sha = sin(ha); float sha = sin(ha);

View File

@@ -33,8 +33,8 @@ KRRenderSettings::KRRenderSettings()
bEnableDeferredLighting = false; bEnableDeferredLighting = false;
max_anisotropy = 4.0f; max_anisotropy = 4.0f;
ambient_intensity = KRVector3::Zero(); ambient_intensity = Vector3::Zero();
light_intensity = KRVector3::One(); light_intensity = Vector3::One();
perspective_fov = 45.0 * D2R; perspective_fov = 45.0 * D2R;
perspective_nearz = 0.3f; // was 0.05f perspective_nearz = 0.3f; // was 0.05f
@@ -67,7 +67,7 @@ KRRenderSettings::KRRenderSettings()
fog_near = 50.0f; fog_near = 50.0f;
fog_far = 500.0f; fog_far = 500.0f;
fog_density = 0.0005f; fog_density = 0.0005f;
fog_color = KRVector3(0.45, 0.45, 0.5); fog_color = Vector3(0.45, 0.45, 0.5);
fog_type = 0; fog_type = 0;
dust_particle_intensity = 0.25f; dust_particle_intensity = 0.25f;

View File

@@ -45,8 +45,8 @@ public:
bool bEnableDiffuse; bool bEnableDiffuse;
bool bEnableSpecular; bool bEnableSpecular;
bool bEnableDeferredLighting; bool bEnableDeferredLighting;
KRVector3 light_intensity; Vector3 light_intensity;
KRVector3 ambient_intensity; Vector3 ambient_intensity;
float perspective_fov; float perspective_fov;
int dof_quality; int dof_quality;
@@ -76,7 +76,7 @@ public:
float fog_near; float fog_near;
float fog_far; float fog_far;
float fog_density; float fog_density;
KRVector3 fog_color; Vector3 fog_color;
int fog_type; // 0 = no fog, 1 = linear, 2 = exponential, 3 = exponential squared int fog_type; // 0 = no fog, 1 = linear, 2 = exponential, 3 = exponential squared
float dust_particle_intensity; float dust_particle_intensity;

View File

@@ -590,7 +590,7 @@ void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pG
// Transform = T * Roff * Rp * Rpre * R * Rpost * inverse(Rp) * Soff * Sp * S * inverse(Sp) // Transform = T * Roff * Rp * Rpre * R * Rpost * inverse(Rp) * Soff * Sp * S * inverse(Sp)
int node_has_n_points = 0; // this will be 3 if the node_frame_key_position is complete after the import animated properties loop int node_has_n_points = 0; // this will be 3 if the node_frame_key_position is complete after the import animated properties loop
KRVector3 node_key_frame_position = KRVector3(0.0, 0.0, 0.0); Vector3 node_key_frame_position = Vector3(0.0, 0.0, 0.0);
// ADDED 3, 2013 by Peter to store the key frame (start location) of an animation // ADDED 3, 2013 by Peter to store the key frame (start location) of an animation
// the x, y, z translation position of the animation will be extracted from the curves // the x, y, z translation position of the animation will be extracted from the curves
// as they are added to the animation layer in the loop below .. // as they are added to the animation layer in the loop below ..
@@ -917,22 +917,22 @@ void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pG
// do we store it as node_local or store it as the world translation? or somewhere else ?? // do we store it as node_local or store it as the world translation? or somewhere else ??
// //
KRVector3 node_translation = KRVector3(local_translation[0], local_translation[1], local_translation[2]); // T * Roff * Rp Vector3 node_translation = Vector3(local_translation[0], local_translation[1], local_translation[2]); // T * Roff * Rp
KRVector3 node_rotation = KRVector3(local_rotation[0], local_rotation[1], local_rotation[2]) / 180.0 * M_PI; Vector3 node_rotation = Vector3(local_rotation[0], local_rotation[1], local_rotation[2]) / 180.0 * M_PI;
KRVector3 node_scale = KRVector3(local_scale[0], local_scale[1], local_scale[2]); Vector3 node_scale = Vector3(local_scale[0], local_scale[1], local_scale[2]);
KRVector3 node_rotation_offset = KRVector3(rotation_offset[0], rotation_offset[1], rotation_offset[2]); Vector3 node_rotation_offset = Vector3(rotation_offset[0], rotation_offset[1], rotation_offset[2]);
KRVector3 node_scaling_offset = KRVector3(scaling_offset[0], scaling_offset[1], scaling_offset[2]); Vector3 node_scaling_offset = Vector3(scaling_offset[0], scaling_offset[1], scaling_offset[2]);
KRVector3 node_rotation_pivot = KRVector3(rotation_pivot[0], rotation_pivot[1], rotation_pivot[2]); Vector3 node_rotation_pivot = Vector3(rotation_pivot[0], rotation_pivot[1], rotation_pivot[2]);
KRVector3 node_scaling_pivot = KRVector3(scaling_pivot[0], scaling_pivot[1], scaling_pivot[2]); Vector3 node_scaling_pivot = Vector3(scaling_pivot[0], scaling_pivot[1], scaling_pivot[2]);
KRVector3 node_pre_rotation, node_post_rotation; Vector3 node_pre_rotation, node_post_rotation;
if(rotation_active) { if(rotation_active) {
node_pre_rotation = KRVector3(pre_rotation[0], pre_rotation[1], pre_rotation[2]) / 180.0 * M_PI; node_pre_rotation = Vector3(pre_rotation[0], pre_rotation[1], pre_rotation[2]) / 180.0 * M_PI;
node_post_rotation = KRVector3(post_rotation[0], post_rotation[1], post_rotation[2]) / 180.0 * M_PI; node_post_rotation = Vector3(post_rotation[0], post_rotation[1], post_rotation[2]) / 180.0 * M_PI;
//&KRF HACK removing this line (above) to prevent the post rotation from corrupting the default light values; the FBX is importing a post rotation and setting it to -90 degrees //&KRF HACK removing this line (above) to prevent the post rotation from corrupting the default light values; the FBX is importing a post rotation and setting it to -90 degrees
} else { } else {
node_pre_rotation = KRVector3::Zero(); node_pre_rotation = Vector3::Zero();
node_post_rotation = KRVector3::Zero(); node_post_rotation = Vector3::Zero();
} }
// printf(" Local Translation: %f %f %f\n", local_translation[0], local_translation[1], local_translation[2]); // printf(" Local Translation: %f %f %f\n", local_translation[0], local_translation[1], local_translation[2]);
@@ -1115,15 +1115,15 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) {
// Ambient Color // Ambient Color
lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Ambient; lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Ambient;
new_material->setAmbient(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); new_material->setAmbient(Vector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]));
// Diffuse Color // Diffuse Color
lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Diffuse; lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Diffuse;
new_material->setDiffuse(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); new_material->setDiffuse(Vector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]));
// Specular Color (unique to Phong materials) // Specular Color (unique to Phong materials)
lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Specular; lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Specular;
new_material->setSpecular(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); new_material->setSpecular(Vector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]));
// Emissive Color // Emissive Color
//lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Emissive; //lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Emissive;
@@ -1155,18 +1155,18 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) {
//lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Reflection; //lKFbxDouble3 =((FbxSurfacePhong *) pMaterial)->Reflection;
// We modulate Relection color by reflection factor, as we only have one "reflection color" variable in Kraken // We modulate Relection color by reflection factor, as we only have one "reflection color" variable in Kraken
new_material->setReflection(KRVector3(/*lKFbxDouble3.Get()[0] * */lKFbxDouble1.Get(), /*lKFbxDouble3.Get()[1] * */lKFbxDouble1.Get(), /*lKFbxDouble3.Get()[2] * */lKFbxDouble1.Get())); new_material->setReflection(Vector3(/*lKFbxDouble3.Get()[0] * */lKFbxDouble1.Get(), /*lKFbxDouble3.Get()[1] * */lKFbxDouble1.Get(), /*lKFbxDouble3.Get()[2] * */lKFbxDouble1.Get()));
} else if(pMaterial->GetClassId().Is(FbxSurfaceLambert::ClassId) ) { } else if(pMaterial->GetClassId().Is(FbxSurfaceLambert::ClassId) ) {
// We found a Lambert material. // We found a Lambert material.
// Ambient Color // Ambient Color
lKFbxDouble3=((FbxSurfaceLambert *)pMaterial)->Ambient; lKFbxDouble3=((FbxSurfaceLambert *)pMaterial)->Ambient;
new_material->setAmbient(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); new_material->setAmbient(Vector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]));
// Diffuse Color // Diffuse Color
lKFbxDouble3 =((FbxSurfaceLambert *)pMaterial)->Diffuse; lKFbxDouble3 =((FbxSurfaceLambert *)pMaterial)->Diffuse;
new_material->setDiffuse(KRVector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2])); new_material->setDiffuse(Vector3(lKFbxDouble3.Get()[0], lKFbxDouble3.Get()[1], lKFbxDouble3.Get()[2]));
// Emissive // Emissive
//lKFbxDouble3 =((KFbxSurfaceLambert *)pMaterial)->Emissive; //lKFbxDouble3 =((KFbxSurfaceLambert *)pMaterial)->Emissive;
@@ -1306,10 +1306,10 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe
if(FbxPose::GetBindPoseContaining(pFbxScene, cluster->GetLink(), pose_list, pose_indices)) { if(FbxPose::GetBindPoseContaining(pFbxScene, cluster->GetLink(), pose_list, pose_indices)) {
fbx_bind_pose_matrix = (*pose_list)[0].GetMatrix(pose_indices[0]); fbx_bind_pose_matrix = (*pose_list)[0].GetMatrix(pose_indices[0]);
bind_pose = KRMat4( bind_pose = KRMat4(
KRVector3(fbx_bind_pose_matrix.GetColumn(0).mData), Vector3(fbx_bind_pose_matrix.GetColumn(0).mData),
KRVector3(fbx_bind_pose_matrix.GetColumn(1).mData), Vector3(fbx_bind_pose_matrix.GetColumn(1).mData),
KRVector3(fbx_bind_pose_matrix.GetColumn(2).mData), Vector3(fbx_bind_pose_matrix.GetColumn(2).mData),
KRVector3(fbx_bind_pose_matrix.GetColumn(3).mData) Vector3(fbx_bind_pose_matrix.GetColumn(3).mData)
); );
fprintf(stderr, "Found bind pose(s)!\n"); fprintf(stderr, "Found bind pose(s)!\n");
} }
@@ -1318,10 +1318,10 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe
FbxAMatrix link_matrix; FbxAMatrix link_matrix;
cluster->GetTransformLinkMatrix(link_matrix); cluster->GetTransformLinkMatrix(link_matrix);
mi.bone_bind_poses.push_back(KRMat4( mi.bone_bind_poses.push_back(KRMat4(
KRVector3(link_matrix.GetColumn(0).mData), Vector3(link_matrix.GetColumn(0).mData),
KRVector3(link_matrix.GetColumn(1).mData), Vector3(link_matrix.GetColumn(1).mData),
KRVector3(link_matrix.GetColumn(2).mData), Vector3(link_matrix.GetColumn(2).mData),
KRVector3(link_matrix.GetColumn(3).mData) Vector3(link_matrix.GetColumn(3).mData)
)); ));
int cluster_control_point_count = cluster->GetControlPointIndicesCount(); int cluster_control_point_count = cluster->GetControlPointIndicesCount();
@@ -1381,11 +1381,11 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe
// std::vector<std::vector<float> > bone_weights; // std::vector<std::vector<float> > bone_weights;
// std::vector<std::vector<int> > bone_indexes; // std::vector<std::vector<int> > bone_indexes;
// //
// std::vector<KRVector3> vertices; // std::vector<Vector3> vertices;
// std::vector<Vector2> uva; // std::vector<Vector2> uva;
// std::vector<Vector2> uvb; // std::vector<Vector2> uvb;
// std::vector<KRVector3> normals; // std::vector<Vector3> normals;
// std::vector<KRVector3> tangents; // std::vector<Vector3> tangents;
// std::vector<int> submesh_lengths; // std::vector<int> submesh_lengths;
// std::vector<int> submesh_starts; // std::vector<int> submesh_starts;
// std::vector<std::string> material_names; // std::vector<std::string> material_names;
@@ -1434,7 +1434,7 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe
// ----====---- Read Vertex Position ----====---- // ----====---- Read Vertex Position ----====----
int lControlPointIndex = pMesh->GetPolygonVertex(iPolygon, iVertex); int lControlPointIndex = pMesh->GetPolygonVertex(iPolygon, iVertex);
FbxVector4 v = control_points[lControlPointIndex]; FbxVector4 v = control_points[lControlPointIndex];
mi.vertices.push_back(KRVector3(v[0], v[1], v[2])); mi.vertices.push_back(Vector3(v[0], v[1], v[2]));
if(mi.bone_names.size() > 0) { if(mi.bone_names.size() > 0) {
control_point_weight_info_t &weight_info = control_point_weights[lControlPointIndex]; control_point_weight_info_t &weight_info = control_point_weights[lControlPointIndex];
@@ -1484,7 +1484,7 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe
FbxVector4 new_normal; FbxVector4 new_normal;
if(pMesh->GetPolygonVertexNormal(iPolygon, iVertex, new_normal)) { if(pMesh->GetPolygonVertexNormal(iPolygon, iVertex, new_normal)) {
mi.normals.push_back(KRVector3(new_normal[0], new_normal[1], new_normal[2])); mi.normals.push_back(Vector3(new_normal[0], new_normal[1], new_normal[2]));
} }
/* /*
@@ -1513,7 +1513,7 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe
} }
} }
if(l == 0) { if(l == 0) {
mi.tangents.push_back(KRVector3(new_tangent[0], new_tangent[1], new_tangent[2])); mi.tangents.push_back(Vector3(new_tangent[0], new_tangent[1], new_tangent[2]));
} }
} }
@@ -1715,7 +1715,7 @@ KRNode *LoadLight(KRNode *parent_node, FbxNode* pNode) {
} }
if(new_light) { if(new_light) {
new_light->setColor(KRVector3(light_color[0], light_color[1], light_color[2])); new_light->setColor(Vector3(light_color[0], light_color[1], light_color[2]));
new_light->setIntensity(light_intensity); new_light->setIntensity(light_intensity);
new_light->setDecayStart(light_decaystart); new_light->setDecayStart(light_decaystart);
} }

View File

@@ -101,9 +101,9 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
int *pFaces = (int *)malloc(sizeof(int) * (cFaces + 1)); int *pFaces = (int *)malloc(sizeof(int) * (cFaces + 1));
assert(pFaces != NULL); assert(pFaces != NULL);
std::vector<KRVector3> indexed_vertices; std::vector<Vector3> indexed_vertices;
std::vector<Vector2> indexed_uva; std::vector<Vector2> indexed_uva;
std::vector<KRVector3> indexed_normals; std::vector<Vector3> indexed_normals;
int *pFace = pFaces; int *pFace = pFaces;
int *pMaterialFaces = pFace++; int *pMaterialFaces = pFace++;
@@ -154,7 +154,7 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
y = strtof(pChar, &pChar); y = strtof(pChar, &pChar);
pChar = szSymbol[3]; pChar = szSymbol[3];
z = strtof(pChar, &pChar); z = strtof(pChar, &pChar);
indexed_vertices.push_back(KRVector3(x,y,z)); indexed_vertices.push_back(Vector3(x,y,z));
} else if(strcmp(szSymbol[0], "vt") == 0) { } else if(strcmp(szSymbol[0], "vt") == 0) {
// Vertex Texture UV Coordinate (vt) // Vertex Texture UV Coordinate (vt)
char *pChar = szSymbol[1]; char *pChar = szSymbol[1];
@@ -173,7 +173,7 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
y = strtof(pChar, &pChar); y = strtof(pChar, &pChar);
pChar = szSymbol[3]; pChar = szSymbol[3];
z = strtof(pChar, &pChar); z = strtof(pChar, &pChar);
indexed_normals.push_back(KRVector3(x,y,z)); indexed_normals.push_back(Vector3(x,y,z));
} else if(strcmp(szSymbol[0], "f") == 0) { } else if(strcmp(szSymbol[0], "f") == 0) {
// Face (f) // Face (f)
int cFaceVertices = cSymbols - 1; int cFaceVertices = cSymbols - 1;
@@ -249,10 +249,10 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
int *pMaterialEndFace = pFace + *pFace++; int *pMaterialEndFace = pFace + *pFace++;
while(pFace < pMaterialEndFace && iVertex < cVertexData) { while(pFace < pMaterialEndFace && iVertex < cVertexData) {
int cFaceVertexes = *pFace; int cFaceVertexes = *pFace;
KRVector3 firstFaceVertex; Vector3 firstFaceVertex;
KRVector3 prevFaceVertex; Vector3 prevFaceVertex;
KRVector3 firstFaceNormal; Vector3 firstFaceNormal;
KRVector3 prevFaceNormal; Vector3 prevFaceNormal;
Vector2 firstFaceUva; Vector2 firstFaceUva;
Vector2 prevFaceUva; Vector2 prevFaceUva;
for(int iFaceVertex=0; iFaceVertex < cFaceVertexes; iFaceVertex++) { for(int iFaceVertex=0; iFaceVertex < cFaceVertexes; iFaceVertex++) {
@@ -268,14 +268,14 @@ std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::str
mi.uva.push_back(prevFaceUva); mi.uva.push_back(prevFaceUva);
mi.normals.push_back(prevFaceNormal); mi.normals.push_back(prevFaceNormal);
} }
KRVector3 vertex = indexed_vertices[pFace[iFaceVertex*3+1]]; Vector3 vertex = indexed_vertices[pFace[iFaceVertex*3+1]];
Vector2 new_uva; Vector2 new_uva;
if(pFace[iFaceVertex*3+2] >= 0) { if(pFace[iFaceVertex*3+2] >= 0) {
new_uva = indexed_uva[pFace[iFaceVertex*3+2]]; new_uva = indexed_uva[pFace[iFaceVertex*3+2]];
} }
KRVector3 normal; Vector3 normal;
if(pFace[iFaceVertex*3+3] >= 0){ if(pFace[iFaceVertex*3+3] >= 0){
KRVector3 normal = indexed_normals[pFace[iFaceVertex*3+3]]; Vector3 normal = indexed_normals[pFace[iFaceVertex*3+3]];
} }
mi.vertices.push_back(vertex); mi.vertices.push_back(vertex);

View File

@@ -97,7 +97,7 @@ void KRReverbZone::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_
KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
// Enable additive blending // Enable additive blending
GLDEBUG(glEnable(GL_BLEND)); GLDEBUG(glEnable(GL_BLEND));
@@ -138,17 +138,17 @@ void KRReverbZone::setGradientDistance(float gradient_distance)
KRAABB KRReverbZone::getBounds() { KRAABB KRReverbZone::getBounds() {
// Reverb zones always have a -1, -1, -1 to 1, 1, 1 bounding box // Reverb zones always have a -1, -1, -1 to 1, 1, 1 bounding box
return KRAABB(-KRVector3::One(), KRVector3::One(), getModelMatrix()); return KRAABB(-Vector3::One(), Vector3::One(), getModelMatrix());
} }
float KRReverbZone::getContainment(const KRVector3 &pos) float KRReverbZone::getContainment(const Vector3 &pos)
{ {
KRAABB bounds = getBounds(); KRAABB bounds = getBounds();
if(bounds.contains(pos)) { if(bounds.contains(pos)) {
KRVector3 size = bounds.size(); Vector3 size = bounds.size();
KRVector3 diff = pos - bounds.center(); Vector3 diff = pos - bounds.center();
diff = diff * 2.0f; diff = diff * 2.0f;
diff = KRVector3(diff.x / size.x, diff.y / size.y, diff.z / size.z); diff = Vector3(diff.x / size.x, diff.y / size.y, diff.z / size.z);
float d = diff.magnitude(); float d = diff.magnitude();
if(m_gradient_distance <= 0.0f) { if(m_gradient_distance <= 0.0f) {

View File

@@ -37,7 +37,7 @@ public:
virtual KRAABB getBounds(); virtual KRAABB getBounds();
float getContainment(const KRVector3 &pos); float getContainment(const Vector3 &pos);
private: private:
std::string m_zone; std::string m_zone;

View File

@@ -208,7 +208,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map<KRAABB, int> &visi
bool in_viewport = false; bool in_viewport = false;
if(renderPass == KRNode::RENDER_PASS_PRESTREAM) { if(renderPass == KRNode::RENDER_PASS_PRESTREAM) {
// When pre-streaming, objects are streamed in behind and in-front of the camera // When pre-streaming, objects are streamed in behind and in-front of the camera
KRAABB viewportExtents = KRAABB(viewport.getCameraPosition() - KRVector3(pCamera->settings.getPerspectiveFarZ()), viewport.getCameraPosition() + KRVector3(pCamera->settings.getPerspectiveFarZ())); KRAABB viewportExtents = KRAABB(viewport.getCameraPosition() - Vector3(pCamera->settings.getPerspectiveFarZ()), viewport.getCameraPosition() + Vector3(pCamera->settings.getPerspectiveFarZ()));
in_viewport = octreeBounds.intersects(viewportExtents); in_viewport = octreeBounds.intersects(viewportExtents);
} else { } else {
in_viewport = viewport.visible(pOctreeNode->getBounds()); in_viewport = viewport.visible(pOctreeNode->getBounds());
@@ -227,7 +227,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map<KRAABB, int> &visi
if(!bVisible) { if(!bVisible) {
// Assume bounding boxes are visible without occlusion test queries if the camera is inside the box. // 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 // The near clipping plane of the camera is taken into consideration by expanding the match area
KRAABB cameraExtents = KRAABB(viewport.getCameraPosition() - KRVector3(pCamera->settings.getPerspectiveNearZ()), viewport.getCameraPosition() + KRVector3(pCamera->settings.getPerspectiveNearZ())); KRAABB cameraExtents = KRAABB(viewport.getCameraPosition() - Vector3(pCamera->settings.getPerspectiveNearZ()), viewport.getCameraPosition() + Vector3(pCamera->settings.getPerspectiveNearZ()));
bVisible = octreeBounds.intersects(cameraExtents); bVisible = octreeBounds.intersects(cameraExtents);
if(bVisible) { if(bVisible) {
// Record the frame number in which the camera was within the bounds // Record the frame number in which the camera was within the bounds
@@ -298,7 +298,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, unordered_map<KRAABB, int> &visi
GLDEBUG(glDepthMask(GL_FALSE)); GLDEBUG(glDepthMask(GL_FALSE));
} }
if(getContext().getShaderManager()->selectShader("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, matModel, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader("occlusion_test", *pCamera, point_lights, directional_lights, spot_lights, 0, viewport, matModel, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14)); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
m_pContext->getMeshManager()->log_draw_call(renderPass, "octree", "occlusion_test", 14); m_pContext->getMeshManager()->log_draw_call(renderPass, "octree", "occlusion_test", 14);
} }
@@ -565,7 +565,7 @@ void KRScene::addDefaultLights()
{ {
KRDirectionalLight *light1 = new KRDirectionalLight(*this, "default_light1"); KRDirectionalLight *light1 = new KRDirectionalLight(*this, "default_light1");
light1->setLocalRotation((KRQuaternion(KRVector3(0.0, M_PI * 0.10, 0.0)) * KRQuaternion(KRVector3(0.0, 0.0, -M_PI * 0.15))).eulerXYZ()); light1->setLocalRotation((KRQuaternion(Vector3(0.0, M_PI * 0.10, 0.0)) * KRQuaternion(Vector3(0.0, 0.0, -M_PI * 0.15))).eulerXYZ());
m_pRootNode->addChild(light1); m_pRootNode->addChild(light1);
} }
@@ -574,22 +574,22 @@ KRAABB KRScene::getRootOctreeBounds()
if(m_nodeTree.getRootNode()) { if(m_nodeTree.getRootNode()) {
return m_nodeTree.getRootNode()->getBounds(); return m_nodeTree.getRootNode()->getBounds();
} else { } else {
return KRAABB(-KRVector3::One(), KRVector3::One()); return KRAABB(-Vector3::One(), Vector3::One());
} }
} }
bool KRScene::lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask) bool KRScene::lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask)
{ {
return m_nodeTree.lineCast(v0, v1, hitinfo, layer_mask); return m_nodeTree.lineCast(v0, v1, hitinfo, layer_mask);
} }
bool KRScene::rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask) bool KRScene::rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask)
{ {
return m_nodeTree.rayCast(v0, dir, hitinfo, layer_mask); return m_nodeTree.rayCast(v0, dir, hitinfo, layer_mask);
} }
bool KRScene::sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask) bool KRScene::sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask)
{ {
return m_nodeTree.sphereCast(v0, v1, radius, hitinfo, layer_mask); return m_nodeTree.sphereCast(v0, v1, radius, hitinfo, layer_mask);
} }

View File

@@ -65,9 +65,9 @@ public:
kraken_stream_level getStreamLevel(); kraken_stream_level getStreamLevel();
bool lineCast(const KRVector3 &v0, const KRVector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask); bool lineCast(const Vector3 &v0, const Vector3 &v1, KRHitInfo &hitinfo, unsigned int layer_mask);
bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask); bool rayCast(const Vector3 &v0, const Vector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask);
bool sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask); bool sphereCast(const Vector3 &v0, const Vector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask);
void renderFrame(GLint defaultFBO, float deltaTime, int width, int height); void renderFrame(GLint defaultFBO, float deltaTime, int width, int height);
void render(KRCamera *pCamera, unordered_map<KRAABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame); void render(KRCamera *pCamera, unordered_map<KRAABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame);

View File

@@ -295,7 +295,7 @@ void KRShader::setUniform(int location, const Vector2 &value)
} }
} }
} }
void KRShader::setUniform(int location, const KRVector3 &value) void KRShader::setUniform(int location, const Vector3 &value)
{ {
if(m_uniforms[location] != -1) { if(m_uniforms[location] != -1) {
int value_index = m_uniform_value_index[location]; int value_index = m_uniform_value_index[location];
@@ -351,7 +351,7 @@ void KRShader::setUniform(int location, const KRMat4 &value)
} }
} }
bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, const KRNode::RenderPass &renderPass, const KRVector3 &rim_color, float rim_power, const KRVector4 &fade_color) { bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const KRVector4 &fade_color) {
if(m_iProgram == 0) { if(m_iProgram == 0) {
return false; return false;
} }
@@ -417,7 +417,7 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
inverseModelMatrix.invert(); inverseModelMatrix.invert();
// Bind the light direction vector // Bind the light direction vector
KRVector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection()); Vector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, directional_light->getWorldLightDirection());
lightDirObject.normalize(); lightDirObject.normalize();
setUniform(KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE, lightDirObject); setUniform(KRENGINE_UNIFORM_LIGHT_DIRECTION_MODEL_SPACE, lightDirObject);
} }
@@ -438,7 +438,7 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
if(m_uniforms[KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE] != -1) { if(m_uniforms[KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE] != -1) {
// Transform location of camera to object space for calculation of specular halfVec // Transform location of camera to object space for calculation of specular halfVec
KRVector3 cameraPosObject = KRMat4::Dot(inverseModelMatrix, viewport.getCameraPosition()); Vector3 cameraPosObject = KRMat4::Dot(inverseModelMatrix, viewport.getCameraPosition());
setUniform(KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE, cameraPosObject); setUniform(KRENGINE_UNIFORM_CAMERAPOS_MODEL_SPACE, cameraPosObject);
} }
} }
@@ -459,7 +459,7 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
if(m_uniforms[KRShader::KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN] != -1) { if(m_uniforms[KRShader::KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN] != -1) {
KRVector3 view_space_model_origin = KRMat4::Dot(matModelView, KRVector3::Zero()); // Origin point of model space is the light source position. No perspective, so no w divide required Vector3 view_space_model_origin = KRMat4::Dot(matModelView, Vector3::Zero()); // Origin point of model space is the light source position. No perspective, so no w divide required
setUniform(KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN, view_space_model_origin); setUniform(KRENGINE_UNIFORM_VIEW_SPACE_MODEL_ORIGIN, view_space_model_origin);
} }

View File

@@ -46,7 +46,7 @@ public:
virtual ~KRShader(); virtual ~KRShader();
const char *getKey() const; const char *getKey() const;
bool bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, const KRNode::RenderPass &renderPass, const KRVector3 &rim_color, float rim_power, const KRVector4 &fade_color); bool bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const KRVector4 &fade_color);
enum { enum {
KRENGINE_UNIFORM_MATERIAL_AMBIENT = 0, KRENGINE_UNIFORM_MATERIAL_AMBIENT = 0,
@@ -140,7 +140,7 @@ public:
std::vector<float> m_uniform_value_float; std::vector<float> m_uniform_value_float;
std::vector<int> m_uniform_value_int; std::vector<int> m_uniform_value_int;
std::vector<Vector2> m_uniform_value_vector2; std::vector<Vector2> m_uniform_value_vector2;
std::vector<KRVector3> m_uniform_value_vector3; std::vector<Vector3> m_uniform_value_vector3;
std::vector<KRVector4> m_uniform_value_vector4; std::vector<KRVector4> m_uniform_value_vector4;
std::vector<KRMat4> m_uniform_value_mat4; std::vector<KRMat4> m_uniform_value_mat4;
@@ -150,7 +150,7 @@ public:
void setUniform(int location, float value); void setUniform(int location, float value);
void setUniform(int location, int value); void setUniform(int location, int value);
void setUniform(int location, const Vector2 &value); void setUniform(int location, const Vector2 &value);
void setUniform(int location, const KRVector3 &value); void setUniform(int location, const Vector3 &value);
void setUniform(int location, const KRVector4 &value); void setUniform(int location, const KRVector4 &value);
void setUniform(int location, const KRMat4 &value); void setUniform(int location, const KRMat4 &value);

View File

@@ -245,13 +245,13 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, KRCamera *p
return pShader; return pShader;
} }
bool KRShaderManager::selectShader(const std::string &shader_name, KRCamera &camera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRViewport &viewport, const KRMat4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, const KRVector3 &rim_color, float rim_power, const KRVector4 &fade_color) bool KRShaderManager::selectShader(const std::string &shader_name, KRCamera &camera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRViewport &viewport, const KRMat4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, const Vector3 &rim_color, float rim_power, const KRVector4 &fade_color)
{ {
KRShader *pShader = getShader(shader_name, &camera, point_lights, directional_lights, spot_lights, bone_count, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, bLightMap, bDiffuseMapScale, bSpecMapScale, bNormalMapScale, bReflectionMapScale, bDiffuseMapOffset, bSpecMapOffset, bNormalMapOffset, bReflectionMapOffset, bAlphaTest, bAlphaBlend, renderPass, rim_power != 0.0f); KRShader *pShader = getShader(shader_name, &camera, point_lights, directional_lights, spot_lights, bone_count, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, bLightMap, bDiffuseMapScale, bSpecMapScale, bNormalMapScale, bReflectionMapScale, bDiffuseMapOffset, bSpecMapOffset, bNormalMapOffset, bReflectionMapOffset, bAlphaTest, bAlphaBlend, renderPass, rim_power != 0.0f);
return selectShader(camera, pShader, viewport, matModel, point_lights, directional_lights, spot_lights, bone_count, renderPass, rim_color, rim_power, fade_color); return selectShader(camera, pShader, viewport, matModel, point_lights, directional_lights, spot_lights, bone_count, renderPass, rim_color, rim_power, fade_color);
} }
bool KRShaderManager::selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const KRMat4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const KRVector3 &rim_color, float rim_power, const KRVector4 &fade_color) bool KRShaderManager::selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const KRMat4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const KRVector4 &fade_color)
{ {
if(pShader) { if(pShader) {
return pShader->bind(camera, viewport, matModel, point_lights, directional_lights, spot_lights, renderPass, rim_color, rim_power, fade_color); return pShader->bind(camera, viewport, matModel, point_lights, directional_lights, spot_lights, renderPass, rim_color, rim_power, fade_color);

View File

@@ -60,9 +60,9 @@ public:
KRShader *getShader(const std::string &shader_name, KRCamera *pCamera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, bool bRimColor = false); KRShader *getShader(const std::string &shader_name, KRCamera *pCamera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, bool bRimColor = false);
bool selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const KRMat4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const KRVector3 &rim_color, float rim_power, const KRVector4 &fade_color); bool selectShader(KRCamera &camera, KRShader *pShader, const KRViewport &viewport, const KRMat4 &matModel, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRNode::RenderPass &renderPass, const Vector3 &rim_color, float rim_power, const KRVector4 &fade_color);
bool selectShader(const std::string &shader_name, KRCamera &camera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRViewport &viewport, const KRMat4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, const KRVector3 &rim_color, float rim_power, const KRVector4 &fade_color); bool selectShader(const std::string &shader_name, KRCamera &camera, const std::vector<KRPointLight *> &point_lights, const std::vector<KRDirectionalLight *> &directional_lights, const std::vector<KRSpotLight *>&spot_lights, int bone_count, const KRViewport &viewport, const KRMat4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass, const Vector3 &rim_color, float rim_power, const KRVector4 &fade_color);
long getShaderHandlesUsed(); long getShaderHandlesUsed();

View File

@@ -55,7 +55,7 @@ KRAABB KRSpotLight::getBounds() {
if(influence_radius < m_flareOcclusionSize) { if(influence_radius < m_flareOcclusionSize) {
influence_radius = m_flareOcclusionSize; influence_radius = m_flareOcclusionSize;
} }
return KRAABB(KRVector3(-influence_radius), KRVector3(influence_radius), getModelMatrix()); return KRAABB(Vector3(-influence_radius), Vector3(influence_radius), getModelMatrix());
} }

View File

@@ -77,7 +77,7 @@ float KRSprite::getSpriteAlpha() const
} }
KRAABB KRSprite::getBounds() { KRAABB KRSprite::getBounds() {
return KRAABB(-KRVector3::One() * 0.5f, KRVector3::One() * 0.5f, getModelMatrix()); return KRAABB(-Vector3::One() * 0.5f, Vector3::One() * 0.5f, getModelMatrix());
} }
@@ -128,7 +128,7 @@ void KRSprite::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_ligh
// Render light sprite on transparency pass // Render light sprite on transparency pass
KRShader *pShader = getContext().getShaderManager()->getShader("sprite", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pShader = getContext().getShaderManager()->getShader("sprite", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) { if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, KRVector4::Zero())) {
pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_spriteAlpha); pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_spriteAlpha);
m_pContext->getTextureManager()->selectTexture(0, m_pSpriteTexture, 0.0f, KRTexture::TEXTURE_USAGE_SPRITE); m_pContext->getTextureManager()->selectTexture(0, m_pSpriteTexture, 0.0f, KRTexture::TEXTURE_USAGE_SPRITE);
m_pContext->getMeshManager()->bindVBO(&m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f); m_pContext->getMeshManager()->bindVBO(&m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);

View File

@@ -11,16 +11,16 @@
using namespace kraken; using namespace kraken;
namespace { namespace {
bool _intersectSphere(const KRVector3 &start, const KRVector3 &dir, const KRVector3 &sphere_center, float sphere_radius, float &distance) bool _intersectSphere(const Vector3 &start, const Vector3 &dir, const Vector3 &sphere_center, float sphere_radius, float &distance)
{ {
// dir must be normalized // dir must be normalized
// From: http://archive.gamedev.net/archive/reference/articles/article1026.html // From: http://archive.gamedev.net/archive/reference/articles/article1026.html
// TODO - Move to another class? // TODO - Move to another class?
KRVector3 Q = sphere_center - start; Vector3 Q = sphere_center - start;
float c = Q.magnitude(); float c = Q.magnitude();
float v = KRVector3::Dot(Q, dir); float v = Vector3::Dot(Q, dir);
float d = sphere_radius * sphere_radius - (c * c - v * v); float d = sphere_radius * sphere_radius - (c * c - v * v);
@@ -40,27 +40,27 @@ namespace {
} }
bool _sameSide(const KRVector3 &p1, const KRVector3 &p2, const KRVector3 &a, const KRVector3 &b) bool _sameSide(const Vector3 &p1, const Vector3 &p2, const Vector3 &a, const Vector3 &b)
{ {
// TODO - Move to KRVector3 class? // TODO - Move to Vector3 class?
// From: http://stackoverflow.com/questions/995445/determine-if-a-3d-point-is-within-a-triangle // From: http://stackoverflow.com/questions/995445/determine-if-a-3d-point-is-within-a-triangle
KRVector3 cp1 = KRVector3::Cross(b - a, p1 - a); Vector3 cp1 = Vector3::Cross(b - a, p1 - a);
KRVector3 cp2 = KRVector3::Cross(b - a, p2 - a); Vector3 cp2 = Vector3::Cross(b - a, p2 - a);
if (KRVector3::Dot(cp1, cp2) >= 0) return true; if (Vector3::Dot(cp1, cp2) >= 0) return true;
return false; return false;
} }
KRVector3 _closestPointOnLine(const KRVector3 &a, const KRVector3 &b, const KRVector3 &p) 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 // 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) // Determine t (the length of the vector from a to p)
KRVector3 c = p - a; Vector3 c = p - a;
KRVector3 V = KRVector3::Normalize(b - a); Vector3 V = Vector3::Normalize(b - a);
float d = (a - b).magnitude(); float d = (a - b).magnitude();
float t = KRVector3::Dot(V, c); float t = Vector3::Dot(V, c);
// Check to see if t is beyond the extents of the line segment // Check to see if t is beyond the extents of the line segment
@@ -75,7 +75,7 @@ namespace {
namespace kraken { namespace kraken {
KRTriangle3::KRTriangle3(const KRVector3 &v1, const KRVector3 &v2, const KRVector3 &v3) KRTriangle3::KRTriangle3(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3)
{ {
vert[0] = v1; vert[0] = v1;
vert[1] = v2; vert[1] = v2;
@@ -114,35 +114,35 @@ KRTriangle3& KRTriangle3::operator =(const KRTriangle3& b)
return *this; return *this;
} }
KRVector3& KRTriangle3::operator[](unsigned int i) Vector3& KRTriangle3::operator[](unsigned int i)
{ {
return vert[i]; return vert[i];
} }
KRVector3 KRTriangle3::operator[](unsigned int i) const Vector3 KRTriangle3::operator[](unsigned int i) const
{ {
return vert[i]; return vert[i];
} }
bool KRTriangle3::rayCast(const KRVector3 &start, const KRVector3 &dir, KRVector3 &hit_point) const bool KRTriangle3::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 // 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 const float SMALL_NUM = 0.00000001; // anything that avoids division overflow
KRVector3 u, v, n; // triangle vectors Vector3 u, v, n; // triangle vectors
KRVector3 w0, w; // ray vectors Vector3 w0, w; // ray vectors
float r, a, b; // params to calc ray-plane intersect float r, a, b; // params to calc ray-plane intersect
// get triangle edge vectors and plane normal // get triangle edge vectors and plane normal
u = vert[1] - vert[0]; u = vert[1] - vert[0];
v = vert[2] - vert[0]; v = vert[2] - vert[0];
n = KRVector3::Cross(u, v); // cross product n = Vector3::Cross(u, v); // cross product
if (n == KRVector3::Zero()) // triangle is degenerate if (n == Vector3::Zero()) // triangle is degenerate
return false; // do not deal with this case return false; // do not deal with this case
w0 = start - vert[0]; w0 = start - vert[0];
a = -KRVector3::Dot(n, w0); a = -Vector3::Dot(n, w0);
b = KRVector3::Dot(n,dir); b = Vector3::Dot(n,dir);
if (fabs(b) < SMALL_NUM) { // ray is parallel to triangle plane if (fabs(b) < SMALL_NUM) { // ray is parallel to triangle plane
if (a == 0) if (a == 0)
return false; // ray lies in triangle plane return false; // ray lies in triangle plane
@@ -158,16 +158,16 @@ bool KRTriangle3::rayCast(const KRVector3 &start, const KRVector3 &dir, KRVector
// for a segment, also test if (r > 1.0) => no intersect // for a segment, also test if (r > 1.0) => no intersect
KRVector3 plane_hit_point = start + dir * r; // intersect point of ray and plane Vector3 plane_hit_point = start + dir * r; // intersect point of ray and plane
// is plane_hit_point inside triangle? // is plane_hit_point inside triangle?
float uu, uv, vv, wu, wv, D; float uu, uv, vv, wu, wv, D;
uu = KRVector3::Dot(u,u); uu = Vector3::Dot(u,u);
uv = KRVector3::Dot(u,v); uv = Vector3::Dot(u,v);
vv = KRVector3::Dot(v,v); vv = Vector3::Dot(v,v);
w = plane_hit_point - vert[0]; w = plane_hit_point - vert[0];
wu = KRVector3::Dot(w,u); wu = Vector3::Dot(w,u);
wv = KRVector3::Dot(w,v); wv = Vector3::Dot(w,v);
D = uv * uv - uu * vv; D = uv * uv - uu * vv;
// get and test parametric coords // get and test parametric coords
@@ -184,23 +184,23 @@ bool KRTriangle3::rayCast(const KRVector3 &start, const KRVector3 &dir, KRVector
return true; return true;
} }
KRVector3 KRTriangle3::calculateNormal() const Vector3 KRTriangle3::calculateNormal() const
{ {
KRVector3 v1 = vert[1] - vert[0]; Vector3 v1 = vert[1] - vert[0];
KRVector3 v2 = vert[2] - vert[0]; Vector3 v2 = vert[2] - vert[0];
return KRVector3::Normalize(KRVector3::Cross(v1, v2)); return Vector3::Normalize(Vector3::Cross(v1, v2));
} }
KRVector3 KRTriangle3::closestPointOnTriangle(const KRVector3 &p) const Vector3 KRTriangle3::closestPointOnTriangle(const Vector3 &p) const
{ {
KRVector3 a = vert[0]; Vector3 a = vert[0];
KRVector3 b = vert[1]; Vector3 b = vert[1];
KRVector3 c = vert[2]; Vector3 c = vert[2];
KRVector3 Rab = _closestPointOnLine(a, b, p); Vector3 Rab = _closestPointOnLine(a, b, p);
KRVector3 Rbc = _closestPointOnLine(b, c, p); Vector3 Rbc = _closestPointOnLine(b, c, p);
KRVector3 Rca = _closestPointOnLine(c, a, p); Vector3 Rca = _closestPointOnLine(c, a, p);
// return closest [Rab, Rbc, Rca] to p; // return closest [Rab, Rbc, Rca] to p;
float sd_Rab = (p - Rab).sqrMagnitude(); float sd_Rab = (p - Rab).sqrMagnitude();
@@ -216,21 +216,21 @@ KRVector3 KRTriangle3::closestPointOnTriangle(const KRVector3 &p) const
} }
} }
bool KRTriangle3::sphereCast(const KRVector3 &start, const KRVector3 &dir, float radius, KRVector3 &hit_point, float &hit_distance) const bool KRTriangle3::sphereCast(const Vector3 &start, const Vector3 &dir, float radius, Vector3 &hit_point, float &hit_distance) const
{ {
// Dir must be normalized // Dir must be normalized
const float SMALL_NUM = 0.001f; // anything that avoids division overflow const float SMALL_NUM = 0.001f; // anything that avoids division overflow
KRVector3 tri_normal = calculateNormal(); Vector3 tri_normal = calculateNormal();
float d = KRVector3::Dot(tri_normal, vert[0]); float d = Vector3::Dot(tri_normal, vert[0]);
float e = KRVector3::Dot(tri_normal, start) - radius; float e = Vector3::Dot(tri_normal, start) - radius;
float cotangent_distance = e - d; float cotangent_distance = e - d;
KRVector3 plane_intersect; Vector3 plane_intersect;
float plane_intersect_distance; float plane_intersect_distance;
float denom = KRVector3::Dot(tri_normal, dir); float denom = Vector3::Dot(tri_normal, dir);
if(denom > -SMALL_NUM) { if(denom > -SMALL_NUM) {
return false; // dir is co-planar with the triangle or going in the direction of the normal; no intersection return false; // dir is co-planar with the triangle or going in the direction of the normal; no intersection
@@ -261,7 +261,7 @@ bool KRTriangle3::sphereCast(const KRVector3 &start, const KRVector3 &dir, float
return true; return true;
} else { } else {
// Triangle does not contain point, cast ray back to sphere from closest point on triangle edge or vertice // Triangle does not contain point, cast ray back to sphere from closest point on triangle edge or vertice
KRVector3 closest_point = closestPointOnTriangle(plane_intersect); Vector3 closest_point = closestPointOnTriangle(plane_intersect);
float reverse_hit_distance; float reverse_hit_distance;
if(_intersectSphere(closest_point, -dir, start, radius, reverse_hit_distance)) { if(_intersectSphere(closest_point, -dir, start, radius, reverse_hit_distance)) {
// Reverse cast hit sphere // Reverse cast hit sphere
@@ -276,16 +276,16 @@ bool KRTriangle3::sphereCast(const KRVector3 &start, const KRVector3 &dir, float
} }
bool KRTriangle3::containsPoint(const KRVector3 &p) const bool KRTriangle3::containsPoint(const Vector3 &p) const
{ {
/* /*
// From: http://stackoverflow.com/questions/995445/determine-if-a-3d-point-is-within-a-triangle // 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 const float SMALL_NUM = 0.00000001f; // anything that avoids division overflow
// KRVector3 A = vert[0], B = vert[1], C = vert[2]; // 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])) { 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])) {
KRVector3 vc1 = KRVector3::Cross(vert[0] - vert[1], vert[0] - vert[2]); Vector3 vc1 = Vector3::Cross(vert[0] - vert[1], vert[0] - vert[2]);
if(fabs(KRVector3::Dot(vert[0] - p, vc1)) <= SMALL_NUM) { if(fabs(Vector3::Dot(vert[0] - p, vc1)) <= SMALL_NUM) {
return true; return true;
} }
} }
@@ -295,28 +295,28 @@ bool KRTriangle3::containsPoint(const KRVector3 &p) const
// From: http://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspx // From: http://blogs.msdn.com/b/rezanour/archive/2011/08/07/barycentric-coordinates-and-point-in-triangle-tests.aspx
KRVector3 A = vert[0]; Vector3 A = vert[0];
KRVector3 B = vert[1]; Vector3 B = vert[1];
KRVector3 C = vert[2]; Vector3 C = vert[2];
KRVector3 P = p; Vector3 P = p;
// Prepare our barycentric variables // Prepare our barycentric variables
KRVector3 u = B - A; Vector3 u = B - A;
KRVector3 v = C - A; Vector3 v = C - A;
KRVector3 w = P - A; Vector3 w = P - A;
KRVector3 vCrossW = KRVector3::Cross(v, w); Vector3 vCrossW = Vector3::Cross(v, w);
KRVector3 vCrossU = KRVector3::Cross(v, u); Vector3 vCrossU = Vector3::Cross(v, u);
// Test sign of r // Test sign of r
if (KRVector3::Dot(vCrossW, vCrossU) < 0) if (Vector3::Dot(vCrossW, vCrossU) < 0)
return false; return false;
KRVector3 uCrossW = KRVector3::Cross(u, w); Vector3 uCrossW = Vector3::Cross(u, w);
KRVector3 uCrossV = KRVector3::Cross(u, v); Vector3 uCrossV = Vector3::Cross(u, v);
// Test sign of t // Test sign of t
if (KRVector3::Dot(uCrossW, uCrossV) < 0) if (Vector3::Dot(uCrossW, uCrossV) < 0)
return false; return false;
// At this point, we know that r and t and both > 0. // At this point, we know that r and t and both > 0.

View File

@@ -51,7 +51,7 @@ KRVector4::KRVector4(const KRVector4 &v) {
w = v.w; w = v.w;
} }
KRVector4::KRVector4(const KRVector3 &v, float W) { KRVector4::KRVector4(const Vector3 &v, float W) {
x = v.x; x = v.x;
y = v.y; y = v.y;
z = v.z; z = v.z;

View File

@@ -95,12 +95,12 @@ const KRMat4 &KRViewport::getInverseProjectionMatrix() const
return m_matInverseProjection; return m_matInverseProjection;
} }
const KRVector3 &KRViewport::getCameraDirection() const const Vector3 &KRViewport::getCameraDirection() const
{ {
return m_cameraDirection; return m_cameraDirection;
} }
const KRVector3 &KRViewport::getCameraPosition() const const Vector3 &KRViewport::getCameraPosition() const
{ {
return m_cameraPosition; return m_cameraPosition;
} }
@@ -120,8 +120,8 @@ void KRViewport::calculateDerivedValues()
m_matViewProjection = m_matView * m_matProjection; m_matViewProjection = m_matView * m_matProjection;
m_matInverseView = KRMat4::Invert(m_matView); m_matInverseView = KRMat4::Invert(m_matView);
m_matInverseProjection = KRMat4::Invert(m_matProjection); m_matInverseProjection = KRMat4::Invert(m_matProjection);
m_cameraPosition = KRMat4::Dot(m_matInverseView, KRVector3::Zero()); m_cameraPosition = KRMat4::Dot(m_matInverseView, Vector3::Zero());
m_cameraDirection = KRMat4::Dot(m_matInverseView, KRVector3(0.0, 0.0, 1.0)) - KRMat4::Dot(m_matInverseView, KRVector3(0.0, 0.0, 0.0)); m_cameraDirection = KRMat4::Dot(m_matInverseView, Vector3(0.0, 0.0, 1.0)) - KRMat4::Dot(m_matInverseView, Vector3(0.0, 0.0, 0.0));
for(int i=0; i<8; i++) { for(int i=0; i<8; i++) {
m_frontToBackOrder[i] = i; m_frontToBackOrder[i] = i;
@@ -174,10 +174,10 @@ float KRViewport::coverage(const KRAABB &b) const
if(!visible(b)) { if(!visible(b)) {
return 0.0f; // Culled out by view frustrum return 0.0f; // Culled out by view frustrum
} else { } else {
KRVector3 nearest_point = b.nearestPoint(getCameraPosition()); Vector3 nearest_point = b.nearestPoint(getCameraPosition());
float distance = (nearest_point - getCameraPosition()).magnitude(); float distance = (nearest_point - getCameraPosition()).magnitude();
KRVector3 v = KRMat4::DotWDiv(m_matProjection, getCameraPosition() + getCameraDirection() * distance); Vector3 v = KRMat4::DotWDiv(m_matProjection, getCameraPosition() + getCameraDirection() * distance);
float screen_depth = distance / 1000.0f; float screen_depth = distance / 1000.0f;
@@ -189,7 +189,7 @@ float KRViewport::coverage(const KRAABB &b) const
Vector2 screen_max; Vector2 screen_max;
// Loop through all corners and transform them to screen space // Loop through all corners and transform them to screen space
for(int i=0; i<8; i++) { for(int i=0; i<8; i++) {
KRVector3 screen_pos = KRMat4::DotWDiv(m_matViewProjection, KRVector3(i & 1 ? b.min.x : b.max.x, i & 2 ? b.min.y : b.max.y, i & 4 ? b.min.z : b.max.z)); Vector3 screen_pos = KRMat4::DotWDiv(m_matViewProjection, Vector3(i & 1 ? b.min.x : b.max.x, i & 2 ? b.min.y : b.max.y, i & 4 ? b.min.z : b.max.z));
if(i==0) { if(i==0) {
screen_min = screen_pos.xy(); screen_min = screen_pos.xy();
screen_max = screen_pos.xy(); screen_max = screen_pos.xy();

View File

@@ -25,8 +25,8 @@ public:
const KRMat4 &getViewProjectionMatrix() const; const KRMat4 &getViewProjectionMatrix() const;
const KRMat4 &getInverseViewMatrix() const; const KRMat4 &getInverseViewMatrix() const;
const KRMat4 &getInverseProjectionMatrix() const; const KRMat4 &getInverseProjectionMatrix() const;
const KRVector3 &getCameraDirection() const; const Vector3 &getCameraDirection() const;
const KRVector3 &getCameraPosition() const; const Vector3 &getCameraPosition() const;
const int *getFrontToBackOrder() const; const int *getFrontToBackOrder() const;
const int *getBackToFrontOrder() const; const int *getBackToFrontOrder() const;
void setSize(const Vector2 &size); void setSize(const Vector2 &size);
@@ -57,8 +57,8 @@ private:
KRMat4 m_matViewProjection; KRMat4 m_matViewProjection;
KRMat4 m_matInverseView; KRMat4 m_matInverseView;
KRMat4 m_matInverseProjection; KRMat4 m_matInverseProjection;
KRVector3 m_cameraDirection; Vector3 m_cameraDirection;
KRVector3 m_cameraPosition; Vector3 m_cameraPosition;
int m_frontToBackOrder[8]; int m_frontToBackOrder[8];
int m_backToFrontOrder[8]; int m_backToFrontOrder[8];

View File

@@ -14,7 +14,7 @@
#include <functional> // for hash<> #include <functional> // for hash<>
#include "Vector2.h" #include "Vector2.h"
#include "KRVector3.h" #include "Vector3.h"
namespace kraken { namespace kraken {
@@ -22,24 +22,24 @@ class KRMat4;
class KRAABB { class KRAABB {
public: public:
KRAABB(const KRVector3 &minPoint, const KRVector3 &maxPoint); KRAABB(const Vector3 &minPoint, const Vector3 &maxPoint);
KRAABB(const KRVector3 &corner1, const KRVector3 &corner2, const KRMat4 &modelMatrix); KRAABB(const Vector3 &corner1, const Vector3 &corner2, const KRMat4 &modelMatrix);
KRAABB(); KRAABB();
~KRAABB(); ~KRAABB();
void scale(const KRVector3 &s); void scale(const Vector3 &s);
void scale(float s); void scale(float s);
KRVector3 center() const; Vector3 center() const;
KRVector3 size() const; Vector3 size() const;
float volume() const; float volume() const;
bool intersects(const KRAABB& b) const; bool intersects(const KRAABB& b) const;
bool contains(const KRAABB &b) const; bool contains(const KRAABB &b) const;
bool contains(const KRVector3 &v) const; bool contains(const Vector3 &v) const;
bool intersectsLine(const KRVector3 &v1, const KRVector3 &v2) const; bool intersectsLine(const Vector3 &v1, const Vector3 &v2) const;
bool intersectsRay(const KRVector3 &v1, const KRVector3 &dir) const; bool intersectsRay(const Vector3 &v1, const Vector3 &dir) const;
bool intersectsSphere(const KRVector3 &center, float radius) const; bool intersectsSphere(const Vector3 &center, float radius) const;
void encapsulate(const KRAABB & b); void encapsulate(const KRAABB & b);
KRAABB& operator =(const KRAABB& b); KRAABB& operator =(const KRAABB& b);
@@ -50,14 +50,14 @@ public:
bool operator >(const KRAABB& b) const; bool operator >(const KRAABB& b) const;
bool operator <(const KRAABB& b) const; bool operator <(const KRAABB& b) const;
KRVector3 min; Vector3 min;
KRVector3 max; Vector3 max;
static KRAABB Infinite(); static KRAABB Infinite();
static KRAABB Zero(); static KRAABB Zero();
float longest_radius() const; float longest_radius() const;
KRVector3 nearestPoint(const KRVector3 & v) const; Vector3 nearestPoint(const Vector3 & v) const;
}; };
} // namespace kraken } // namespace kraken
@@ -68,8 +68,8 @@ namespace std {
public: public:
size_t operator()(const kraken::KRAABB &s) const size_t operator()(const kraken::KRAABB &s) const
{ {
size_t h1 = hash<kraken::KRVector3>()(s.min); size_t h1 = hash<kraken::Vector3>()(s.min);
size_t h2 = hash<kraken::KRVector3>()(s.max); size_t h2 = hash<kraken::Vector3>()(s.max);
return h1 ^ ( h2 << 1 ); return h1 ^ ( h2 << 1 );
} }
}; };

View File

@@ -30,7 +30,7 @@
// //
#include "KRVector3.h" #include "Vector3.h"
#include "KRVector4.h" #include "KRVector4.h"
#ifndef KRMAT4_H #ifndef KRMAT4_H
@@ -56,7 +56,7 @@ class KRMat4 {
KRMat4(float *pMat); KRMat4(float *pMat);
KRMat4(const KRVector3 &axis_x, const KRVector3 &axis_y, const KRVector3 &axis_z, const KRVector3 &trans); KRMat4(const Vector3 &axis_x, const Vector3 &axis_y, const Vector3 &axis_z, const Vector3 &trans);
// Destructor // Destructor
~KRMat4(); ~KRMat4();
@@ -85,9 +85,9 @@ class KRMat4 {
void perspective(float fov, float aspect, float nearz, float farz); 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 ortho(float left, float right, float top, float bottom, float nearz, float farz);
void translate(float x, float y, float z); void translate(float x, float y, float z);
void translate(const KRVector3 &v); void translate(const Vector3 &v);
void scale(float x, float y, float z); void scale(float x, float y, float z);
void scale(const KRVector3 &v); void scale(const Vector3 &v);
void scale(float s); void scale(float s);
void rotate(float angle, AXIS axis); void rotate(float angle, AXIS axis);
void rotate(const KRQuaternion &q); void rotate(const KRQuaternion &q);
@@ -95,19 +95,19 @@ class KRMat4 {
bool invert(); bool invert();
void transpose(); void transpose();
static KRVector3 DotNoTranslate(const KRMat4 &m, const KRVector3 &v); // Dot product without including translation; useful for transforming normals and tangents static Vector3 DotNoTranslate(const KRMat4 &m, const Vector3 &v); // Dot product without including translation; useful for transforming normals and tangents
static KRMat4 Invert(const KRMat4 &m); static KRMat4 Invert(const KRMat4 &m);
static KRMat4 Transpose(const KRMat4 &m); static KRMat4 Transpose(const KRMat4 &m);
static KRVector3 Dot(const KRMat4 &m, const KRVector3 &v); static Vector3 Dot(const KRMat4 &m, const Vector3 &v);
static KRVector4 Dot4(const KRMat4 &m, const KRVector4 &v); static KRVector4 Dot4(const KRMat4 &m, const KRVector4 &v);
static float DotW(const KRMat4 &m, const KRVector3 &v); static float DotW(const KRMat4 &m, const Vector3 &v);
static KRVector3 DotWDiv(const KRMat4 &m, const KRVector3 &v); static Vector3 DotWDiv(const KRMat4 &m, const Vector3 &v);
static KRMat4 LookAt(const KRVector3 &cameraPos, const KRVector3 &lookAtPos, const KRVector3 &upDirection); static KRMat4 LookAt(const Vector3 &cameraPos, const Vector3 &lookAtPos, const Vector3 &upDirection);
static KRMat4 Translation(const KRVector3 &v); static KRMat4 Translation(const Vector3 &v);
static KRMat4 Rotation(const KRVector3 &v); static KRMat4 Rotation(const Vector3 &v);
static KRMat4 Scaling(const KRVector3 &v); static KRMat4 Scaling(const Vector3 &v);
}; };
} // namespace kraken } // namespace kraken

View File

@@ -32,7 +32,7 @@
#ifndef KRQUATERNION_H #ifndef KRQUATERNION_H
#define KRQUATERNION_H #define KRQUATERNION_H
#include "KRVector3.h" #include "Vector3.h"
namespace kraken { namespace kraken {
@@ -41,8 +41,8 @@ public:
KRQuaternion(); KRQuaternion();
KRQuaternion(float w, float x, float y, float z); KRQuaternion(float w, float x, float y, float z);
KRQuaternion(const KRQuaternion& p); KRQuaternion(const KRQuaternion& p);
KRQuaternion(const KRVector3 &euler); KRQuaternion(const Vector3 &euler);
KRQuaternion(const KRVector3 &from_vector, const KRVector3 &to_vector); KRQuaternion(const Vector3 &from_vector, const Vector3 &to_vector);
~KRQuaternion(); ~KRQuaternion();
KRQuaternion& operator =( const KRQuaternion& p ); KRQuaternion& operator =( const KRQuaternion& p );
@@ -66,9 +66,9 @@ public:
float& operator [](unsigned i); float& operator [](unsigned i);
float operator [](unsigned i) const; float operator [](unsigned i) const;
void setEulerXYZ(const KRVector3 &euler); void setEulerXYZ(const Vector3 &euler);
void setEulerZYX(const KRVector3 &euler); void setEulerZYX(const Vector3 &euler);
KRVector3 eulerXYZ() const; Vector3 eulerXYZ() const;
KRMat4 rotationMatrix() const; KRMat4 rotationMatrix() const;
void normalize(); void normalize();
@@ -77,7 +77,7 @@ public:
void conjugate(); void conjugate();
static KRQuaternion Conjugate(const KRQuaternion &v1); static KRQuaternion Conjugate(const KRQuaternion &v1);
static KRQuaternion FromAngleAxis(const KRVector3 &axis, float angle); static KRQuaternion FromAngleAxis(const Vector3 &axis, float angle);
static KRQuaternion Lerp(const KRQuaternion &a, const KRQuaternion &b, float t); static KRQuaternion Lerp(const KRQuaternion &a, const KRQuaternion &b, float t);
static KRQuaternion Slerp(const KRQuaternion &a, const KRQuaternion &b, float t); static KRQuaternion Slerp(const KRQuaternion &a, const KRQuaternion &b, float t);
static float Dot(const KRQuaternion &v1, const KRQuaternion &v2); static float Dot(const KRQuaternion &v1, const KRQuaternion &v2);

View File

@@ -32,32 +32,32 @@
#ifndef KRTRIANGLE3_H #ifndef KRTRIANGLE3_H
#define KRTRIANGLE3_H #define KRTRIANGLE3_H
#include "KRVector3.h" #include "Vector3.h"
namespace kraken { namespace kraken {
class KRTriangle3 class KRTriangle3
{ {
public: public:
KRVector3 vert[3]; Vector3 vert[3];
KRTriangle3(const KRTriangle3 &tri); KRTriangle3(const KRTriangle3 &tri);
KRTriangle3(const KRVector3 &v1, const KRVector3 &v2, const KRVector3 &v3); KRTriangle3(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3);
~KRTriangle3(); ~KRTriangle3();
KRVector3 calculateNormal() const; Vector3 calculateNormal() const;
bool operator ==(const KRTriangle3& b) const; bool operator ==(const KRTriangle3& b) const;
bool operator !=(const KRTriangle3& b) const; bool operator !=(const KRTriangle3& b) const;
KRTriangle3& operator =(const KRTriangle3& b); KRTriangle3& operator =(const KRTriangle3& b);
KRVector3& operator[](unsigned int i); Vector3& operator[](unsigned int i);
KRVector3 operator[](unsigned int i) const; Vector3 operator[](unsigned int i) const;
bool rayCast(const KRVector3 &start, const KRVector3 &dir, KRVector3 &hit_point) const; bool rayCast(const Vector3 &start, const Vector3 &dir, Vector3 &hit_point) const;
bool sphereCast(const KRVector3 &start, const KRVector3 &dir, float radius, KRVector3 &hit_point, float &hit_distance) const; bool sphereCast(const Vector3 &start, const Vector3 &dir, float radius, Vector3 &hit_point, float &hit_distance) const;
bool containsPoint(const KRVector3 &p) const; bool containsPoint(const Vector3 &p) const;
KRVector3 closestPointOnTriangle(const KRVector3 &p) const; Vector3 closestPointOnTriangle(const Vector3 &p) const;
}; };
} // namespace kraken } // namespace kraken

View File

@@ -36,7 +36,7 @@
namespace kraken { namespace kraken {
class KRVector3; class Vector3;
class KRVector4 { class KRVector4 {
@@ -53,7 +53,7 @@ public:
KRVector4(float v); KRVector4(float v);
KRVector4(float *v); KRVector4(float *v);
KRVector4(const KRVector4 &v); KRVector4(const KRVector4 &v);
KRVector4(const KRVector3 &v, float W); KRVector4(const Vector3 &v, float W);
~KRVector4(); ~KRVector4();

View File

@@ -3,7 +3,7 @@
#include "KRFloat.h" #include "KRFloat.h"
#include "vector2.h" #include "vector2.h"
#include "KRVector3.h" #include "vector3.h"
#include "KRVector4.h" #include "KRVector4.h"
#include "KRMat4.h" #include "KRMat4.h"
#include "KRQuaternion.h" #include "KRQuaternion.h"

116
kraken/public/vector2.h Normal file
View File

@@ -0,0 +1,116 @@
//
// vector2.h
// Kraken
//
// Copyright 2017 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<>
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);
}
};
}
#endif // KRAKEN_VECTOR2_H

View File

@@ -1,5 +1,5 @@
// //
// KRVector3.h // Vector3.h
// Kraken // Kraken
// //
// Copyright 2017 Kearwood Gilbert. All rights reserved. // Copyright 2017 Kearwood Gilbert. All rights reserved.
@@ -34,11 +34,12 @@
#include <functional> // for hash<> #include <functional> // for hash<>
#include "Vector2.h"
#include "KRVector4.h" #include "KRVector4.h"
namespace kraken { namespace kraken {
class KRVector3 { class Vector3 {
public: public:
union { union {
@@ -48,14 +49,14 @@ public:
float c[3]; float c[3];
}; };
KRVector3(); Vector3();
KRVector3(float X, float Y, float Z); Vector3(float X, float Y, float Z);
KRVector3(float v); Vector3(float v);
KRVector3(float *v); Vector3(float *v);
KRVector3(double *v); Vector3(double *v);
KRVector3(const KRVector3 &v); Vector3(const Vector3 &v);
KRVector3(const KRVector4 &v); Vector3(const KRVector4 &v);
~KRVector3(); ~Vector3();
// Vector2 swizzle getters // Vector2 swizzle getters
Vector2 xx() const; Vector2 xx() const;
@@ -76,26 +77,26 @@ public:
void zx(const Vector2 &v); void zx(const Vector2 &v);
void zy(const Vector2 &v); void zy(const Vector2 &v);
KRVector3& operator =(const KRVector3& b); Vector3& operator =(const Vector3& b);
KRVector3& operator =(const KRVector4& b); Vector3& operator =(const KRVector4& b);
KRVector3 operator +(const KRVector3& b) const; Vector3 operator +(const Vector3& b) const;
KRVector3 operator -(const KRVector3& b) const; Vector3 operator -(const Vector3& b) const;
KRVector3 operator +() const; Vector3 operator +() const;
KRVector3 operator -() const; Vector3 operator -() const;
KRVector3 operator *(const float v) const; Vector3 operator *(const float v) const;
KRVector3 operator /(const float v) const; Vector3 operator /(const float v) const;
KRVector3& operator +=(const KRVector3& b); Vector3& operator +=(const Vector3& b);
KRVector3& operator -=(const KRVector3& b); Vector3& operator -=(const Vector3& b);
KRVector3& operator *=(const float v); Vector3& operator *=(const float v);
KRVector3& operator /=(const float v); Vector3& operator /=(const float v);
bool operator ==(const KRVector3& b) const; bool operator ==(const Vector3& b) const;
bool operator !=(const KRVector3& b) const; bool operator !=(const Vector3& b) const;
// Comparison operators are implemented to allow insertion into sorted containers such as std::set // Comparison operators are implemented to allow insertion into sorted containers such as std::set
bool operator >(const KRVector3& b) const; bool operator >(const Vector3& b) const;
bool operator <(const KRVector3& b) const; bool operator <(const Vector3& b) const;
float& operator[](unsigned i); float& operator[](unsigned i);
float operator[](unsigned i) const; float operator[](unsigned i) const;
@@ -103,36 +104,36 @@ public:
float sqrMagnitude() const; // calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function) float sqrMagnitude() const; // calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function)
float magnitude() const; float magnitude() const;
void scale(const KRVector3 &v); void scale(const Vector3 &v);
void normalize(); void normalize();
static KRVector3 Normalize(const KRVector3 &v); static Vector3 Normalize(const Vector3 &v);
static KRVector3 Cross(const KRVector3 &v1, const KRVector3 &v2); static Vector3 Cross(const Vector3 &v1, const Vector3 &v2);
static float Dot(const KRVector3 &v1, const KRVector3 &v2); static float Dot(const Vector3 &v1, const Vector3 &v2);
static KRVector3 Min(); static Vector3 Min();
static KRVector3 Max(); static Vector3 Max();
static const KRVector3 &Zero(); static const Vector3 &Zero();
static KRVector3 One(); static Vector3 One();
static KRVector3 Forward(); static Vector3 Forward();
static KRVector3 Backward(); static Vector3 Backward();
static KRVector3 Up(); static Vector3 Up();
static KRVector3 Down(); static Vector3 Down();
static KRVector3 Left(); static Vector3 Left();
static KRVector3 Right(); static Vector3 Right();
static KRVector3 Scale(const KRVector3 &v1, const KRVector3 &v2); static Vector3 Scale(const Vector3 &v1, const Vector3 &v2);
static KRVector3 Lerp(const KRVector3 &v1, const KRVector3 &v2, float d); static Vector3 Lerp(const Vector3 &v1, const Vector3 &v2, float d);
static KRVector3 Slerp(const KRVector3 &v1, const KRVector3 &v2, float d); static Vector3 Slerp(const Vector3 &v1, const Vector3 &v2, float d);
static void OrthoNormalize(KRVector3 &normal, KRVector3 &tangent); // Gram-Schmidt Orthonormalization static void OrthoNormalize(Vector3 &normal, Vector3 &tangent); // Gram-Schmidt Orthonormalization
}; };
} // namespace kraken } // namespace kraken
namespace std { namespace std {
template<> template<>
struct hash<kraken::KRVector3> { struct hash<kraken::Vector3> {
public: public:
size_t operator()(const kraken::KRVector3 &s) const size_t operator()(const kraken::Vector3 &s) const
{ {
size_t h1 = hash<float>()(s.x); size_t h1 = hash<float>()(s.x);
size_t h2 = hash<float>()(s.y); size_t h2 = hash<float>()(s.y);

215
kraken/vector2.cpp Normal file
View File

@@ -0,0 +1,215 @@
//
// 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

170
kraken/KRVector3.cpp → kraken/vector3.cpp Executable file → Normal file
View File

@@ -1,5 +1,5 @@
// //
// KRVector3.cpp // Vector3.cpp
// KREngine // KREngine
// //
// Copyright 2012 Kearwood Gilbert. All rights reserved. // Copyright 2012 Kearwood Gilbert. All rights reserved.
@@ -32,182 +32,182 @@
#include "KREngine-common.h" #include "KREngine-common.h"
#include "public/kraken.h" #include "public/kraken.h"
const KRVector3 KRVECTOR3_ZERO(0.0f, 0.0f, 0.0f); const Vector3 Vector3_ZERO(0.0f, 0.0f, 0.0f);
//default constructor //default constructor
KRVector3::KRVector3() Vector3::Vector3()
{ {
x = 0.0f; x = 0.0f;
y = 0.0f; y = 0.0f;
z = 0.0f; z = 0.0f;
} }
KRVector3::KRVector3(const KRVector3 &v) { Vector3::Vector3(const Vector3 &v) {
x = v.x; x = v.x;
y = v.y; y = v.y;
z = v.z; z = v.z;
} }
KRVector3::KRVector3(const KRVector4 &v) { Vector3::Vector3(const KRVector4 &v) {
x = v.x; x = v.x;
y = v.y; y = v.y;
z = v.z; z = v.z;
} }
KRVector3::KRVector3(float *v) { Vector3::Vector3(float *v) {
x = v[0]; x = v[0];
y = v[1]; y = v[1];
z = v[2]; z = v[2];
} }
KRVector3::KRVector3(double *v) { Vector3::Vector3(double *v) {
x = (float)v[0]; x = (float)v[0];
y = (float)v[1]; y = (float)v[1];
z = (float)v[2]; z = (float)v[2];
} }
Vector2 KRVector3::xx() const Vector2 Vector3::xx() const
{ {
return Vector2(x,x); return Vector2(x,x);
} }
Vector2 KRVector3::xy() const Vector2 Vector3::xy() const
{ {
return Vector2(x,y); return Vector2(x,y);
} }
Vector2 KRVector3::xz() const Vector2 Vector3::xz() const
{ {
return Vector2(x,z); return Vector2(x,z);
} }
Vector2 KRVector3::yx() const Vector2 Vector3::yx() const
{ {
return Vector2(y,x); return Vector2(y,x);
} }
Vector2 KRVector3::yy() const Vector2 Vector3::yy() const
{ {
return Vector2(y,y); return Vector2(y,y);
} }
Vector2 KRVector3::yz() const Vector2 Vector3::yz() const
{ {
return Vector2(y,z); return Vector2(y,z);
} }
Vector2 KRVector3::zx() const Vector2 Vector3::zx() const
{ {
return Vector2(z,x); return Vector2(z,x);
} }
Vector2 KRVector3::zy() const Vector2 Vector3::zy() const
{ {
return Vector2(z,y); return Vector2(z,y);
} }
Vector2 KRVector3::zz() const Vector2 Vector3::zz() const
{ {
return Vector2(z,z); return Vector2(z,z);
} }
void KRVector3::xy(const Vector2 &v) void Vector3::xy(const Vector2 &v)
{ {
x = v.x; x = v.x;
y = v.y; y = v.y;
} }
void KRVector3::xz(const Vector2 &v) void Vector3::xz(const Vector2 &v)
{ {
x = v.x; x = v.x;
z = v.y; z = v.y;
} }
void KRVector3::yx(const Vector2 &v) void Vector3::yx(const Vector2 &v)
{ {
y = v.x; y = v.x;
x = v.y; x = v.y;
} }
void KRVector3::yz(const Vector2 &v) void Vector3::yz(const Vector2 &v)
{ {
y = v.x; y = v.x;
z = v.y; z = v.y;
} }
void KRVector3::zx(const Vector2 &v) void Vector3::zx(const Vector2 &v)
{ {
z = v.x; z = v.x;
x = v.y; x = v.y;
} }
void KRVector3::zy(const Vector2 &v) void Vector3::zy(const Vector2 &v)
{ {
z = v.x; z = v.x;
y = v.y; y = v.y;
} }
KRVector3 KRVector3::Min() { Vector3 Vector3::Min() {
return KRVector3(-std::numeric_limits<float>::max()); return Vector3(-std::numeric_limits<float>::max());
} }
KRVector3 KRVector3::Max() { Vector3 Vector3::Max() {
return KRVector3(std::numeric_limits<float>::max()); return Vector3(std::numeric_limits<float>::max());
} }
const KRVector3 &KRVector3::Zero() { const Vector3 &Vector3::Zero() {
return KRVECTOR3_ZERO; return Vector3_ZERO;
} }
KRVector3 KRVector3::One() { Vector3 Vector3::One() {
return KRVector3(1.0f, 1.0f, 1.0f); return Vector3(1.0f, 1.0f, 1.0f);
} }
KRVector3 KRVector3::Forward() { Vector3 Vector3::Forward() {
return KRVector3(0.0f, 0.0f, 1.0f); return Vector3(0.0f, 0.0f, 1.0f);
} }
KRVector3 KRVector3::Backward() { Vector3 Vector3::Backward() {
return KRVector3(0.0f, 0.0f, -1.0f); return Vector3(0.0f, 0.0f, -1.0f);
} }
KRVector3 KRVector3::Up() { Vector3 Vector3::Up() {
return KRVector3(0.0f, 1.0f, 0.0f); return Vector3(0.0f, 1.0f, 0.0f);
} }
KRVector3 KRVector3::Down() { Vector3 Vector3::Down() {
return KRVector3(0.0f, -1.0f, 0.0f); return Vector3(0.0f, -1.0f, 0.0f);
} }
KRVector3 KRVector3::Left() { Vector3 Vector3::Left() {
return KRVector3(-1.0f, 0.0f, 0.0f); return Vector3(-1.0f, 0.0f, 0.0f);
} }
KRVector3 KRVector3::Right() { Vector3 Vector3::Right() {
return KRVector3(1.0f, 0.0f, 0.0f); return Vector3(1.0f, 0.0f, 0.0f);
} }
void KRVector3::scale(const KRVector3 &v) void Vector3::scale(const Vector3 &v)
{ {
x *= v.x; x *= v.x;
y *= v.y; y *= v.y;
z *= v.z; z *= v.z;
} }
KRVector3 KRVector3::Scale(const KRVector3 &v1, const KRVector3 &v2) Vector3 Vector3::Scale(const Vector3 &v1, const Vector3 &v2)
{ {
return KRVector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z); return Vector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z);
} }
KRVector3 KRVector3::Lerp(const KRVector3 &v1, const KRVector3 &v2, float d) { Vector3 Vector3::Lerp(const Vector3 &v1, const Vector3 &v2, float d) {
return v1 + (v2 - v1) * d; return v1 + (v2 - v1) * d;
} }
KRVector3 KRVector3::Slerp(const KRVector3 &v1, const KRVector3 &v2, float 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/ // From: http://keithmaggio.wordpress.com/2011/02/15/math-magician-lerp-slerp-and-nlerp/
// Dot product - the cosine of the angle between 2 vectors. // Dot product - the cosine of the angle between 2 vectors.
float dot = KRVector3::Dot(v1, v2); float dot = Vector3::Dot(v1, v2);
// Clamp it to be in the range of Acos() // Clamp it to be in the range of Acos()
if(dot < -1.0f) dot = -1.0f; if(dot < -1.0f) dot = -1.0f;
if(dot > 1.0f) dot = 1.0f; if(dot > 1.0f) dot = 1.0f;
@@ -215,74 +215,74 @@ KRVector3 KRVector3::Slerp(const KRVector3 &v1, const KRVector3 &v2, float d) {
// And multiplying that by percent returns the angle between // And multiplying that by percent returns the angle between
// start and the final result. // start and the final result.
float theta = acos(dot)*d; float theta = acos(dot)*d;
KRVector3 RelativeVec = v2 - v1*dot; Vector3 RelativeVec = v2 - v1*dot;
RelativeVec.normalize(); // Orthonormal basis RelativeVec.normalize(); // Orthonormal basis
// The final result. // The final result.
return ((v1*cos(theta)) + (RelativeVec*sin(theta))); return ((v1*cos(theta)) + (RelativeVec*sin(theta)));
} }
void KRVector3::OrthoNormalize(KRVector3 &normal, KRVector3 &tangent) { void Vector3::OrthoNormalize(Vector3 &normal, Vector3 &tangent) {
// Gram-Schmidt Orthonormalization // Gram-Schmidt Orthonormalization
normal.normalize(); normal.normalize();
KRVector3 proj = normal * Dot(tangent, normal); Vector3 proj = normal * Dot(tangent, normal);
tangent = tangent - proj; tangent = tangent - proj;
tangent.normalize(); tangent.normalize();
} }
KRVector3::KRVector3(float v) { Vector3::Vector3(float v) {
x = v; x = v;
y = v; y = v;
z = v; z = v;
} }
KRVector3::KRVector3(float X, float Y, float Z) Vector3::Vector3(float X, float Y, float Z)
{ {
x = X; x = X;
y = Y; y = Y;
z = Z; z = Z;
} }
KRVector3::~KRVector3() Vector3::~Vector3()
{ {
} }
KRVector3& KRVector3::operator =(const KRVector3& b) { Vector3& Vector3::operator =(const Vector3& b) {
x = b.x; x = b.x;
y = b.y; y = b.y;
z = b.z; z = b.z;
return *this; return *this;
} }
KRVector3& KRVector3::operator =(const KRVector4 &b) { Vector3& Vector3::operator =(const KRVector4 &b) {
x = b.x; x = b.x;
y = b.y; y = b.y;
z = b.z; z = b.z;
return *this; return *this;
} }
KRVector3 KRVector3::operator +(const KRVector3& b) const { Vector3 Vector3::operator +(const Vector3& b) const {
return KRVector3(x + b.x, y + b.y, z + b.z); return Vector3(x + b.x, y + b.y, z + b.z);
} }
KRVector3 KRVector3::operator -(const KRVector3& b) const { Vector3 Vector3::operator -(const Vector3& b) const {
return KRVector3(x - b.x, y - b.y, z - b.z); return Vector3(x - b.x, y - b.y, z - b.z);
} }
KRVector3 KRVector3::operator +() const { Vector3 Vector3::operator +() const {
return *this; return *this;
} }
KRVector3 KRVector3::operator -() const { Vector3 Vector3::operator -() const {
return KRVector3(-x, -y, -z); return Vector3(-x, -y, -z);
} }
KRVector3 KRVector3::operator *(const float v) const { Vector3 Vector3::operator *(const float v) const {
return KRVector3(x * v, y * v, z * v); return Vector3(x * v, y * v, z * v);
} }
KRVector3 KRVector3::operator /(const float v) const { Vector3 Vector3::operator /(const float v) const {
float inv_v = 1.0f / v; float inv_v = 1.0f / v;
return KRVector3(x * inv_v, y * inv_v, z * inv_v); return Vector3(x * inv_v, y * inv_v, z * inv_v);
} }
KRVector3& KRVector3::operator +=(const KRVector3& b) { Vector3& Vector3::operator +=(const Vector3& b) {
x += b.x; x += b.x;
y += b.y; y += b.y;
z += b.z; z += b.z;
@@ -290,7 +290,7 @@ KRVector3& KRVector3::operator +=(const KRVector3& b) {
return *this; return *this;
} }
KRVector3& KRVector3::operator -=(const KRVector3& b) { Vector3& Vector3::operator -=(const Vector3& b) {
x -= b.x; x -= b.x;
y -= b.y; y -= b.y;
z -= b.z; z -= b.z;
@@ -298,7 +298,7 @@ KRVector3& KRVector3::operator -=(const KRVector3& b) {
return *this; return *this;
} }
KRVector3& KRVector3::operator *=(const float v) { Vector3& Vector3::operator *=(const float v) {
x *= v; x *= v;
y *= v; y *= v;
z *= v; z *= v;
@@ -306,7 +306,7 @@ KRVector3& KRVector3::operator *=(const float v) {
return *this; return *this;
} }
KRVector3& KRVector3::operator /=(const float v) { Vector3& Vector3::operator /=(const float v) {
float inv_v = 1.0f / v; float inv_v = 1.0f / v;
x *= inv_v; x *= inv_v;
y *= inv_v; y *= inv_v;
@@ -315,15 +315,15 @@ KRVector3& KRVector3::operator /=(const float v) {
return *this; return *this;
} }
bool KRVector3::operator ==(const KRVector3& b) const { bool Vector3::operator ==(const Vector3& b) const {
return x == b.x && y == b.y && z == b.z; return x == b.x && y == b.y && z == b.z;
} }
bool KRVector3::operator !=(const KRVector3& b) const { bool Vector3::operator !=(const Vector3& b) const {
return x != b.x || y != b.y || z != b.z; return x != b.x || y != b.y || z != b.z;
} }
float& KRVector3::operator[](unsigned i) { float& Vector3::operator[](unsigned i) {
switch(i) { switch(i) {
case 0: case 0:
return x; return x;
@@ -335,7 +335,7 @@ float& KRVector3::operator[](unsigned i) {
} }
} }
float KRVector3::operator[](unsigned i) const { float Vector3::operator[](unsigned i) const {
switch(i) { switch(i) {
case 0: case 0:
return x; return x;
@@ -347,37 +347,37 @@ float KRVector3::operator[](unsigned i) const {
} }
} }
float KRVector3::sqrMagnitude() const { float Vector3::sqrMagnitude() const {
// calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function) // 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; return x * x + y * y + z * z;
} }
float KRVector3::magnitude() const { float Vector3::magnitude() const {
return sqrtf(x * x + y * y + z * z); return sqrtf(x * x + y * y + z * z);
} }
void KRVector3::normalize() { void Vector3::normalize() {
float inv_magnitude = 1.0f / sqrtf(x * x + y * y + z * z); float inv_magnitude = 1.0f / sqrtf(x * x + y * y + z * z);
x *= inv_magnitude; x *= inv_magnitude;
y *= inv_magnitude; y *= inv_magnitude;
z *= inv_magnitude; z *= inv_magnitude;
} }
KRVector3 KRVector3::Normalize(const KRVector3 &v) { Vector3 Vector3::Normalize(const Vector3 &v) {
float inv_magnitude = 1.0f / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); float inv_magnitude = 1.0f / sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
return KRVector3(v.x * inv_magnitude, v.y * inv_magnitude, v.z * inv_magnitude); return Vector3(v.x * inv_magnitude, v.y * inv_magnitude, v.z * inv_magnitude);
} }
KRVector3 KRVector3::Cross(const KRVector3 &v1, const KRVector3 &v2) { Vector3 Vector3::Cross(const Vector3 &v1, const Vector3 &v2) {
return KRVector3(v1.y * v2.z - v1.z * v2.y, return Vector3(v1.y * v2.z - v1.z * v2.y,
v1.z * v2.x - v1.x * v2.z, v1.z * v2.x - v1.x * v2.z,
v1.x * v2.y - v1.y * v2.x); v1.x * v2.y - v1.y * v2.x);
} }
float KRVector3::Dot(const KRVector3 &v1, const KRVector3 &v2) { float Vector3::Dot(const Vector3 &v1, const Vector3 &v2) {
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
} }
bool KRVector3::operator >(const KRVector3& b) const bool Vector3::operator >(const Vector3& b) const
{ {
// Comparison operators are implemented to allow insertion into sorted containers such as std::set // Comparison operators are implemented to allow insertion into sorted containers such as std::set
if(x > b.x) { if(x > b.x) {
@@ -395,7 +395,7 @@ bool KRVector3::operator >(const KRVector3& b) const
} }
} }
bool KRVector3::operator <(const KRVector3& b) const bool Vector3::operator <(const Vector3& b) const
{ {
// Comparison operators are implemented to allow insertion into sorted containers such as std::set // Comparison operators are implemented to allow insertion into sorted containers such as std::set
if(x < b.x) { if(x < b.x) {

View File

@@ -196,7 +196,7 @@
<ClCompile Include="..\kraken\KRUnknown.cpp" /> <ClCompile Include="..\kraken\KRUnknown.cpp" />
<ClCompile Include="..\kraken\KRUnknownManager.cpp" /> <ClCompile Include="..\kraken\KRUnknownManager.cpp" />
<ClCompile Include="..\kraken\vector2.cpp" /> <ClCompile Include="..\kraken\vector2.cpp" />
<ClCompile Include="..\kraken\KRVector3.cpp" /> <ClCompile Include="..\kraken\vector3.cpp" />
<ClCompile Include="..\kraken\KRVector4.cpp" /> <ClCompile Include="..\kraken\KRVector4.cpp" />
<ClCompile Include="..\kraken\KRViewport.cpp" /> <ClCompile Include="..\kraken\KRViewport.cpp" />
</ItemGroup> </ItemGroup>
@@ -278,7 +278,7 @@
<ClInclude Include="..\kraken\public\KRQuaternion.h" /> <ClInclude Include="..\kraken\public\KRQuaternion.h" />
<ClInclude Include="..\kraken\public\KRTriangle3.h" /> <ClInclude Include="..\kraken\public\KRTriangle3.h" />
<ClInclude Include="..\kraken\public\vector2.h" /> <ClInclude Include="..\kraken\public\vector2.h" />
<ClInclude Include="..\kraken\public\KRVector3.h" /> <ClInclude Include="..\kraken\public\vector3.h" />
<ClInclude Include="..\kraken\public\KRVector4.h" /> <ClInclude Include="..\kraken\public\KRVector4.h" />
<ClInclude Include="3rdparty\glew\glew-1.13.0\include\GL\glew.h" /> <ClInclude Include="3rdparty\glew\glew-1.13.0\include\GL\glew.h" />
<ClInclude Include="3rdparty\glew\glew-1.13.0\include\GL\glxew.h" /> <ClInclude Include="3rdparty\glew\glew-1.13.0\include\GL\glxew.h" />

View File

@@ -30,9 +30,6 @@
<ClCompile Include="..\3rdparty\forsyth\forsyth.cpp"> <ClCompile Include="..\3rdparty\forsyth\forsyth.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\kraken\KRVector3.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\kraken\KRVector4.cpp"> <ClCompile Include="..\kraken\KRVector4.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
@@ -252,6 +249,9 @@
<ClCompile Include="..\kraken\vector2.cpp"> <ClCompile Include="..\kraken\vector2.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\kraken\vector3.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\3rdparty\tinyxml2\tinyxml2.h"> <ClInclude Include="..\3rdparty\tinyxml2\tinyxml2.h">
@@ -479,9 +479,6 @@
<ClInclude Include="..\kraken\public\KRMat4.h"> <ClInclude Include="..\kraken\public\KRMat4.h">
<Filter>Header Files\public</Filter> <Filter>Header Files\public</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\kraken\public\KRVector3.h">
<Filter>Header Files\public</Filter>
</ClInclude>
<ClInclude Include="..\kraken\public\KRVector4.h"> <ClInclude Include="..\kraken\public\KRVector4.h">
<Filter>Header Files\public</Filter> <Filter>Header Files\public</Filter>
</ClInclude> </ClInclude>
@@ -500,5 +497,8 @@
<ClInclude Include="..\kraken\public\vector2.h"> <ClInclude Include="..\kraken\public\vector2.h">
<Filter>Header Files\public</Filter> <Filter>Header Files\public</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\kraken\public\vector3.h">
<Filter>Header Files\public</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>