Very early KRWorldBuilder scaffolding in progress.

New KRVector3 math functions

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4058
This commit is contained in:
kearwood
2012-06-07 17:19:29 +00:00
parent 0b76fadeef
commit cad53fcf69
15 changed files with 545 additions and 164 deletions

View File

@@ -43,6 +43,16 @@
E46DBE801512AF4600D59F86 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E491016413C99B9E0098455B /* Foundation.framework */; };
E46DBE811512AFE600D59F86 /* KRMesh.h in Headers */ = {isa = PBXBuildFile; fileRef = E49E79FC15126146009CF99C /* KRMesh.h */; settings = {ATTRIBUTES = (Public, ); }; };
E46DBE851512B9FA00D59F86 /* KREngine-common.h in Headers */ = {isa = PBXBuildFile; fileRef = E46DBE841512B9E200D59F86 /* KREngine-common.h */; settings = {ATTRIBUTES = (Public, ); }; };
E46F4A00155DF46700CCF8B8 /* KRWorld.h in Headers */ = {isa = PBXBuildFile; fileRef = E46F49FF155DF46700CCF8B8 /* KRWorld.h */; };
E46F4A01155DF46700CCF8B8 /* KRWorld.h in Headers */ = {isa = PBXBuildFile; fileRef = E46F49FF155DF46700CCF8B8 /* KRWorld.h */; settings = {ATTRIBUTES = (Public, ); }; };
E46F4A04155DF47C00CCF8B8 /* KRWorld.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46F4A03155DF47C00CCF8B8 /* KRWorld.cpp */; };
E46F4A05155DF47C00CCF8B8 /* KRWorld.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46F4A03155DF47C00CCF8B8 /* KRWorld.cpp */; };
E46F4A09155DF6E400CCF8B8 /* KRWorld.cpp in Headers */ = {isa = PBXBuildFile; fileRef = E46F4A03155DF47C00CCF8B8 /* KRWorld.cpp */; settings = {ATTRIBUTES = (Public, ); }; };
E46F4A0B155E002100CCF8B8 /* KRDataBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = E46F4A0A155E002100CCF8B8 /* KRDataBlock.h */; };
E46F4A0C155E002100CCF8B8 /* KRDataBlock.h in Headers */ = {isa = PBXBuildFile; fileRef = E46F4A0A155E002100CCF8B8 /* KRDataBlock.h */; };
E46F4A0E155E003000CCF8B8 /* KRDataBlock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */; };
E46F4A0F155E003000CCF8B8 /* KRDataBlock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */; };
E46F4A10155E004100CCF8B8 /* KRDataBlock.cpp in Headers */ = {isa = PBXBuildFile; fileRef = E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */; settings = {ATTRIBUTES = (Public, ); }; };
E47C25A213F4F65A00FF4370 /* KRShaderManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E47C25A113F4F65A00FF4370 /* KRShaderManager.h */; };
E47C25A513F4F66F00FF4370 /* KRShader.h in Headers */ = {isa = PBXBuildFile; fileRef = E47C25A413F4F66F00FF4370 /* KRShader.h */; };
E47C25A713F4F6AB00FF4370 /* KRShaderManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */; };
@@ -170,6 +180,10 @@
E46C214A15364DEC009CABF3 /* KRSceneManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRSceneManager.cpp; path = Classes/KRSceneManager.cpp; sourceTree = "<group>"; };
E46DBE7D1512AD4900D59F86 /* OpenGL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGL.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenGL.framework; sourceTree = DEVELOPER_DIR; };
E46DBE841512B9E200D59F86 /* KREngine-common.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "KREngine-common.h"; path = "Classes/KREngine-common.h"; sourceTree = "<group>"; };
E46F49FF155DF46700CCF8B8 /* KRWorld.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRWorld.h; path = Classes/KRWorld.h; sourceTree = "<group>"; };
E46F4A03155DF47C00CCF8B8 /* KRWorld.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRWorld.cpp; path = Classes/KRWorld.cpp; sourceTree = "<group>"; };
E46F4A0A155E002100CCF8B8 /* KRDataBlock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRDataBlock.h; path = Classes/KRDataBlock.h; sourceTree = "<group>"; };
E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRDataBlock.cpp; path = Classes/KRDataBlock.cpp; sourceTree = "<group>"; };
E47C25A113F4F65A00FF4370 /* KRShaderManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRShaderManager.h; path = Classes/KRShaderManager.h; sourceTree = "<group>"; };
E47C25A413F4F66F00FF4370 /* KRShader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRShader.h; path = Classes/KRShader.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRShaderManager.cpp; path = Classes/KRShaderManager.cpp; sourceTree = "<group>"; };
@@ -438,6 +452,10 @@
E46C214A15364DEC009CABF3 /* KRSceneManager.cpp */,
E48C696E15374F5A00232E28 /* KRContext.h */,
E48C697115374F7E00232E28 /* KRContext.cpp */,
E46F49FF155DF46700CCF8B8 /* KRWorld.h */,
E46F4A0A155E002100CCF8B8 /* KRDataBlock.h */,
E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */,
E46F4A03155DF47C00CCF8B8 /* KRWorld.cpp */,
);
name = Classes;
sourceTree = "<group>";
@@ -515,6 +533,8 @@
E4F975321536220900FD60B2 /* KRNode.h in Headers */,
E46C214715364BC8009CABF3 /* tinyxml2.h in Headers */,
E48C696F15374F5B00232E28 /* KRContext.h in Headers */,
E46F4A00155DF46700CCF8B8 /* KRWorld.h in Headers */,
E46F4A0B155E002100CCF8B8 /* KRDataBlock.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -542,13 +562,17 @@
E461A153152E54B500F2044A /* KRLight.h in Headers */,
E4F97552153633EF00FD60B2 /* KRMaterialManager.h in Headers */,
E461A176152E5C5600F2044A /* KRPointLight.h in Headers */,
E46F4A09155DF6E400CCF8B8 /* KRWorld.cpp in Headers */,
E4F975541536340400FD60B2 /* KRTexture.h in Headers */,
E46F4A01155DF46700CCF8B8 /* KRWorld.h in Headers */,
E48C697015374F5B00232E28 /* KRContext.h in Headers */,
E46F4A10155E004100CCF8B8 /* KRDataBlock.cpp in Headers */,
E4D13365153767FF0070068C /* KRShaderManager.h in Headers */,
E461A15D152E563100F2044A /* KRDirectionalLight.h in Headers */,
E461A169152E570700F2044A /* KRSpotLight.h in Headers */,
E46C214815364BC8009CABF3 /* tinyxml2.h in Headers */,
E46A6B701559EF0A000DBD37 /* KRResource+blend.h in Headers */,
E46F4A0C155E002100CCF8B8 /* KRDataBlock.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -665,6 +689,8 @@
E4D133BC1538F7560070068C /* light_directional.vsh in Sources */,
E4A9DEBE154120C4009DF363 /* light_point.fsh in Sources */,
E4A9DEC1154120E8009DF363 /* light_point.vsh in Sources */,
E46F4A04155DF47C00CCF8B8 /* KRWorld.cpp in Sources */,
E46F4A0E155E003000CCF8B8 /* KRDataBlock.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -700,6 +726,8 @@
E46C214C15364DEC009CABF3 /* KRSceneManager.cpp in Sources */,
E48C697315374F7E00232E28 /* KRContext.cpp in Sources */,
E46A6B6D1559E97D000DBD37 /* KRResource+blend.cpp in Sources */,
E46F4A05155DF47C00CCF8B8 /* KRWorld.cpp in Sources */,
E46F4A0F155E003000CCF8B8 /* KRDataBlock.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -0,0 +1,42 @@
//
// KRDataBlock.cpp
// KREngine
//
// Created by Kearwood Gilbert on 12-05-11.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
//
#include <iostream>
#include "KRDataBlock.h"
KRDataBlock::KRDataBlock() {
m_data = NULL;
m_data_size = 0;
}
KRDataBlock::~KRDataBlock() {
if(m_data) {
free(m_data);
}
}
void *KRDataBlock::getData() {
return m_data;
}
int KRDataBlock::getSize() {
return m_data_size;
}
void KRDataBlock::append(void *data, int size) {
if(m_data == NULL) {
m_data = malloc(size);
memcpy(m_data, data, size);
m_data_size = size;
} else {
m_data = realloc(m_data, m_data_size + size);
memcpy((unsigned char *)m_data + size, data, size);
m_data_size += size;
}
}

View File

@@ -0,0 +1,26 @@
//
// KRDataBlock.h
// KREngine
//
// Created by Kearwood Gilbert on 12-05-11.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
//
#ifndef KREngine_KRDataBlock_h
#define KREngine_KRDataBlock_h
class KRDataBlock {
public:
KRDataBlock();
~KRDataBlock();
void append(void *data, int size);
void *getData();
int getSize();
private:
void *m_data;
int m_data_size;
};
#endif

View File

@@ -39,6 +39,67 @@ KRVector3::KRVector3()
z = 0.0f;
}
KRVector3 KRVector3::ZeroVector() {
return KRVector3(0.0f, 0.0f, 0.0f);
}
KRVector3 KRVector3::OneVector() {
return KRVector3(1.0f, 1.0f, 1.0f);
}
KRVector3 KRVector3::ForwardVector() {
return KRVector3(0.0f, 0.0f, 1.0f);
}
KRVector3 KRVector3::BackwardVector() {
return KRVector3(0.0f, 0.0f, -1.0f);
}
KRVector3 KRVector3::UpVector() {
return KRVector3(0.0f, 1.0f, 0.0f);
}
KRVector3 KRVector3::DownVector() {
return KRVector3(0.0f, -1.0f, 0.0f);
}
KRVector3 KRVector3::LeftVector() {
return KRVector3(-1.0f, 0.0f, 0.0f);
}
KRVector3 KRVector3::RightVector() {
return KRVector3(1.0f, 0.0f, 0.0f);
}
KRVector3 KRVector3::Lerp(const KRVector3 &v1, const KRVector3 &v2, float d) {
return v1 + (v2 - v1) * d;
}
KRVector3 KRVector3::Slerp(const KRVector3 &v1, const KRVector3 &v2, float d) {
// From: http://keithmaggio.wordpress.com/2011/02/15/math-magician-lerp-slerp-and-nlerp/
// Dot product - the cosine of the angle between 2 vectors.
float dot = KRVector3::Dot(v1, v2);
// Clamp it to be in the range of Acos()
if(dot < -1.0f) dot = -1.0f;
if(dot > 1.0f) dot = 1.0f;
// Acos(dot) returns the angle between start and end,
// And multiplying that by percent returns the angle between
// start and the final result.
float theta = acos(dot)*d;
KRVector3 RelativeVec = v2 - v1*dot;
RelativeVec.normalize(); // Orthonormal basis
// The final result.
return ((v1*cos(theta)) + (RelativeVec*sin(theta)));
}
void KRVector3::OrthoNormalize(KRVector3 &normal, KRVector3 &tangent) {
// Gram-Schmidt Orthonormalization
normal.normalize();
KRVector3 proj = normal * Dot(tangent, normal);
tangent = tangent - proj;
tangent.normalize();
}
KRVector3::KRVector3(float v) {
x = v;
y = v;
@@ -73,7 +134,12 @@ KRVector3::~KRVector3()
//calculate and return the magnitude of this vector
float KRVector3::GetMagnitude()
{
return sqrtf(x * x + y * y + z * z);
return sqrtf(GetSqrMagnitude());
}
float KRVector3::GetSqrMagnitude()
{
return x * x + y * y + z * z;
}
//multiply this vector by a scalar
@@ -111,6 +177,10 @@ void KRVector3::normalize()
z /= magnitude;
}
float KRVector3::Dot(const KRVector3 &v1, const KRVector3 &v2) {
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}
//calculate and return dot product
float KRVector3::dot(const KRVector3 &vec) const
{

View File

@@ -48,14 +48,30 @@ public:
KRVector3();
~KRVector3();
static KRVector3 ZeroVector();
static KRVector3 OneVector();
static KRVector3 ForwardVector();
static KRVector3 BackwardVector();
static KRVector3 UpVector();
static KRVector3 DownVector();
static KRVector3 LeftVector();
static KRVector3 RightVector();
static KRVector3 Lerp(const KRVector3 &v1, const KRVector3 &v2, float d);
static KRVector3 Slerp(const KRVector3 &v1, const KRVector3 &v2, float d);
static float Dot(const KRVector3 &v1, const KRVector3 &v2);
static void OrthoNormalize(KRVector3 &normal, KRVector3 &tangent); // Gram-Schmidt Orthonormalization
KRVector3(const KRVector3& p);
KRVector3& operator = ( const KRVector3& p );
friend bool operator== (KRVector3 &v1, KRVector3 &v2);
friend bool operator!= (KRVector3 &v1, KRVector3 &v2);
//calculate and return the magnitude of this vector
// calculate and return the magnitude of this vector
float GetMagnitude();
// calculate the square of the magnitude (useful for comparison of magnitudes without the cost of a sqrt() function used in GetMagnitude
float GetSqrMagnitude();
//multiply this vector by a scalar
KRVector3 operator*(float num) const;
@@ -70,6 +86,8 @@ public:
//normalize this vector
void normalize();
//calculate and return dot product
float dot(const KRVector3 &vec) const;

View File

@@ -0,0 +1,29 @@
//
// KRWorld.cpp
// KREngine
//
// Created by Kearwood Gilbert on 12-05-11.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
//
#include <iostream>
#include "KRWorld.h"
#include "KRDataBlock.h"
KRWorld::KRWorld() {
}
KRWorld::~KRWorld() {
}
void KRWorld::Load(void *data, int data_size) {
}
KRDataBlock *KRWorld::Save() {
KRDataBlock *block = new KRDataBlock();
return block;
}

View File

@@ -0,0 +1,24 @@
//
// KRWorld.h
// KREngine
//
// Created by Kearwood Gilbert on 12-05-11.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
//
#ifndef KREngine_KRWorld_h
#define KREngine_KRWorld_h
class KRDataBlock;
class KRWorld {
public:
KRWorld();
~KRWorld();
void Load(void *data, int data_size);
KRDataBlock *Save();
private:
};
#endif

View File

@@ -31,5 +31,5 @@ uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying the mo
void main()
{
gl_Position = mvp_matrix * vertex_position;
gl_Position.z = max(gl_Position.z / gl_Position.w, 0.0) * gl_Position.w;
gl_Position.z = max(gl_Position.z / gl_Position.w, 0.00) * gl_Position.w;
}