* Fix many style issues. Quaternion and Vector3 still show some of their foreign
origin. Yes.. shame on me, i had even imported their non unix line endings :) Will make them BCitizens soon. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33890 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
ae762f316d
commit
3904801c31
@ -15,43 +15,47 @@
|
||||
|
||||
|
||||
float
|
||||
MathUtils::EaseInOutCubic(float t /*time*/, float b /*begin*/, float c /*distance*/, float d /*duration*/)
|
||||
MathUtils::EaseInOutCubic(float time, float start, float distance,
|
||||
float duration)
|
||||
{
|
||||
t /= d / 2.0;
|
||||
if (t < 1.0)
|
||||
return c / 2.0 * t * t * t + b;
|
||||
t -= 2.0;
|
||||
return c / 2.0 * (t * t * t + 2.0) + b;
|
||||
time /= duration / 2.0;
|
||||
if (time < 1.0)
|
||||
return distance / 2.0 * time * time * time + start;
|
||||
time -= 2.0;
|
||||
return distance / 2.0 * (time * time * time + 2.0) + start;
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
MathUtils::EaseInOutQuart(float t /*time*/, float b /*begin*/, float c /*distance*/, float d /*duration*/)
|
||||
MathUtils::EaseInOutQuart(float time, float start, float distance,
|
||||
float duration)
|
||||
{
|
||||
t /= d / 2;
|
||||
time /= duration / 2;
|
||||
|
||||
if (t < 1)
|
||||
return c / 2 * t * t * t * t + b;
|
||||
if (time < 1)
|
||||
return distance / 2 * time * time * time * time + start;
|
||||
|
||||
t -= 2;
|
||||
time -= 2;
|
||||
|
||||
return -c / 2 * (t * t * t * t - 2) + b;
|
||||
return -distance / 2 * (time * time * time * time - 2) + start;
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
MathUtils::EaseInOutQuint(float t /*time*/, float b /*begin*/, float c /*distance*/, float d /*duration*/)
|
||||
MathUtils::EaseInOutQuint(float time, float start, float distance,
|
||||
float duration)
|
||||
{
|
||||
t /= d / 2;
|
||||
if (t < 1)
|
||||
return c / 2 * t * t * t * t * t + b;
|
||||
t -= 2;
|
||||
return c / 2 *(t * t * t * t * t + 2) + b;
|
||||
time /= duration / 2;
|
||||
if (time < 1)
|
||||
return distance / 2 * time * time * time * time * time + start;
|
||||
time -= 2;
|
||||
return distance / 2 *(time * time * time * time * time + 2) + start;
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
MathUtils::EaseInOutSine(float t /*time*/, float b /*begin*/, float c /*distance*/, float d /*duration*/)
|
||||
MathUtils::EaseInOutSine(float time, float start, float distance,
|
||||
float duration)
|
||||
{
|
||||
return -c / 2 * (cos(3.14159 * t / d) - 1) + b;
|
||||
return -distance / 2 * (cos(3.14159 * time / distance) - 1) + start;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Copyright 2009, Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
@ -11,11 +11,15 @@
|
||||
|
||||
class MathUtils
|
||||
{
|
||||
public:
|
||||
static float EaseInOutCubic(float time, float begin, float distance, float duration);
|
||||
static float EaseInOutQuart(float time, float begin, float distance, float duration);
|
||||
static float EaseInOutQuint(float time, float begin, float distance, float duration);
|
||||
static float EaseInOutSine(float time, float begin, float distance, float duration);
|
||||
public:
|
||||
static float EaseInOutCubic(float time, float begin, float distance,
|
||||
float duration);
|
||||
static float EaseInOutQuart(float time, float begin, float distance,
|
||||
float duration);
|
||||
static float EaseInOutQuint(float time, float begin, float distance,
|
||||
float duration);
|
||||
static float EaseInOutSine(float time, float begin, float distance,
|
||||
float duration);
|
||||
};
|
||||
|
||||
#endif /* _MATH_UTILS_H */
|
||||
|
@ -76,9 +76,8 @@ MeshInstance::Render()
|
||||
glBindTexture(GL_TEXTURE_2D, fTextureReference->Id());
|
||||
|
||||
int lastVertexCount = 0;
|
||||
//int batchCount = 0;
|
||||
|
||||
for(uint32 i = 0; i < fMeshReference->FaceCount(); i++) {
|
||||
for (uint32 i = 0; i < fMeshReference->FaceCount(); i++) {
|
||||
|
||||
const Face& face = fMeshReference->GetFace(i);
|
||||
|
||||
@ -91,8 +90,6 @@ MeshInstance::Render()
|
||||
glBegin(GL_TRIANGLES);
|
||||
else
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
//batchCount++;
|
||||
}
|
||||
|
||||
// calculate normal
|
||||
@ -144,11 +141,10 @@ MeshInstance::Render()
|
||||
lastVertexCount = face.vertexCount;
|
||||
}
|
||||
glEnd();
|
||||
//printf("batchCount %d\n", batchCount);
|
||||
|
||||
if (fDrawNormals) {
|
||||
glBegin(GL_LINES);
|
||||
for(uint32 i = 0; i < fMeshReference->FaceCount(); i++) {
|
||||
for (uint32 i = 0; i < fMeshReference->FaceCount(); i++) {
|
||||
|
||||
const Face& face = fMeshReference->GetFace(i);
|
||||
|
||||
@ -174,7 +170,7 @@ MeshInstance::Render()
|
||||
|
||||
glVertex3f(g.x(), g.y(), g.z());
|
||||
glVertex3f(h.x(), h.y(), h.z());
|
||||
}
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
@ -1,407 +1,416 @@
|
||||
/*
|
||||
* Copyright 2008 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Alexandre Deckner
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* This is a refactored and stripped down version of bullet-2.66 src\LinearMath\btQuaternion.h
|
||||
* The dependancies on base class btQuadWord have been removed for simplification.
|
||||
* Added gl matrix conversion method.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#ifndef __QUATERNION_H__
|
||||
#define __QUATERNION_H__
|
||||
|
||||
#include "Vector3.h"
|
||||
#include <SupportDefs.h> //pout FLT_EPSILON
|
||||
|
||||
class Quaternion {
|
||||
protected:
|
||||
float m_x;
|
||||
float m_y;
|
||||
float m_z;
|
||||
float m_w;
|
||||
public:
|
||||
Quaternion() {}
|
||||
|
||||
Quaternion(const Quaternion& q)
|
||||
{
|
||||
*((Quaternion*)this) = q;
|
||||
}
|
||||
|
||||
Quaternion(const float& x, const float& y, const float& z,const float& w)
|
||||
{
|
||||
m_x = x, m_y = y, m_z = z, m_w = w;
|
||||
}
|
||||
|
||||
Quaternion(const Vector3& axis, const float& angle)
|
||||
{
|
||||
setRotation(axis, angle);
|
||||
}
|
||||
|
||||
Quaternion(const float& yaw, const float& pitch, const float& roll)
|
||||
{
|
||||
setEuler(yaw, pitch, roll);
|
||||
}
|
||||
|
||||
inline const float& x() const { return m_x; }
|
||||
|
||||
|
||||
inline const float& y() const { return m_y; }
|
||||
|
||||
|
||||
inline const float& z() const { return m_z; }
|
||||
|
||||
|
||||
inline const float& w() const { return m_w; }
|
||||
|
||||
|
||||
void setValue(const float& x, const float& y, const float& z)
|
||||
{
|
||||
m_x=x;
|
||||
m_y=y;
|
||||
m_z=z;
|
||||
m_w = 0.f;
|
||||
}
|
||||
|
||||
|
||||
void setValue(const float& x, const float& y, const float& z,const float& w)
|
||||
{
|
||||
m_x=x;
|
||||
m_y=y;
|
||||
m_z=z;
|
||||
m_w=w;
|
||||
}
|
||||
|
||||
|
||||
void setRotation(const Vector3& axis, const float& angle)
|
||||
{
|
||||
float d = axis.length();
|
||||
assert(d != 0.0f);
|
||||
float s = sin(angle * 0.5f) / d;
|
||||
setValue(axis.x() * s, axis.y() * s, axis.z() * s,
|
||||
cos(angle * 0.5f));
|
||||
}
|
||||
|
||||
|
||||
void setEuler(const float& yaw, const float& pitch, const float& roll)
|
||||
{
|
||||
float halfYaw = yaw * 0.5f;
|
||||
float halfPitch = pitch * 0.5f;
|
||||
float halfRoll = roll * 0.5f;
|
||||
float cosYaw = cos(halfYaw);
|
||||
float sinYaw = sin(halfYaw);
|
||||
float cosPitch = cos(halfPitch);
|
||||
float sinPitch = sin(halfPitch);
|
||||
float cosRoll = cos(halfRoll);
|
||||
float sinRoll = sin(halfRoll);
|
||||
setValue(cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw,
|
||||
cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw,
|
||||
sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw,
|
||||
cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw);
|
||||
}
|
||||
|
||||
|
||||
Quaternion& operator+=(const Quaternion& q)
|
||||
{
|
||||
m_x += q.x(); m_y += q.y(); m_z += q.z(); m_w += q.m_w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Quaternion& operator-=(const Quaternion& q)
|
||||
{
|
||||
m_x -= q.x(); m_y -= q.y(); m_z -= q.z(); m_w -= q.m_w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Quaternion& operator*=(const float& s)
|
||||
{
|
||||
m_x *= s; m_y *= s; m_z *= s; m_w *= s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Quaternion& operator*=(const Quaternion& q)
|
||||
{
|
||||
setValue(m_w * q.x() + m_x * q.m_w + m_y * q.z() - m_z * q.y(),
|
||||
m_w * q.y() + m_y * q.m_w + m_z * q.x() - m_x * q.z(),
|
||||
m_w * q.z() + m_z * q.m_w + m_x * q.y() - m_y * q.x(),
|
||||
m_w * q.m_w - m_x * q.x() - m_y * q.y() - m_z * q.z());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
float dot(const Quaternion& q) const
|
||||
{
|
||||
return m_x * q.x() + m_y * q.y() + m_z * q.z() + m_w * q.m_w;
|
||||
}
|
||||
|
||||
|
||||
float length2() const
|
||||
{
|
||||
return dot(*this);
|
||||
}
|
||||
|
||||
|
||||
float length() const
|
||||
{
|
||||
return sqrt(length2());
|
||||
}
|
||||
|
||||
|
||||
Quaternion& normalize()
|
||||
{
|
||||
return *this /= length();
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
operator*(const float& s) const
|
||||
{
|
||||
return Quaternion(x() * s, y() * s, z() * s, m_w * s);
|
||||
}
|
||||
|
||||
|
||||
Quaternion operator/(const float& s) const
|
||||
{
|
||||
assert(s != 0.0f);
|
||||
return *this * (1.0f / s);
|
||||
}
|
||||
|
||||
|
||||
Quaternion& operator/=(const float& s)
|
||||
{
|
||||
assert(s != 0.0f);
|
||||
return *this *= 1.0f / s;
|
||||
}
|
||||
|
||||
|
||||
Quaternion normalized() const
|
||||
{
|
||||
return *this / length();
|
||||
}
|
||||
|
||||
|
||||
float angle(const Quaternion& q) const
|
||||
{
|
||||
float s = sqrt(length2() * q.length2());
|
||||
assert(s != 0.0f);
|
||||
return acos(dot(q) / s);
|
||||
}
|
||||
|
||||
|
||||
float getAngle() const
|
||||
{
|
||||
float s = 2.0f * acos(m_w);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Quaternion inverse() const
|
||||
{
|
||||
return Quaternion(m_x, m_y, m_z, -m_w);
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
operator+(const Quaternion& q2) const
|
||||
{
|
||||
const Quaternion& q1 = *this;
|
||||
return Quaternion(q1.x() + q2.x(), q1.y() + q2.y(), q1.z() + q2.z(), q1.m_w + q2.m_w);
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
operator-(const Quaternion& q2) const
|
||||
{
|
||||
const Quaternion& q1 = *this;
|
||||
return Quaternion(q1.x() - q2.x(), q1.y() - q2.y(), q1.z() - q2.z(), q1.m_w - q2.m_w);
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion operator-() const
|
||||
{
|
||||
const Quaternion& q2 = *this;
|
||||
return Quaternion( - q2.x(), - q2.y(), - q2.z(), - q2.m_w);
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion farthest( const Quaternion& qd) const
|
||||
{
|
||||
Quaternion diff,sum;
|
||||
diff = *this - qd;
|
||||
sum = *this + qd;
|
||||
if( diff.dot(diff) > sum.dot(sum) )
|
||||
return qd;
|
||||
return (-qd);
|
||||
}
|
||||
|
||||
|
||||
Quaternion slerp(const Quaternion& q, const float& t) const
|
||||
{
|
||||
float theta = angle(q);
|
||||
if (theta != 0.0f)
|
||||
{
|
||||
float d = 1.0f / sin(theta);
|
||||
float s0 = sin((1.0f - t) * theta);
|
||||
float s1 = sin(t * theta);
|
||||
return Quaternion((m_x * s0 + q.x() * s1) * d,
|
||||
(m_y * s0 + q.y() * s1) * d,
|
||||
(m_z * s0 + q.z() * s1) * d,
|
||||
(m_w * s0 + q.m_w * s1) * d);
|
||||
}
|
||||
else
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void toOpenGLMatrix(float m[4][4]){
|
||||
|
||||
float wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2;
|
||||
|
||||
// calculate coefficients
|
||||
x2 = m_x + m_x; y2 = m_y + m_y;
|
||||
z2 = m_z + m_z;
|
||||
xx = m_x * x2; xy = m_x * y2; xz = m_x * z2;
|
||||
yy = m_y * y2; yz = m_y * z2; zz = m_z * z2;
|
||||
wx = m_w * x2; wy = m_w * y2; wz = m_w * z2;
|
||||
|
||||
|
||||
m[0][0] = 1.0 - (yy + zz); m[1][0] = xy - wz;
|
||||
m[2][0] = xz + wy; m[3][0] = 0.0;
|
||||
|
||||
m[0][1] = xy + wz; m[1][1] = 1.0 - (xx + zz);
|
||||
m[2][1] = yz - wx; m[3][1] = 0.0;
|
||||
|
||||
|
||||
m[0][2] = xz - wy; m[1][2] = yz + wx;
|
||||
m[2][2] = 1.0 - (xx + yy); m[3][2] = 0.0;
|
||||
|
||||
|
||||
m[0][3] = 0; m[1][3] = 0;
|
||||
m[2][3] = 0; m[3][3] = 1;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
inline Quaternion
|
||||
operator-(const Quaternion& q)
|
||||
{
|
||||
return Quaternion(-q.x(), -q.y(), -q.z(), -q.w());
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
operator*(const Quaternion& q1, const Quaternion& q2) {
|
||||
return Quaternion(q1.w() * q2.x() + q1.x() * q2.w() + q1.y() * q2.z() - q1.z() * q2.y(),
|
||||
q1.w() * q2.y() + q1.y() * q2.w() + q1.z() * q2.x() - q1.x() * q2.z(),
|
||||
q1.w() * q2.z() + q1.z() * q2.w() + q1.x() * q2.y() - q1.y() * q2.x(),
|
||||
q1.w() * q2.w() - q1.x() * q2.x() - q1.y() * q2.y() - q1.z() * q2.z());
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
operator*(const Quaternion& q, const Vector3& w)
|
||||
{
|
||||
return Quaternion( q.w() * w.x() + q.y() * w.z() - q.z() * w.y(),
|
||||
q.w() * w.y() + q.z() * w.x() - q.x() * w.z(),
|
||||
q.w() * w.z() + q.x() * w.y() - q.y() * w.x(),
|
||||
-q.x() * w.x() - q.y() * w.y() - q.z() * w.z());
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
operator*(const Vector3& w, const Quaternion& q)
|
||||
{
|
||||
return Quaternion( w.x() * q.w() + w.y() * q.z() - w.z() * q.y(),
|
||||
w.y() * q.w() + w.z() * q.x() - w.x() * q.z(),
|
||||
w.z() * q.w() + w.x() * q.y() - w.y() * q.x(),
|
||||
-w.x() * q.x() - w.y() * q.y() - w.z() * q.z());
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
dot(const Quaternion& q1, const Quaternion& q2)
|
||||
{
|
||||
return q1.dot(q2);
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
length(const Quaternion& q)
|
||||
{
|
||||
return q.length();
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
angle(const Quaternion& q1, const Quaternion& q2)
|
||||
{
|
||||
return q1.angle(q2);
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
inverse(const Quaternion& q)
|
||||
{
|
||||
return q.inverse();
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
slerp(const Quaternion& q1, const Quaternion& q2, const float& t)
|
||||
{
|
||||
return q1.slerp(q2, t);
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
shortestArcQuat(const Vector3& v0, const Vector3& v1) // Game Programming Gems 2.10. make sure v0,v1 are normalized
|
||||
{
|
||||
Vector3 c = v0.cross(v1);
|
||||
float d = v0.dot(v1);
|
||||
|
||||
if (d < -1.0 + FLT_EPSILON)
|
||||
return Quaternion(0.0f, 1.0f, 0.0f, 0.0f); // just pick any vector
|
||||
|
||||
float s = sqrt((1.0f + d) * 2.0f);
|
||||
float rs = 1.0f / s;
|
||||
|
||||
return Quaternion(c.x() * rs, c.y() * rs, c.z() * rs, s * 0.5f);
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
shortestArcQuatNormalize2(Vector3& v0, Vector3& v1)
|
||||
{
|
||||
v0.normalize();
|
||||
v1.normalize();
|
||||
return shortestArcQuat(v0, v1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Copyright 2008 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Alexandre Deckner
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* This is a refactored and stripped down version of
|
||||
* bullet-2.66 src\LinearMath\btQuaternion.h
|
||||
* The dependancies on base class btQuadWord have been removed for
|
||||
* simplification.
|
||||
* Added gl matrix conversion method.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans
|
||||
http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the
|
||||
use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim
|
||||
that you wrote the original software. If you use this software in a product,
|
||||
an acknowledgment in the product documentation would be appreciated but is
|
||||
not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#ifndef __QUATERNION_H__
|
||||
#define __QUATERNION_H__
|
||||
|
||||
#include "Vector3.h"
|
||||
#include <SupportDefs.h>
|
||||
|
||||
class Quaternion {
|
||||
protected:
|
||||
float m_x;
|
||||
float m_y;
|
||||
float m_z;
|
||||
float m_w;
|
||||
public:
|
||||
Quaternion() {}
|
||||
|
||||
Quaternion(const Quaternion& q)
|
||||
{
|
||||
*((Quaternion*)this) = q;
|
||||
}
|
||||
|
||||
Quaternion(const float& x, const float& y, const float& z, const float& w)
|
||||
{
|
||||
m_x = x, m_y = y, m_z = z, m_w = w;
|
||||
}
|
||||
|
||||
Quaternion(const Vector3& axis, const float& angle)
|
||||
{
|
||||
setRotation(axis, angle);
|
||||
}
|
||||
|
||||
Quaternion(const float& yaw, const float& pitch, const float& roll)
|
||||
{
|
||||
setEuler(yaw, pitch, roll);
|
||||
}
|
||||
|
||||
inline const float& x() const { return m_x; }
|
||||
|
||||
|
||||
inline const float& y() const { return m_y; }
|
||||
|
||||
|
||||
inline const float& z() const { return m_z; }
|
||||
|
||||
|
||||
inline const float& w() const { return m_w; }
|
||||
|
||||
|
||||
void setValue(const float& x, const float& y, const float& z)
|
||||
{
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
m_z = z;
|
||||
m_w = 0.f;
|
||||
}
|
||||
|
||||
|
||||
void setValue(const float& x, const float& y, const float& z, const float& w)
|
||||
{
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
m_z = z;
|
||||
m_w = w;
|
||||
}
|
||||
|
||||
|
||||
void setRotation(const Vector3& axis, const float& angle)
|
||||
{
|
||||
float d = axis.length();
|
||||
assert(d != 0.0f);
|
||||
float s = sin(angle * 0.5f) / d;
|
||||
setValue(axis.x() * s, axis.y() * s, axis.z() * s,
|
||||
cos(angle * 0.5f));
|
||||
}
|
||||
|
||||
|
||||
void setEuler(const float& yaw, const float& pitch, const float& roll)
|
||||
{
|
||||
float halfYaw = yaw * 0.5f;
|
||||
float halfPitch = pitch * 0.5f;
|
||||
float halfRoll = roll * 0.5f;
|
||||
float cosYaw = cos(halfYaw);
|
||||
float sinYaw = sin(halfYaw);
|
||||
float cosPitch = cos(halfPitch);
|
||||
float sinPitch = sin(halfPitch);
|
||||
float cosRoll = cos(halfRoll);
|
||||
float sinRoll = sin(halfRoll);
|
||||
setValue(cosRoll * sinPitch * cosYaw + sinRoll * cosPitch * sinYaw,
|
||||
cosRoll * cosPitch * sinYaw - sinRoll * sinPitch * cosYaw,
|
||||
sinRoll * cosPitch * cosYaw - cosRoll * sinPitch * sinYaw,
|
||||
cosRoll * cosPitch * cosYaw + sinRoll * sinPitch * sinYaw);
|
||||
}
|
||||
|
||||
|
||||
Quaternion& operator+=(const Quaternion& q)
|
||||
{
|
||||
m_x += q.x(); m_y += q.y(); m_z += q.z(); m_w += q.m_w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Quaternion& operator-=(const Quaternion& q)
|
||||
{
|
||||
m_x -= q.x(); m_y -= q.y(); m_z -= q.z(); m_w -= q.m_w;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Quaternion& operator*=(const float& s)
|
||||
{
|
||||
m_x *= s; m_y *= s; m_z *= s; m_w *= s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Quaternion& operator*=(const Quaternion& q)
|
||||
{
|
||||
setValue(m_w * q.x() + m_x * q.m_w + m_y * q.z() - m_z * q.y(),
|
||||
m_w * q.y() + m_y * q.m_w + m_z * q.x() - m_x * q.z(),
|
||||
m_w * q.z() + m_z * q.m_w + m_x * q.y() - m_y * q.x(),
|
||||
m_w * q.m_w - m_x * q.x() - m_y * q.y() - m_z * q.z());
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
float dot(const Quaternion& q) const
|
||||
{
|
||||
return m_x * q.x() + m_y * q.y() + m_z * q.z() + m_w * q.m_w;
|
||||
}
|
||||
|
||||
|
||||
float length2() const
|
||||
{
|
||||
return dot(*this);
|
||||
}
|
||||
|
||||
|
||||
float length() const
|
||||
{
|
||||
return sqrt(length2());
|
||||
}
|
||||
|
||||
|
||||
Quaternion& normalize()
|
||||
{
|
||||
return *this /= length();
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
operator*(const float& s) const
|
||||
{
|
||||
return Quaternion(x() * s, y() * s, z() * s, m_w * s);
|
||||
}
|
||||
|
||||
|
||||
Quaternion operator/(const float& s) const
|
||||
{
|
||||
assert(s != 0.0f);
|
||||
return *this * (1.0f / s);
|
||||
}
|
||||
|
||||
|
||||
Quaternion& operator/=(const float& s)
|
||||
{
|
||||
assert(s != 0.0f);
|
||||
return *this *= 1.0f / s;
|
||||
}
|
||||
|
||||
|
||||
Quaternion normalized() const
|
||||
{
|
||||
return *this / length();
|
||||
}
|
||||
|
||||
|
||||
float angle(const Quaternion& q) const
|
||||
{
|
||||
float s = sqrt(length2() * q.length2());
|
||||
assert(s != 0.0f);
|
||||
return acos(dot(q) / s);
|
||||
}
|
||||
|
||||
|
||||
float getAngle() const
|
||||
{
|
||||
float s = 2.0f * acos(m_w);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
Quaternion inverse() const
|
||||
{
|
||||
return Quaternion(m_x, m_y, m_z, -m_w);
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
operator+(const Quaternion& q2) const
|
||||
{
|
||||
const Quaternion& q1 = *this;
|
||||
return Quaternion(q1.x() + q2.x(), q1.y() + q2.y(), q1.z() + q2.z(),
|
||||
q1.m_w + q2.m_w);
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
operator-(const Quaternion& q2) const
|
||||
{
|
||||
const Quaternion& q1 = *this;
|
||||
return Quaternion(q1.x() - q2.x(), q1.y() - q2.y(), q1.z() - q2.z(),
|
||||
q1.m_w - q2.m_w);
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion operator-() const
|
||||
{
|
||||
const Quaternion& q2 = *this;
|
||||
return Quaternion( - q2.x(), - q2.y(), - q2.z(), - q2.m_w);
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion farthest( const Quaternion& qd) const
|
||||
{
|
||||
Quaternion diff, sum;
|
||||
diff = *this - qd;
|
||||
sum = *this + qd;
|
||||
if (diff.dot(diff) > sum.dot(sum))
|
||||
return qd;
|
||||
return (-qd);
|
||||
}
|
||||
|
||||
|
||||
Quaternion slerp(const Quaternion& q, const float& t) const
|
||||
{
|
||||
float theta = angle(q);
|
||||
if (theta != 0.0f) {
|
||||
float d = 1.0f / sin(theta);
|
||||
float s0 = sin((1.0f - t) * theta);
|
||||
float s1 = sin(t * theta);
|
||||
return Quaternion((m_x * s0 + q.x() * s1) * d,
|
||||
(m_y * s0 + q.y() * s1) * d,
|
||||
(m_z * s0 + q.z() * s1) * d,
|
||||
(m_w * s0 + q.m_w * s1) * d);
|
||||
} else {
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void toOpenGLMatrix(float m[4][4])
|
||||
{
|
||||
float wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2;
|
||||
|
||||
// calculate coefficients
|
||||
x2 = m_x + m_x; y2 = m_y + m_y;
|
||||
z2 = m_z + m_z;
|
||||
xx = m_x * x2; xy = m_x * y2; xz = m_x * z2;
|
||||
yy = m_y * y2; yz = m_y * z2; zz = m_z * z2;
|
||||
wx = m_w * x2; wy = m_w * y2; wz = m_w * z2;
|
||||
|
||||
|
||||
m[0][0] = 1.0 - (yy + zz); m[1][0] = xy - wz;
|
||||
m[2][0] = xz + wy; m[3][0] = 0.0;
|
||||
|
||||
m[0][1] = xy + wz; m[1][1] = 1.0 - (xx + zz);
|
||||
m[2][1] = yz - wx; m[3][1] = 0.0;
|
||||
|
||||
|
||||
m[0][2] = xz - wy; m[1][2] = yz + wx;
|
||||
m[2][2] = 1.0 - (xx + yy); m[3][2] = 0.0;
|
||||
|
||||
|
||||
m[0][3] = 0; m[1][3] = 0;
|
||||
m[2][3] = 0; m[3][3] = 1;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
inline Quaternion
|
||||
operator-(const Quaternion& q)
|
||||
{
|
||||
return Quaternion(-q.x(), -q.y(), -q.z(), -q.w());
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
operator*(const Quaternion& q1, const Quaternion& q2) {
|
||||
return Quaternion(
|
||||
q1.w() * q2.x() + q1.x() * q2.w() + q1.y() * q2.z() - q1.z() * q2.y(),
|
||||
q1.w() * q2.y() + q1.y() * q2.w() + q1.z() * q2.x() - q1.x() * q2.z(),
|
||||
q1.w() * q2.z() + q1.z() * q2.w() + q1.x() * q2.y() - q1.y() * q2.x(),
|
||||
q1.w() * q2.w() - q1.x() * q2.x() - q1.y() * q2.y() - q1.z() * q2.z());
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
operator*(const Quaternion& q, const Vector3& w)
|
||||
{
|
||||
return Quaternion( q.w() * w.x() + q.y() * w.z() - q.z() * w.y(),
|
||||
q.w() * w.y() + q.z() * w.x() - q.x() * w.z(),
|
||||
q.w() * w.z() + q.x() * w.y() - q.y() * w.x(),
|
||||
-q.x() * w.x() - q.y() * w.y() - q.z() * w.z());
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
operator*(const Vector3& w, const Quaternion& q)
|
||||
{
|
||||
return Quaternion( w.x() * q.w() + w.y() * q.z() - w.z() * q.y(),
|
||||
w.y() * q.w() + w.z() * q.x() - w.x() * q.z(),
|
||||
w.z() * q.w() + w.x() * q.y() - w.y() * q.x(),
|
||||
-w.x() * q.x() - w.y() * q.y() - w.z() * q.z());
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
dot(const Quaternion& q1, const Quaternion& q2)
|
||||
{
|
||||
return q1.dot(q2);
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
length(const Quaternion& q)
|
||||
{
|
||||
return q.length();
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
angle(const Quaternion& q1, const Quaternion& q2)
|
||||
{
|
||||
return q1.angle(q2);
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
inverse(const Quaternion& q)
|
||||
{
|
||||
return q.inverse();
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
slerp(const Quaternion& q1, const Quaternion& q2, const float& t)
|
||||
{
|
||||
return q1.slerp(q2, t);
|
||||
}
|
||||
|
||||
|
||||
// Game Programming Gems 2.10. make sure v0,v1 are normalized
|
||||
inline Quaternion
|
||||
shortestArcQuat(const Vector3& v0, const Vector3& v1)
|
||||
{
|
||||
Vector3 c = v0.cross(v1);
|
||||
float d = v0.dot(v1);
|
||||
|
||||
if (d < -1.0 + FLT_EPSILON)
|
||||
return Quaternion(0.0f, 1.0f, 0.0f, 0.0f); // just pick any vector
|
||||
|
||||
float s = sqrt((1.0f + d) * 2.0f);
|
||||
float rs = 1.0f / s;
|
||||
|
||||
return Quaternion(c.x() * rs, c.y() * rs, c.z() * rs, s * 0.5f);
|
||||
}
|
||||
|
||||
|
||||
inline Quaternion
|
||||
shortestArcQuatNormalize2(Vector3& v0, Vector3& v1)
|
||||
{
|
||||
v0.normalize();
|
||||
v1.normalize();
|
||||
return shortestArcQuat(v0, v1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -186,7 +186,7 @@ void
|
||||
RenderView::_DeleteScene()
|
||||
{
|
||||
MeshInstanceList::iterator it = fMeshInstances.begin();
|
||||
for(; it != fMeshInstances.end(); it++) {
|
||||
for (; it != fMeshInstances.end(); it++) {
|
||||
delete (*it);
|
||||
}
|
||||
fMeshInstances.clear();
|
||||
@ -231,7 +231,7 @@ RenderView::_Render()
|
||||
fLastFrameTime = time;
|
||||
|
||||
MeshInstanceList::iterator it = fMeshInstances.begin();
|
||||
for(; it != fMeshInstances.end(); it++) {
|
||||
for (; it != fMeshInstances.end(); it++) {
|
||||
(*it)->Update(deltaTime);
|
||||
(*it)->Render();
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
Texture();
|
||||
virtual ~Texture();
|
||||
|
||||
GLuint Id();
|
||||
GLuint Id();
|
||||
|
||||
virtual void Update(float dt);
|
||||
|
||||
|
@ -1,353 +1,384 @@
|
||||
/*
|
||||
* Copyright 2008 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Alexandre Deckner
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* This is a refactored and stripped down version of bullet-2.66 src\LinearMath\btVector3.h
|
||||
* The dependancies on base class btQuadWord have been removed for simplification.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __VECTOR3_H__
|
||||
#define __VECTOR3_H__
|
||||
|
||||
#include "assert.h"
|
||||
#include "math.h"
|
||||
|
||||
///Vector3 can be used to represent 3D points and vectors.
|
||||
|
||||
class Vector3 {
|
||||
protected:
|
||||
float m_x;
|
||||
float m_y;
|
||||
float m_z;
|
||||
|
||||
public:
|
||||
inline Vector3() {}
|
||||
|
||||
|
||||
inline Vector3(const Vector3& v)
|
||||
{
|
||||
*((Vector3*)this) = v;
|
||||
}
|
||||
|
||||
|
||||
inline Vector3(const float& x, const float& y, const float& z)
|
||||
{
|
||||
m_x = x, m_y = y, m_z = z;
|
||||
}
|
||||
|
||||
|
||||
inline const float& x() const { return m_x; }
|
||||
|
||||
|
||||
inline const float& y() const { return m_y; }
|
||||
|
||||
|
||||
inline const float& z() const { return m_z; }
|
||||
|
||||
|
||||
inline void setValue(const float& x, const float& y, const float& z)
|
||||
{
|
||||
m_x=x;
|
||||
m_y=y;
|
||||
m_z=z;
|
||||
}
|
||||
|
||||
inline Vector3& operator+=(const Vector3& v)
|
||||
{
|
||||
m_x += v.x(); m_y += v.y(); m_z += v.z();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Vector3& operator-=(const Vector3& v)
|
||||
{
|
||||
m_x -= v.x(); m_y -= v.y(); m_z -= v.z();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Vector3& operator*=(const float& s)
|
||||
{
|
||||
m_x *= s; m_y *= s; m_z *= s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Vector3& operator/=(const float& s)
|
||||
{
|
||||
assert(s != 0.0f);
|
||||
return *this *= 1.0f / s;
|
||||
}
|
||||
|
||||
|
||||
inline float dot(const Vector3& v) const
|
||||
{
|
||||
return m_x * v.x() + m_y * v.y() + m_z * v.z();
|
||||
}
|
||||
|
||||
|
||||
inline float length2() const
|
||||
{
|
||||
return dot(*this);
|
||||
}
|
||||
|
||||
|
||||
inline float length() const
|
||||
{
|
||||
return sqrt(length2());
|
||||
}
|
||||
|
||||
|
||||
inline float distance2(const Vector3& v) const;
|
||||
|
||||
|
||||
inline float distance(const Vector3& v) const;
|
||||
|
||||
|
||||
inline Vector3& normalize()
|
||||
{
|
||||
return *this /= length();
|
||||
}
|
||||
|
||||
|
||||
inline Vector3 normalized() const;
|
||||
|
||||
|
||||
inline Vector3 rotate( const Vector3& wAxis, const float angle );
|
||||
|
||||
|
||||
inline float angle(const Vector3& v) const
|
||||
{
|
||||
float s = sqrt(length2() * v.length2());
|
||||
assert(s != 0.0f);
|
||||
return acos(dot(v) / s);
|
||||
}
|
||||
|
||||
|
||||
inline Vector3 absolute() const
|
||||
{
|
||||
return Vector3(
|
||||
fabs(m_x),
|
||||
fabs(m_y),
|
||||
fabs(m_z));
|
||||
}
|
||||
|
||||
|
||||
inline Vector3 cross(const Vector3& v) const
|
||||
{
|
||||
return Vector3(
|
||||
m_y * v.z() - m_z * v.y(),
|
||||
m_z * v.x() - m_x * v.z(),
|
||||
m_x * v.y() - m_y * v.x());
|
||||
}
|
||||
|
||||
|
||||
inline float triple(const Vector3& v1, const Vector3& v2) const
|
||||
{
|
||||
return m_x * (v1.y() * v2.z() - v1.z() * v2.y()) +
|
||||
m_y * (v1.z() * v2.x() - v1.x() * v2.z()) +
|
||||
m_z * (v1.x() * v2.y() - v1.y() * v2.x());
|
||||
}
|
||||
|
||||
|
||||
inline int minAxis() const
|
||||
{
|
||||
return m_x < m_y ? (m_x < m_z ? 0 : 2) : (m_y < m_z ? 1 : 2);
|
||||
}
|
||||
|
||||
|
||||
inline int maxAxis() const
|
||||
{
|
||||
return m_x < m_y ? (m_y < m_z ? 2 : 1) : (m_x < m_z ? 2 : 0);
|
||||
}
|
||||
|
||||
|
||||
inline int furthestAxis() const
|
||||
{
|
||||
return absolute().minAxis();
|
||||
}
|
||||
|
||||
|
||||
inline int closestAxis() const
|
||||
{
|
||||
return absolute().maxAxis();
|
||||
}
|
||||
|
||||
|
||||
inline void setInterpolate3(const Vector3& v0, const Vector3& v1, float rt)
|
||||
{
|
||||
float s = 1.0f - rt;
|
||||
m_x = s * v0.x() + rt * v1.x();
|
||||
m_y = s * v0.y() + rt * v1.y();
|
||||
m_z = s * v0.z() + rt * v1.z();
|
||||
//don't do the unused w component
|
||||
// m_co[3] = s * v0[3] + rt * v1[3];
|
||||
}
|
||||
|
||||
|
||||
inline Vector3 lerp(const Vector3& v, const float& t) const
|
||||
{
|
||||
return Vector3(m_x + (v.x() - m_x) * t,
|
||||
m_y + (v.y() - m_y) * t,
|
||||
m_z + (v.z() - m_z) * t);
|
||||
}
|
||||
|
||||
|
||||
inline Vector3& operator*=(const Vector3& v)
|
||||
{
|
||||
m_x *= v.x(); m_y *= v.y(); m_z *= v.z();
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
inline Vector3
|
||||
operator+(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return Vector3(v1.x() + v2.x(), v1.y() + v2.y(), v1.z() + v2.z());
|
||||
}
|
||||
|
||||
inline Vector3
|
||||
operator*(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return Vector3(v1.x() * v2.x(), v1.y() * v2.y(), v1.z() * v2.z());
|
||||
}
|
||||
|
||||
inline Vector3
|
||||
operator-(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return Vector3(v1.x() - v2.x(), v1.y() - v2.y(), v1.z() - v2.z());
|
||||
}
|
||||
|
||||
inline Vector3
|
||||
operator-(const Vector3& v)
|
||||
{
|
||||
return Vector3(-v.x(), -v.y(), -v.z());
|
||||
}
|
||||
|
||||
inline Vector3
|
||||
operator*(const Vector3& v, const float& s)
|
||||
{
|
||||
return Vector3(v.x() * s, v.y() * s, v.z() * s);
|
||||
}
|
||||
|
||||
inline Vector3
|
||||
operator*(const float& s, const Vector3& v)
|
||||
{
|
||||
return v * s;
|
||||
}
|
||||
|
||||
inline Vector3
|
||||
operator/(const Vector3& v, const float& s)
|
||||
{
|
||||
assert(s != 0.0f);
|
||||
return v * (1.0f / s);
|
||||
}
|
||||
|
||||
inline Vector3
|
||||
operator/(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return Vector3(v1.x() / v2.x(),v1.y() / v2.y(),v1.z() / v2.z());
|
||||
}
|
||||
|
||||
inline float
|
||||
dot(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return v1.dot(v2);
|
||||
}
|
||||
|
||||
inline float
|
||||
distance2(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return v1.distance2(v2);
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
distance(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return v1.distance(v2);
|
||||
}
|
||||
|
||||
inline float
|
||||
angle(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return v1.angle(v2);
|
||||
}
|
||||
|
||||
inline Vector3
|
||||
cross(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return v1.cross(v2);
|
||||
}
|
||||
|
||||
inline float
|
||||
triple(const Vector3& v1, const Vector3& v2, const Vector3& v3)
|
||||
{
|
||||
return v1.triple(v2, v3);
|
||||
}
|
||||
|
||||
inline Vector3
|
||||
lerp(const Vector3& v1, const Vector3& v2, const float& t)
|
||||
{
|
||||
return v1.lerp(v2, t);
|
||||
}
|
||||
|
||||
|
||||
inline bool operator==(const Vector3& p1, const Vector3& p2)
|
||||
{
|
||||
return p1.x() == p2.x() && p1.y() == p2.y() && p1.z() == p2.z();
|
||||
}
|
||||
|
||||
inline float Vector3::distance2(const Vector3& v) const
|
||||
{
|
||||
return (v - *this).length2();
|
||||
}
|
||||
|
||||
inline float Vector3::distance(const Vector3& v) const
|
||||
{
|
||||
return (v - *this).length();
|
||||
}
|
||||
|
||||
inline Vector3 Vector3::normalized() const
|
||||
{
|
||||
return *this / length();
|
||||
}
|
||||
|
||||
inline Vector3 Vector3::rotate( const Vector3& wAxis, const float angle )
|
||||
{
|
||||
// wAxis must be a unit lenght vector
|
||||
|
||||
Vector3 o = wAxis * wAxis.dot( *this );
|
||||
Vector3 x = *this - o;
|
||||
Vector3 y;
|
||||
|
||||
y = wAxis.cross( *this );
|
||||
|
||||
return ( o + x * cos( angle ) + y * sin( angle ) );
|
||||
}
|
||||
|
||||
#endif //__VECTOR3_H__
|
||||
/*
|
||||
* Copyright 2008 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Alexandre Deckner
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
* This is a refactored and stripped down version of bullet-2.66
|
||||
* src\LinearMath\btVector3.h
|
||||
* The dependancies on base class btQuadWord have been removed for
|
||||
* simplification.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans
|
||||
http://continuousphysics.com/Bullet/
|
||||
|
||||
This software is provided 'as-is', without any express or implied warranty.
|
||||
In no event will the authors be held liable for any damages arising from the
|
||||
use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it freely,
|
||||
subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not claim
|
||||
that you wrote the original software. If you use this software in a product,
|
||||
an acknowledgment in the product documentation would be appreciated but is
|
||||
not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __VECTOR3_H__
|
||||
#define __VECTOR3_H__
|
||||
|
||||
#include "assert.h"
|
||||
#include "math.h"
|
||||
|
||||
///Vector3 can be used to represent 3D points and vectors.
|
||||
|
||||
class Vector3 {
|
||||
protected:
|
||||
float m_x;
|
||||
float m_y;
|
||||
float m_z;
|
||||
|
||||
public:
|
||||
inline Vector3() {}
|
||||
|
||||
|
||||
inline Vector3(const Vector3& v)
|
||||
{
|
||||
*((Vector3*)this) = v;
|
||||
}
|
||||
|
||||
|
||||
inline Vector3(const float& x, const float& y, const float& z)
|
||||
{
|
||||
m_x = x, m_y = y, m_z = z;
|
||||
}
|
||||
|
||||
|
||||
inline const float& x() const { return m_x; }
|
||||
|
||||
|
||||
inline const float& y() const { return m_y; }
|
||||
|
||||
|
||||
inline const float& z() const { return m_z; }
|
||||
|
||||
|
||||
inline void setValue(const float& x, const float& y, const float& z)
|
||||
{
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
m_z = z;
|
||||
}
|
||||
|
||||
inline Vector3& operator+=(const Vector3& v)
|
||||
{
|
||||
m_x += v.x(); m_y += v.y(); m_z += v.z();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Vector3& operator-=(const Vector3& v)
|
||||
{
|
||||
m_x -= v.x(); m_y -= v.y(); m_z -= v.z();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Vector3& operator*=(const float& s)
|
||||
{
|
||||
m_x *= s; m_y *= s; m_z *= s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
inline Vector3& operator/=(const float& s)
|
||||
{
|
||||
assert(s != 0.0f);
|
||||
return *this *= 1.0f / s;
|
||||
}
|
||||
|
||||
|
||||
inline float dot(const Vector3& v) const
|
||||
{
|
||||
return m_x * v.x() + m_y * v.y() + m_z * v.z();
|
||||
}
|
||||
|
||||
|
||||
inline float length2() const
|
||||
{
|
||||
return dot(*this);
|
||||
}
|
||||
|
||||
|
||||
inline float length() const
|
||||
{
|
||||
return sqrt(length2());
|
||||
}
|
||||
|
||||
|
||||
inline float distance2(const Vector3& v) const;
|
||||
|
||||
|
||||
inline float distance(const Vector3& v) const;
|
||||
|
||||
|
||||
inline Vector3& normalize()
|
||||
{
|
||||
return *this /= length();
|
||||
}
|
||||
|
||||
|
||||
inline Vector3 normalized() const;
|
||||
|
||||
|
||||
inline Vector3 rotate( const Vector3& wAxis, const float angle );
|
||||
|
||||
|
||||
inline float angle(const Vector3& v) const
|
||||
{
|
||||
float s = sqrt(length2() * v.length2());
|
||||
assert(s != 0.0f);
|
||||
return acos(dot(v) / s);
|
||||
}
|
||||
|
||||
|
||||
inline Vector3 absolute() const
|
||||
{
|
||||
return Vector3(
|
||||
fabs(m_x),
|
||||
fabs(m_y),
|
||||
fabs(m_z));
|
||||
}
|
||||
|
||||
|
||||
inline Vector3 cross(const Vector3& v) const
|
||||
{
|
||||
return Vector3(
|
||||
m_y * v.z() - m_z * v.y(),
|
||||
m_z * v.x() - m_x * v.z(),
|
||||
m_x * v.y() - m_y * v.x());
|
||||
}
|
||||
|
||||
|
||||
inline float triple(const Vector3& v1, const Vector3& v2) const
|
||||
{
|
||||
return m_x * (v1.y() * v2.z() - v1.z() * v2.y())
|
||||
+ m_y * (v1.z() * v2.x() - v1.x() * v2.z())
|
||||
+ m_z * (v1.x() * v2.y() - v1.y() * v2.x());
|
||||
}
|
||||
|
||||
|
||||
inline int minAxis() const
|
||||
{
|
||||
return m_x < m_y ? (m_x < m_z ? 0 : 2) : (m_y < m_z ? 1 : 2);
|
||||
}
|
||||
|
||||
|
||||
inline int maxAxis() const
|
||||
{
|
||||
return m_x < m_y ? (m_y < m_z ? 2 : 1) : (m_x < m_z ? 2 : 0);
|
||||
}
|
||||
|
||||
|
||||
inline int furthestAxis() const
|
||||
{
|
||||
return absolute().minAxis();
|
||||
}
|
||||
|
||||
|
||||
inline int closestAxis() const
|
||||
{
|
||||
return absolute().maxAxis();
|
||||
}
|
||||
|
||||
|
||||
inline void setInterpolate3(const Vector3& v0, const Vector3& v1, float rt)
|
||||
{
|
||||
float s = 1.0f - rt;
|
||||
m_x = s * v0.x() + rt * v1.x();
|
||||
m_y = s * v0.y() + rt * v1.y();
|
||||
m_z = s * v0.z() + rt * v1.z();
|
||||
// don't do the unused w component
|
||||
// m_co[3] = s * v0[3] + rt * v1[3];
|
||||
}
|
||||
|
||||
|
||||
inline Vector3 lerp(const Vector3& v, const float& t) const
|
||||
{
|
||||
return Vector3(m_x + (v.x() - m_x) * t,
|
||||
m_y + (v.y() - m_y) * t,
|
||||
m_z + (v.z() - m_z) * t);
|
||||
}
|
||||
|
||||
|
||||
inline Vector3& operator*=(const Vector3& v)
|
||||
{
|
||||
m_x *= v.x(); m_y *= v.y(); m_z *= v.z();
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
inline Vector3
|
||||
operator+(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return Vector3(v1.x() + v2.x(), v1.y() + v2.y(), v1.z() + v2.z());
|
||||
}
|
||||
|
||||
|
||||
inline Vector3
|
||||
operator*(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return Vector3(v1.x() * v2.x(), v1.y() * v2.y(), v1.z() * v2.z());
|
||||
}
|
||||
|
||||
|
||||
inline Vector3
|
||||
operator-(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return Vector3(v1.x() - v2.x(), v1.y() - v2.y(), v1.z() - v2.z());
|
||||
}
|
||||
|
||||
|
||||
inline Vector3
|
||||
operator-(const Vector3& v)
|
||||
{
|
||||
return Vector3(-v.x(), -v.y(), -v.z());
|
||||
}
|
||||
|
||||
|
||||
inline Vector3
|
||||
operator*(const Vector3& v, const float& s)
|
||||
{
|
||||
return Vector3(v.x() * s, v.y() * s, v.z() * s);
|
||||
}
|
||||
|
||||
|
||||
inline Vector3
|
||||
operator*(const float& s, const Vector3& v)
|
||||
{
|
||||
return v * s;
|
||||
}
|
||||
|
||||
|
||||
inline Vector3
|
||||
operator/(const Vector3& v, const float& s)
|
||||
{
|
||||
assert(s != 0.0f);
|
||||
return v * (1.0f / s);
|
||||
}
|
||||
|
||||
|
||||
inline Vector3
|
||||
operator/(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return Vector3(v1.x() / v2.x(),v1.y() / v2.y(),v1.z() / v2.z());
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
dot(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return v1.dot(v2);
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
distance2(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return v1.distance2(v2);
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
distance(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return v1.distance(v2);
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
angle(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return v1.angle(v2);
|
||||
}
|
||||
|
||||
|
||||
inline Vector3
|
||||
cross(const Vector3& v1, const Vector3& v2)
|
||||
{
|
||||
return v1.cross(v2);
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
triple(const Vector3& v1, const Vector3& v2, const Vector3& v3)
|
||||
{
|
||||
return v1.triple(v2, v3);
|
||||
}
|
||||
|
||||
|
||||
inline Vector3
|
||||
lerp(const Vector3& v1, const Vector3& v2, const float& t)
|
||||
{
|
||||
return v1.lerp(v2, t);
|
||||
}
|
||||
|
||||
|
||||
inline bool
|
||||
operator==(const Vector3& p1, const Vector3& p2)
|
||||
{
|
||||
return p1.x() == p2.x() && p1.y() == p2.y() && p1.z() == p2.z();
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
Vector3::distance2(const Vector3& v) const
|
||||
{
|
||||
return (v - *this).length2();
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
Vector3::distance(const Vector3& v) const
|
||||
{
|
||||
return (v - *this).length();
|
||||
}
|
||||
|
||||
|
||||
inline Vector3
|
||||
Vector3::normalized() const
|
||||
{
|
||||
return *this / length();
|
||||
}
|
||||
|
||||
|
||||
inline Vector3
|
||||
Vector3::rotate( const Vector3& wAxis, const float angle )
|
||||
{
|
||||
// wAxis must be a unit lenght vector
|
||||
|
||||
Vector3 o = wAxis * wAxis.dot( *this );
|
||||
Vector3 x = *this - o;
|
||||
Vector3 y;
|
||||
|
||||
y = wAxis.cross( *this );
|
||||
|
||||
return ( o + x * cos( angle ) + y * sin( angle ) );
|
||||
}
|
||||
|
||||
#endif //__VECTOR3_H__
|
||||
|
@ -43,11 +43,11 @@ StaticMesh::~StaticMesh()
|
||||
void
|
||||
StaticMesh::_ReadText(const char* fileName)
|
||||
{
|
||||
FILE* f = fopen(fileName, "r");
|
||||
if (f == NULL) {
|
||||
printf("Mesh::_ReadText, error accessing %s\n", fileName);
|
||||
return;
|
||||
}
|
||||
FILE* f = fopen(fileName, "r");
|
||||
if (f == NULL) {
|
||||
printf("Mesh::_ReadText, error accessing %s\n", fileName);
|
||||
return;
|
||||
}
|
||||
|
||||
fscanf(f, "%lu", &fFaceCount);
|
||||
fFaces = new Face[fFaceCount];
|
||||
@ -98,10 +98,10 @@ StaticMesh::_ReadBinary(const char* fileName)
|
||||
{
|
||||
BFile file(fileName, B_READ_ONLY);
|
||||
|
||||
if (file.InitCheck() != B_OK) {
|
||||
printf("Mesh::_ReadBinary, error accessing %s\n", fileName);
|
||||
return;
|
||||
}
|
||||
if (file.InitCheck() != B_OK) {
|
||||
printf("Mesh::_ReadBinary, error accessing %s\n", fileName);
|
||||
return;
|
||||
}
|
||||
|
||||
file.Read(&fFaceCount, sizeof(uint32));
|
||||
fFaces = new Face[fFaceCount];
|
||||
@ -119,7 +119,7 @@ void
|
||||
StaticMesh::_ReadResource(const char* resourceName)
|
||||
{
|
||||
// TODO: factorize with _ReadBinary
|
||||
app_info info;
|
||||
app_info info;
|
||||
be_app->GetAppInfo(&info);
|
||||
BFile file(&info.ref, B_READ_ONLY);
|
||||
|
||||
|
@ -30,23 +30,23 @@ BitmapTexture::~BitmapTexture()
|
||||
|
||||
void
|
||||
BitmapTexture::_Load(BBitmap* bitmap) {
|
||||
if (bitmap == NULL)
|
||||
return;
|
||||
if (bitmap == NULL)
|
||||
return;
|
||||
|
||||
glGenTextures(1, &fId);
|
||||
glBindTexture(GL_TEXTURE_2D, fId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 4,
|
||||
(int) bitmap->Bounds().Width() + 1,
|
||||
(int) bitmap->Bounds().Height() + 1,
|
||||
0, GL_BGRA, GL_UNSIGNED_BYTE,
|
||||
bitmap->Bits());
|
||||
glGenTextures(1, &fId);
|
||||
glBindTexture(GL_TEXTURE_2D, fId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 4,
|
||||
(int) bitmap->Bounds().Width() + 1,
|
||||
(int) bitmap->Bounds().Height() + 1,
|
||||
0, GL_BGRA, GL_UNSIGNED_BYTE,
|
||||
bitmap->Bits());
|
||||
|
||||
printf("BitmapTexture::_Load, loaded texture %u (%li, %li, %libits)\n",
|
||||
fId, (int32) bitmap->Bounds().Width(),
|
||||
(int32) bitmap->Bounds().Height(),
|
||||
8 * bitmap->BytesPerRow() / (int)bitmap->Bounds().Width());
|
||||
printf("BitmapTexture::_Load, loaded texture %u (%li, %li, %libits)\n",
|
||||
fId, (int32) bitmap->Bounds().Width(),
|
||||
(int32) bitmap->Bounds().Height(),
|
||||
8 * bitmap->BytesPerRow() / (int)bitmap->Bounds().Width());
|
||||
|
||||
delete bitmap;
|
||||
}
|
||||
|
@ -91,8 +91,8 @@ VideoFileTexture::_Load(const char* fileName)
|
||||
format.u.raw_video.display.format = fVideoBitmap->ColorSpace();
|
||||
format.u.raw_video.display.line_width = (int32) bounds.Width();
|
||||
format.u.raw_video.display.line_count = (int32) bounds.Height();
|
||||
format.u.raw_video.display.bytes_per_row =
|
||||
fVideoBitmap->BytesPerRow();
|
||||
format.u.raw_video.display.bytes_per_row
|
||||
= fVideoBitmap->BytesPerRow();
|
||||
|
||||
err = fVideoTrack->DecodedFormat(&format);
|
||||
if (err != B_OK) {
|
||||
@ -102,14 +102,14 @@ VideoFileTexture::_Load(const char* fileName)
|
||||
}
|
||||
|
||||
// Create Texture
|
||||
glGenTextures(1, &fId);
|
||||
glBindTexture(GL_TEXTURE_2D, fId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 4,
|
||||
(int) fVideoBitmap->Bounds().Width() + 1,
|
||||
(int) fVideoBitmap->Bounds().Height() + 1,
|
||||
0, GL_BGRA, GL_UNSIGNED_BYTE, fVideoBitmap->Bits());
|
||||
glGenTextures(1, &fId);
|
||||
glBindTexture(GL_TEXTURE_2D, fId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, 4,
|
||||
(int) fVideoBitmap->Bounds().Width() + 1,
|
||||
(int) fVideoBitmap->Bounds().Height() + 1,
|
||||
0, GL_BGRA, GL_UNSIGNED_BYTE, fVideoBitmap->Bits());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -120,8 +120,8 @@ VideoFileTexture::Update(float /*dt*/) {
|
||||
// TODO loop
|
||||
int64 frameCount = 0;
|
||||
media_header mh;
|
||||
status_t err =
|
||||
fVideoTrack->ReadFrames(fVideoBitmap->Bits(), &frameCount, &mh);
|
||||
status_t err
|
||||
= fVideoTrack->ReadFrames(fVideoBitmap->Bits(), &frameCount, &mh);
|
||||
if (err) {
|
||||
printf("BMediaTrack::ReadFrames error -- %s\n", strerror(err));
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user