From: <axl...@us...> - 2009-05-22 01:29:05
|
Revision: 271 http://hgengine.svn.sourceforge.net/hgengine/?rev=271&view=rev Author: axlecrusher Date: 2009-05-22 01:28:54 +0000 (Fri, 22 May 2009) Log Message: ----------- quaternion Modified Paths: -------------- Mercury2/src/Camera.cpp Mercury2/src/TransformNode.cpp Mercury2/src/TransformNode.h Added Paths: ----------- Mercury2/src/MQuaternion.cpp Mercury2/src/MQuaternion.h Modified: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp 2009-05-19 00:21:56 UTC (rev 270) +++ Mercury2/src/Camera.cpp 2009-05-22 01:28:54 UTC (rev 271) @@ -16,7 +16,9 @@ MercuryMatrix local; - local.RotateXYZ( m_rotation*-1 ); +// local.RotateXYZ( m_rotation*-1 ); +// m_rotation. + AngleMatrix( m_rotation.ToVertex()*-1, local); local.Translate( m_position*-1 ); m_globalMatrix = GetParentMatrix() * local; @@ -28,7 +30,7 @@ { MouseInput* m = (MouseInput*)data; - MercuryVector r = m_rotation; + MQuaternion r = m_rotation; r[0] += m->dy/30.0f; r[1] += m->dx/30.0f; Added: Mercury2/src/MQuaternion.cpp =================================================================== --- Mercury2/src/MQuaternion.cpp (rev 0) +++ Mercury2/src/MQuaternion.cpp 2009-05-22 01:28:54 UTC (rev 271) @@ -0,0 +1,360 @@ +#include <MQuaternion.h> +#include <MercuryMath.h> + +MQuaternion::MQuaternion(float W, float X, float Y, float Z) +{ + m_xyzw[3] = X; + m_xyzw[0] = Y; + m_xyzw[1] = Z; + m_xyzw[2] = W; +} + +MQuaternion::MQuaternion(float* xyzw) +{ + for (uint8_t i = 0; i < 4; ++i) + m_xyzw[i] = xyzw[i]; +} + +MQuaternion::MQuaternion(const MercuryVertex& p) +{ + m_xyzw[0] = p.GetX(); + m_xyzw[1] = p.GetY(); + m_xyzw[2] = p.GetZ(); + m_xyzw[3] = 0; +} + +float & MQuaternion::operator [] (int i) +{ + switch (i) + { + case 0: return m_xyzw[0]; + case 1: return m_xyzw[1]; + case 2: return m_xyzw[2]; + case 3: return m_xyzw[3]; + } + return m_xyzw[0]; //haha we won't even get here. +} + +void MQuaternion::SetEuler(const MercuryVector& angles) +{ + float X = angles[0]/2.0f; //roll + float Y = angles[1]/2.0f; //pitch + float Z = angles[2]/2.0f; //yaw + + float cx = COS(X); + float sx = SIN(X); + float cy = COS(Y); + float sy = SIN(Y); + float cz = COS(Z); + float sz = SIN(Z); + + //Correct according to + //http://en.wikipedia.org/wiki/Conversion_between_MQuaternions_and_Euler_angles + m_xyzw[3] = cx*cy*cz+sx*sy*sz;//q1 + m_xyzw[0] = sx*cy*cz-cx*sy*sz;//q2 + m_xyzw[1] = cx*sy*cz+sx*cy*sz;//q3 + m_xyzw[2] = cx*cy*sz-sx*sy*cz;//q4 +} + +void MQuaternion::CreateFromAxisAngle(const MercuryVector& p, const float radians) +{ + float sn = SIN(radians/2.0f); + m_xyzw[3] = COS(radians/2.0f); + m_xyzw[0] = sn * p.m_xyzw[0]; + m_xyzw[1] = sn * p.m_xyzw[1]; + m_xyzw[2] = sn * p.m_xyzw[2]; +} + +//Returns the magnitude +float MQuaternion::magnitude() const { + return SQRT((m_xyzw[3]*m_xyzw[3])+(m_xyzw[0]*m_xyzw[0])+(m_xyzw[1]*m_xyzw[1])+(m_xyzw[2]*m_xyzw[2])); +} + +//Returns the normalized MQuaternion +MQuaternion MQuaternion::normalize() const { + return (*this)/magnitude(); +} + +//Returns the conjugate MQuaternion +MQuaternion MQuaternion::conjugate() const { + MQuaternion c(m_xyzw[3],-m_xyzw[0],-m_xyzw[1],-m_xyzw[2]); + return c; +} + +//Returns the reciprocal MQuaternion +MQuaternion MQuaternion::reciprocal() const { + float m = magnitude(); + return conjugate()/(m*m); +} + +//Rotate MQuaternion about another MQuaternion +MQuaternion MQuaternion::rotateAbout(const MQuaternion &spinAxis) const { + return (*this)*spinAxis; +} + +//Converts MQuaternion to 4x4 Matrix(3x3 Spatial) +void MQuaternion::toMatrix( MercuryMatrix &matrix ) const { + float X = 2*m_xyzw[0]*m_xyzw[0]; //Reduced calulation for speed + float Y = 2*m_xyzw[1]*m_xyzw[1]; + float Z = 2*m_xyzw[2]*m_xyzw[2]; + float a = 2*m_xyzw[3]*m_xyzw[0]; + float b = 2*m_xyzw[3]*m_xyzw[1]; + float c = 2*m_xyzw[3]*m_xyzw[2]; + float d = 2*m_xyzw[0]*m_xyzw[1]; + float e = 2*m_xyzw[0]*m_xyzw[2]; + float f = 2*m_xyzw[1]*m_xyzw[2]; + + //row major + matrix[0][0] = 1-Y-Z; + matrix[0][1] = d-c; + matrix[0][2] = e+b; + + matrix[1][0] = d+c; + matrix[1][1] = 1-X-Z; + matrix[1][2] = f-a; + + matrix[2][0] = e-b; + matrix[2][1] = f+a; + matrix[2][2] = 1-X-Y; +} + +void MQuaternion::toMatrix4( MercuryMatrix &matrix ) const { + toMatrix( matrix ); + + //row major (even though it looks like column) + matrix[0][3] = 0; + matrix[1][3] = 0; + matrix[2][3] = 0; + matrix[3][3] = 1; + + matrix[3][0] = 0; + matrix[3][1] = 0; + matrix[3][2] = 0; +} + +MQuaternion MQuaternion::operator + (const MQuaternion &rhs) const +{ + MQuaternion result; + result.m_xyzw[3] = m_xyzw[3] + rhs.m_xyzw[3]; + result.m_xyzw[0] = m_xyzw[0] + rhs.m_xyzw[0]; + result.m_xyzw[1] = m_xyzw[1] + rhs.m_xyzw[1]; + result.m_xyzw[2] = m_xyzw[2] + rhs.m_xyzw[2]; + return result; +} + +MQuaternion MQuaternion::operator - (const MQuaternion &rhs) const +{ + MQuaternion result; + result.m_xyzw[3] = m_xyzw[3] - rhs.m_xyzw[3]; + result.m_xyzw[0] = m_xyzw[0] - rhs.m_xyzw[0]; + result.m_xyzw[1] = m_xyzw[1] - rhs.m_xyzw[1]; + result.m_xyzw[2] = m_xyzw[2] - rhs.m_xyzw[2]; + return result; +} + +MQuaternion MQuaternion::operator * (const MQuaternion &rhs) const +{ + MQuaternion result; + result.m_xyzw[3] = (m_xyzw[3]*rhs.m_xyzw[3])-(m_xyzw[0]*rhs.m_xyzw[0])-(m_xyzw[1]*rhs.m_xyzw[1])-(m_xyzw[2]*rhs.m_xyzw[2]); + result.m_xyzw[0] = (m_xyzw[3]*rhs.m_xyzw[0])+(m_xyzw[0]*rhs.m_xyzw[3])+(m_xyzw[1]*rhs.m_xyzw[2])-(m_xyzw[2]*rhs.m_xyzw[1]); + result.m_xyzw[1] = (m_xyzw[3]*rhs.m_xyzw[1])-(m_xyzw[0]*rhs.m_xyzw[2])+(m_xyzw[1]*rhs.m_xyzw[3])+(m_xyzw[2]*rhs.m_xyzw[0]); + result.m_xyzw[2] = (m_xyzw[3]*rhs.m_xyzw[2])+(m_xyzw[0]*rhs.m_xyzw[1])-(m_xyzw[1]*rhs.m_xyzw[0])+(m_xyzw[2]*rhs.m_xyzw[3]); + return result; +} + +MQuaternion& MQuaternion::operator = (const MQuaternion &rhs) +{ + m_xyzw[3] = rhs.m_xyzw[3]; + m_xyzw[0] = rhs.m_xyzw[0]; + m_xyzw[1] = rhs.m_xyzw[1]; + m_xyzw[2] = rhs.m_xyzw[2]; + return (*this); +} + +MQuaternion& MQuaternion::operator += (const MQuaternion &rhs) { + m_xyzw[3] += rhs.m_xyzw[3]; + m_xyzw[0] += rhs.m_xyzw[0]; + m_xyzw[1] += rhs.m_xyzw[1]; + m_xyzw[2] += rhs.m_xyzw[2]; + return (*this); +} + +MQuaternion& MQuaternion::operator -= (const MQuaternion &rhs) { + m_xyzw[3] -= rhs.m_xyzw[3]; + m_xyzw[0] -= rhs.m_xyzw[0]; + m_xyzw[1] -= rhs.m_xyzw[1]; + m_xyzw[2] -= rhs.m_xyzw[2]; + return (*this); +} + +MQuaternion& MQuaternion::operator *= (const MQuaternion &rhs) { + m_xyzw[3] = (m_xyzw[3]*rhs.m_xyzw[3])-(m_xyzw[0]*rhs.m_xyzw[0])-(m_xyzw[1]*rhs.m_xyzw[1])-(m_xyzw[2]*rhs.m_xyzw[2]); + m_xyzw[0] = (m_xyzw[3]*rhs.m_xyzw[0])+(m_xyzw[0]*rhs.m_xyzw[3])+(m_xyzw[1]*rhs.m_xyzw[2])-(m_xyzw[2]*rhs.m_xyzw[1]); + m_xyzw[1] = (m_xyzw[3]*rhs.m_xyzw[1])-(m_xyzw[0]*rhs.m_xyzw[2])+(m_xyzw[1]*rhs.m_xyzw[3])+(m_xyzw[2]*rhs.m_xyzw[0]); + m_xyzw[2] = (m_xyzw[3]*rhs.m_xyzw[2])+(m_xyzw[0]*rhs.m_xyzw[1])-(m_xyzw[1]*rhs.m_xyzw[0])+(m_xyzw[2]*rhs.m_xyzw[3]); + return (*this); +} + +MQuaternion MQuaternion::operator * (const float &rhs) const { + MQuaternion result; + result.m_xyzw[3] = m_xyzw[3]*rhs; + result.m_xyzw[0] = m_xyzw[0]*rhs; + result.m_xyzw[1] = m_xyzw[1]*rhs; + result.m_xyzw[2] = m_xyzw[2]*rhs; + return result; +} + +MQuaternion MQuaternion::operator / (const float &rhs) const { + MQuaternion result; + result.m_xyzw[3] = m_xyzw[3]/rhs; + result.m_xyzw[0] = m_xyzw[0]/rhs; + result.m_xyzw[1] = m_xyzw[1]/rhs; + result.m_xyzw[2] = m_xyzw[2]/rhs; + return result; +} + +MQuaternion& MQuaternion::operator *= (const float &rhs) { + m_xyzw[3] *= rhs; + m_xyzw[0] *= rhs; + m_xyzw[1] *= rhs; + m_xyzw[2] *= rhs; + return (*this); +} + +MQuaternion& MQuaternion::operator /= (const float &rhs) { + m_xyzw[3] /= rhs; + m_xyzw[0] /= rhs; + m_xyzw[1] /= rhs; + m_xyzw[2] /= rhs; + return (*this); +} + +//Returns the Euclidian Inner Product of two MQuaternions (Similar to Vector Dot-Product) +float innerProduct(const MQuaternion & a, const MQuaternion &b) +{ + return (a.m_xyzw[3]*b.m_xyzw[3])+(a.m_xyzw[0]*b.m_xyzw[0])+(a.m_xyzw[1]*b.m_xyzw[1])+(a.m_xyzw[2]*b.m_xyzw[2]); +} + +//Returns the Euclidian Outer Product of two MQuaternions +MercuryVector outerProduct(MQuaternion a,MQuaternion b) +{ + MercuryVector result; + result.m_xyzw[0] = (a.m_xyzw[3]*b.m_xyzw[0])-(a.m_xyzw[0]*b.m_xyzw[3])-(a.m_xyzw[1]*b.m_xyzw[2])+(a.m_xyzw[2]*b.m_xyzw[1]); + result.m_xyzw[1] = (a.m_xyzw[3]*b.m_xyzw[1])+(a.m_xyzw[0]*b.m_xyzw[2])-(a.m_xyzw[1]*b.m_xyzw[3])-(a.m_xyzw[2]*b.m_xyzw[0]); + result.m_xyzw[2] = (a.m_xyzw[3]*b.m_xyzw[2])-(a.m_xyzw[0]*b.m_xyzw[1])+(a.m_xyzw[1]*b.m_xyzw[0])-(a.m_xyzw[2]*b.m_xyzw[3]); + return result; +} + +//Returns the Even Product of two MQuaternions +MQuaternion evenProduct(MQuaternion a,MQuaternion b) { + MQuaternion result; + result.m_xyzw[3] = (a.m_xyzw[3]*b.m_xyzw[3])-(a.m_xyzw[0]*b.m_xyzw[0])-(a.m_xyzw[1]*b.m_xyzw[1])-(a.m_xyzw[2]*b.m_xyzw[2]); + result.m_xyzw[0] = (a.m_xyzw[3]*b.m_xyzw[0])+(a.m_xyzw[0]*b.m_xyzw[3]); + result.m_xyzw[1] = (a.m_xyzw[3]*b.m_xyzw[1])+(a.m_xyzw[1]*b.m_xyzw[3]); + result.m_xyzw[2] = (a.m_xyzw[3]*b.m_xyzw[2])+(a.m_xyzw[2]*b.m_xyzw[3]); + return result; +} + +//Returns the Odd Product of two MQuaternions (Similar to Vector Cross-Product) +MercuryVector oddProduct(MQuaternion a,MQuaternion b) { + MercuryVector result; + result.m_xyzw[0] = (a.m_xyzw[1]*b.m_xyzw[2])-(a.m_xyzw[2]*b.m_xyzw[1]); + result.m_xyzw[1] = (a.m_xyzw[2]*b.m_xyzw[0])-(a.m_xyzw[0]*b.m_xyzw[2]); + result.m_xyzw[2] = (a.m_xyzw[0]*b.m_xyzw[1])-(a.m_xyzw[1]*b.m_xyzw[0]); + return result; +} + +//Spherical Linear Interpolation between two MQuaternions at t percent completion(0-1) +MQuaternion SLERP( const MQuaternion &a, const MQuaternion &b,float t) { + MQuaternion an = a.normalize(), bn = b.normalize(); + float cosTheta = innerProduct(MQuaternion(an),bn); + float sinTheta; + + //Careful: If cosTheta is exactly one, or even if it's infinitesimally over, it'll + // cause SQRT to produce not a number, and screw everything up. + if ( 1 - (cosTheta*cosTheta) <= 0 ) + sinTheta = 0; + else + sinTheta = SQRT(1 - (cosTheta*cosTheta)); + + float Theta = ACOS(cosTheta); //Theta is half the angle between the 2 MQuaternions + + if(fabs(Theta) < 0.01) + return a; + if(fabs(sinTheta) < 0.01) + return (a+b)/2; + return ( (a*SIN((1-t)*Theta)) + (b*SIN(t*Theta)) ) / sinTheta; +} + +bool MQuaternion::operator==(const MQuaternion& p) const +{ + for (unsigned int i = 0; i < 4; ++i) + if (m_xyzw[i] != p.m_xyzw[i]) return false; + return true; +} + +void AngleMatrix (const MercuryVector & angles, MercuryMatrix & matrix ) +{ + float X = angles[0]*2*Q_PI/360; //Reduced calulation for speed + float Y = angles[1]*2*Q_PI/360; + float Z = angles[2]*2*Q_PI/360; + float cx = COS(X); + float sx = SIN(X); + float cy = COS(Y); + float sy = SIN(Y); + float cz = COS(Z); + float sz = SIN(Z); + + //Row major + matrix[0][0] = cy*cz; + matrix[0][1] = (sx*sy*cz)-(cx*sz); + matrix[0][2] = (cx*sy*cz)+(sx*sz); + matrix[0][3] = 0; + + matrix[1][0] = cy*sz; + matrix[1][1] = (sx*sy*sz)+(cx*cz); + matrix[1][2] = (cx*sy*sz)-(sx*cz); + matrix[1][3] = 0; + + matrix[2][0] = -sy; + matrix[2][1] = sx*cy; + matrix[2][2] = cx*cy; + matrix[2][3] = 0; + + matrix[3][0] = 0; + matrix[3][1] = 0; + matrix[3][2] = 0; + matrix[3][3] = 1; +} + +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen, Charles Lohr, Adam Lowman * + * * + * * + * All rights reserved. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the following disclaimer. * + * * 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. * + * * Neither the name of the Mercury Engine nor the names of its * + * contributors may be used to endorse or promote products derived * + * from this software without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "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 THE COPYRIGHT * + * OWNER 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. * + ***************************************************************************/ Added: Mercury2/src/MQuaternion.h =================================================================== --- Mercury2/src/MQuaternion.h (rev 0) +++ Mercury2/src/MQuaternion.h 2009-05-22 01:28:54 UTC (rev 271) @@ -0,0 +1,100 @@ +#ifndef MQUATERNION_H +#define MQUATERNION_H + +#include <MercuryVertex.h> +#include <MercuryMatrix.h> + +///Mathematical Quaternion (Used for Rotation) +class MQuaternion { + public: + //Defines a Quaternion such that q = w + xi + yj + zk + float m_xyzw[4]; + MQuaternion(float W = 0, float X = 0, float Y = 0, float Z = 0); + MQuaternion(float* wxyz); + MQuaternion(const MercuryVertex& p); + + ///Make this quaternion represent to a set of euler angles + void SetEuler(const MercuryVertex& angles); + + ///Make the quaternion represent a given angle radians around an axis p + void CreateFromAxisAngle(const MercuryVertex& p, const float radians); + + ///Access a component of the quaternion with the [] operator + float & operator[] ( const int rhs ); + const float & operator[] ( const int rhs ) const; + + ///Returns the magnitude + float magnitude() const; + ///Returns the normalized Quaternion + MQuaternion normalize() const; + ///Returns the conjugate Quaternion + MQuaternion conjugate() const; + ///Returns the reciprocal Quaternion + MQuaternion reciprocal() const; + ///Rotates Quaternion about another Quaternion + MQuaternion rotateAbout(const MQuaternion &spinAxis) const; + ///Converts Quaternion to 4x4 Matrix(3x3 Spatial) + void toMatrix( MercuryMatrix & mat ) const; + ///Converts Quaternion to complete 4x4 Matrix + void toMatrix4( MercuryMatrix & mat ) const; + ///Convert the quaternion to a point. + MercuryVertex ToVertex() { return MercuryVertex( m_xyzw[0],m_xyzw[1],m_xyzw[2] ); } + + /****************************************************** + * NOTE: Quaternion multipication is not commutative * + * Therefore the / operator could imply for a/b * + * a*b.reciprocal() or b.reciprocal()*a * + ******************************************************/ + MQuaternion operator + (const MQuaternion &rhs) const; + MQuaternion operator - (const MQuaternion &rhs) const; + MQuaternion operator * (const MQuaternion &rhs) const; + MQuaternion& operator = (const MQuaternion &rhs); + MQuaternion& operator += (const MQuaternion &rhs); + MQuaternion& operator -= (const MQuaternion &rhs); + MQuaternion& operator *= (const MQuaternion &rhs); + MQuaternion operator * (const float &rhs) const; + MQuaternion operator / (const float &rhs) const; + MQuaternion& operator *= (const float &rhs); + MQuaternion& operator /= (const float &rhs); + + bool operator==(const MQuaternion& p) const; + inline bool operator!=(const MQuaternion& p) const { return !(*this == p); } + +} M_ALIGN(32); + +///Produce a matrix out of a rotation x, then y then z (how Mercury does it) +void AngleMatrix (const MercuryVector & angles, MercuryMatrix & mat ); + +#endif + +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen, Charles Lohr, Adam Lowman * + * * + * * + * All rights reserved. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the following disclaimer. * + * * 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. * + * * Neither the name of the Mercury Engine nor the names of its * + * contributors may be used to endorse or promote products derived * + * from this software without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "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 THE COPYRIGHT * + * OWNER 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. * + ***************************************************************************/ Modified: Mercury2/src/TransformNode.cpp =================================================================== --- Mercury2/src/TransformNode.cpp 2009-05-19 00:21:56 UTC (rev 270) +++ Mercury2/src/TransformNode.cpp 2009-05-22 01:28:54 UTC (rev 271) @@ -32,7 +32,7 @@ } } -void TransformNode::SetRotation( const MercuryVertex& rotation ) +void TransformNode::SetRotation( const MQuaternion& rotation ) { if (rotation != m_rotation) { @@ -94,17 +94,18 @@ void TransformNode::LoadFromXML(const XMLNode& node) { - MercuryVertex rot(m_rotation), pos(m_position), scale(m_scale); + MercuryVertex pos(m_position), scale(m_scale); + MQuaternion rot(m_rotation); //only change the values that exist in the XML if ( !node.Attribute("rotx").empty() ) - rot.SetX( StrToFloat( node.Attribute("rotx") ) ); + rot[0] = StrToFloat( node.Attribute("rotx") ); if ( !node.Attribute("roty").empty() ) - rot.SetY( StrToFloat( node.Attribute("roty") ) ); + rot[1] = StrToFloat( node.Attribute("roty") ); if ( !node.Attribute("rotz").empty() ) - rot.SetZ( StrToFloat( node.Attribute("rotz") ) ); + rot[2] = StrToFloat( node.Attribute("rotz") ); if ( !node.Attribute("scalex").empty() ) scale.SetX( StrToFloat( node.Attribute("scalex") ) ); @@ -150,7 +151,7 @@ void RotatorNode::Update(float dTime) { - float* r = m_rotation; + MQuaternion r = m_rotation; r[0] += (dTime)*25; r[1] += (dTime)*75; Modified: Mercury2/src/TransformNode.h =================================================================== --- Mercury2/src/TransformNode.h 2009-05-19 00:21:56 UTC (rev 270) +++ Mercury2/src/TransformNode.h 2009-05-22 01:28:54 UTC (rev 271) @@ -4,6 +4,7 @@ #include <MercuryNode.h> #include <MercuryVertex.h> #include <MercuryMatrix.h> +#include <MQuaternion.h> //I am not sure if I like the idea of rippling a taint flag down the tree //if a transform hs changed. There is probably a better way of doing this. @@ -16,11 +17,11 @@ void SetScale( const MercuryVertex& scale ); void SetPosition( const MercuryVertex& position ); - void SetRotation( const MercuryVertex& rotation ); + void SetRotation( const MQuaternion& rotation ); inline const MercuryVertex& GetScale() const { return m_scale; } inline const MercuryVertex& GetPosition() const { return m_position; } - inline const MercuryVertex& GetRotation() const { return m_rotation; } + inline const MQuaternion& GetRotation() const { return m_rotation; } inline const MercuryMatrix& GetGlobalMatrix() const { return m_globalMatrix; } const MercuryMatrix& GetParentMatrix() const; @@ -42,7 +43,8 @@ protected: MercuryVertex m_scale; MercuryVertex m_position; - MercuryVertex m_rotation; +// MercuryVertex m_rotation; + MQuaternion m_rotation; MercuryMatrix m_globalMatrix; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-26 01:14:47
|
Revision: 275 http://hgengine.svn.sourceforge.net/hgengine/?rev=275&view=rev Author: axlecrusher Date: 2009-05-26 00:28:09 +0000 (Tue, 26 May 2009) Log Message: ----------- capture mouse button Modified Paths: -------------- Mercury2/src/MercuryInput.cpp Mercury2/src/MercuryInput.h Mercury2/src/X11Window.cpp Modified: Mercury2/src/MercuryInput.cpp =================================================================== --- Mercury2/src/MercuryInput.cpp 2009-05-26 00:27:12 UTC (rev 274) +++ Mercury2/src/MercuryInput.cpp 2009-05-26 00:28:09 UTC (rev 275) @@ -6,12 +6,20 @@ { } -void MouseInput::ProcessMouseInput(int dx, int dy) +void MouseInput::ProcessMouseInput(int dx, int dy, bool leftButton, bool rightButton, bool centerButton) { MouseInput* mi = new MouseInput(); mi->dx = dx; mi->dy = dy; + uint8_t buttonMasks = 0; + buttonMasks |= (leftButton << MB_LEFT); //enable if true + buttonMasks |= (rightButton << MB_RIGHT); //enable if true + buttonMasks |= (centerButton << MB_CENTER); //enable if true + mi->buttonMasks = buttonMasks; + + currentButtonMasks = buttonMasks; + POST_MESSAGE( INPUTEVENT_MOUSE, mi, 0 ); } @@ -57,6 +65,7 @@ uint8_t KeyboardInput::m_keyStates[512]; +uint8_t MouseInput::currentButtonMasks; /**************************************************************************** Modified: Mercury2/src/MercuryInput.h =================================================================== --- Mercury2/src/MercuryInput.h 2009-05-26 00:27:12 UTC (rev 274) +++ Mercury2/src/MercuryInput.h 2009-05-26 00:28:09 UTC (rev 275) @@ -6,18 +6,24 @@ const MString INPUTEVENT_MOUSE = "MouseInputEvent"; const MString INPUTEVENT_KEYBOARD = "KeyboardInputEvent"; +enum MouseButton +{ + MB_NONE = 0, + MB_LEFT = 1, + MB_RIGHT = 2, + MB_CENTER = 3 +}; + class MouseInput : public MessageData { public: - static const uint8_t LEFTBUTTON = 1; - static const uint8_t RIGHTBUTTON = 2; - static const uint8_t CENTERBUTTON = 4; + static void ProcessMouseInput(int dx, int dy, bool leftButton, bool rightButton, bool centerButton); - static void ProcessMouseInput(int x, int y); - MouseInput(); int32_t dx, dy; uint8_t buttonMasks; + private: + static uint8_t currentButtonMasks; }; class KeyboardInput : public MessageData Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-05-26 00:27:12 UTC (rev 274) +++ Mercury2/src/X11Window.cpp 2009-05-26 00:28:09 UTC (rev 275) @@ -143,13 +143,10 @@ switch (event.type) { case ButtonPress: - { - XButtonEvent* e = (XButtonEvent*)&event; - break; - } case ButtonRelease: { XButtonEvent* e = (XButtonEvent*)&event; + MouseInput::ProcessMouseInput(0, 0, e->button & Button1, e->button & Button3, e->button & Button2); break; } case KeyPress: @@ -172,11 +169,16 @@ { XMotionEvent* e = (XMotionEvent*)&event; int x, y; + bool left, right, center; + left = e->state & Button1Mask; + right = e->state & Button3Mask; + center = e->state & Button2Mask; x = m_width/2 - e->x; y = m_height/2 - e->y; if (x!=0 || y!=0) //prevent recursive XWarp { - MouseInput::ProcessMouseInput(x, y); + MouseInput::ProcessMouseInput(x, y, + left, right, center); XWarpPointer(m_display, None, m_window, 0,0,0,0,m_width/2,m_height/2); } break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-31 00:53:22
|
Revision: 281 http://hgengine.svn.sourceforge.net/hgengine/?rev=281&view=rev Author: axlecrusher Date: 2009-05-31 00:53:17 +0000 (Sun, 31 May 2009) Log Message: ----------- W is component 0 Modified Paths: -------------- Mercury2/src/MQuaternion.cpp Mercury2/src/MQuaternion.h Modified: Mercury2/src/MQuaternion.cpp =================================================================== --- Mercury2/src/MQuaternion.cpp 2009-05-26 03:38:08 UTC (rev 280) +++ Mercury2/src/MQuaternion.cpp 2009-05-31 00:53:17 UTC (rev 281) @@ -1,34 +1,36 @@ #include <MQuaternion.h> #include <MercuryMath.h> -MQuaternion::MQuaternion(float W, float X, float Y, float Z) +MQuaternion::MQuaternion() { - m_xyzw[0] = X; - m_xyzw[1] = Y; - m_xyzw[2] = Z; - m_xyzw[3] = W; + m_wxyz[0] = 0; + m_wxyz[1] = 0; + m_wxyz[2] = 0; + m_wxyz[3] = 0; } -MQuaternion::MQuaternion(float* xyzw) +MQuaternion::MQuaternion(float W, float X, float Y, float Z) { - for (uint8_t i = 0; i < 4; ++i) - m_xyzw[i] = xyzw[i]; + m_wxyz[0] = W; + m_wxyz[1] = X; + m_wxyz[2] = Y; + m_wxyz[3] = Z; } -MQuaternion::MQuaternion(const MercuryVertex& p) +MQuaternion::MQuaternion(float W, const MercuryVertex& p) { - m_xyzw[0] = p.GetX(); - m_xyzw[1] = p.GetY(); - m_xyzw[2] = p.GetZ(); - m_xyzw[3] = 0; + m_wxyz[0] = W; + m_wxyz[1] = p[0]; + m_wxyz[2] = p[1]; + m_wxyz[3] = p[2]; } float & MQuaternion::operator [] (int i) { - return m_xyzw[i]; + return m_wxyz[i]; //haha we won't even get here. } -void MQuaternion::SetEuler(const MercuryVector& angles) +void MQuaternion::SetEuler(const MercuryVertex& angles) { float X = angles[0]/2.0f; //roll float Y = angles[1]/2.0f; //pitch @@ -43,24 +45,24 @@ //Correct according to //http://en.wikipedia.org/wiki/Conversion_between_MQuaternions_and_Euler_angles - m_xyzw[3] = cx*cy*cz+sx*sy*sz;//q1 - m_xyzw[0] = sx*cy*cz-cx*sy*sz;//q2 - m_xyzw[1] = cx*sy*cz+sx*cy*sz;//q3 - m_xyzw[2] = cx*cy*sz-sx*sy*cz;//q4 + m_wxyz[0] = cx*cy*cz+sx*sy*sz;//q1 + m_wxyz[1] = sx*cy*cz-cx*sy*sz;//q2 + m_wxyz[2] = cx*sy*cz+sx*cy*sz;//q3 + m_wxyz[3] = cx*cy*sz-sx*sy*cz;//q4 } -void MQuaternion::CreateFromAxisAngle(const MercuryVector& p, const float radians) +void MQuaternion::CreateFromAxisAngle(const MercuryVertex& p, const float radians) { float sn = SIN(radians/2.0f); - m_xyzw[3] = COS(radians/2.0f); - m_xyzw[0] = sn * p.m_xyzw[0]; - m_xyzw[1] = sn * p.m_xyzw[1]; - m_xyzw[2] = sn * p.m_xyzw[2]; + m_wxyz[0] = COS(radians/2.0f); + m_wxyz[1] = sn * p[0]; + m_wxyz[2] = sn * p[1]; + m_wxyz[3] = sn * p[2]; } //Returns the magnitude float MQuaternion::magnitude() const { - return SQRT((m_xyzw[3]*m_xyzw[3])+(m_xyzw[0]*m_xyzw[0])+(m_xyzw[1]*m_xyzw[1])+(m_xyzw[2]*m_xyzw[2])); + return SQRT((m_wxyz[0]*m_wxyz[0])+(m_wxyz[1]*m_wxyz[1])+(m_wxyz[2]*m_wxyz[2])+(m_wxyz[3]*m_wxyz[3])); } //Returns the normalized MQuaternion @@ -70,7 +72,7 @@ //Returns the conjugate MQuaternion MQuaternion MQuaternion::conjugate() const { - MQuaternion c(m_xyzw[3],-m_xyzw[0],-m_xyzw[1],-m_xyzw[2]); + MQuaternion c(m_wxyz[0],-m_wxyz[1],-m_wxyz[2],-m_wxyz[3]); return c; } @@ -87,15 +89,15 @@ //Converts MQuaternion to 4x4 Matrix(3x3 Spatial) void MQuaternion::toMatrix( MercuryMatrix &matrix ) const { - float X = 2*m_xyzw[0]*m_xyzw[0]; //Reduced calulation for speed - float Y = 2*m_xyzw[1]*m_xyzw[1]; - float Z = 2*m_xyzw[2]*m_xyzw[2]; - float a = 2*m_xyzw[3]*m_xyzw[0]; - float b = 2*m_xyzw[3]*m_xyzw[1]; - float c = 2*m_xyzw[3]*m_xyzw[2]; - float d = 2*m_xyzw[0]*m_xyzw[1]; - float e = 2*m_xyzw[0]*m_xyzw[2]; - float f = 2*m_xyzw[1]*m_xyzw[2]; + float X = 2*m_wxyz[1]*m_wxyz[1]; //Reduced calulation for speed + float Y = 2*m_wxyz[2]*m_wxyz[2]; + float Z = 2*m_wxyz[3]*m_wxyz[3]; + float a = 2*m_wxyz[0]*m_wxyz[1]; + float b = 2*m_wxyz[0]*m_wxyz[2]; + float c = 2*m_wxyz[0]*m_wxyz[3]; + float d = 2*m_wxyz[1]*m_wxyz[2]; + float e = 2*m_wxyz[1]*m_wxyz[3]; + float f = 2*m_wxyz[2]*m_wxyz[3]; //row major matrix[0][0] = 1-Y-Z; @@ -128,132 +130,131 @@ MQuaternion MQuaternion::operator + (const MQuaternion &rhs) const { MQuaternion result; - result.m_xyzw[3] = m_xyzw[3] + rhs.m_xyzw[3]; - result.m_xyzw[0] = m_xyzw[0] + rhs.m_xyzw[0]; - result.m_xyzw[1] = m_xyzw[1] + rhs.m_xyzw[1]; - result.m_xyzw[2] = m_xyzw[2] + rhs.m_xyzw[2]; + for (uint8_t i = 0; i < 4; ++i) + result.m_wxyz[i] = m_wxyz[i]+rhs.m_wxyz[i]; return result; } MQuaternion MQuaternion::operator - (const MQuaternion &rhs) const { MQuaternion result; - result.m_xyzw[3] = m_xyzw[3] - rhs.m_xyzw[3]; - result.m_xyzw[0] = m_xyzw[0] - rhs.m_xyzw[0]; - result.m_xyzw[1] = m_xyzw[1] - rhs.m_xyzw[1]; - result.m_xyzw[2] = m_xyzw[2] - rhs.m_xyzw[2]; + for (uint8_t i = 0; i < 4; ++i) + result.m_wxyz[i] = m_wxyz[i]-rhs.m_wxyz[i]; return result; } MQuaternion MQuaternion::operator * (const MQuaternion &rhs) const { MQuaternion result; - result.m_xyzw[3] = (m_xyzw[3]*rhs.m_xyzw[3])-(m_xyzw[0]*rhs.m_xyzw[0])-(m_xyzw[1]*rhs.m_xyzw[1])-(m_xyzw[2]*rhs.m_xyzw[2]); - result.m_xyzw[0] = (m_xyzw[3]*rhs.m_xyzw[0])+(m_xyzw[0]*rhs.m_xyzw[3])+(m_xyzw[1]*rhs.m_xyzw[2])-(m_xyzw[2]*rhs.m_xyzw[1]); - result.m_xyzw[1] = (m_xyzw[3]*rhs.m_xyzw[1])-(m_xyzw[0]*rhs.m_xyzw[2])+(m_xyzw[1]*rhs.m_xyzw[3])+(m_xyzw[2]*rhs.m_xyzw[0]); - result.m_xyzw[2] = (m_xyzw[3]*rhs.m_xyzw[2])+(m_xyzw[0]*rhs.m_xyzw[1])-(m_xyzw[1]*rhs.m_xyzw[0])+(m_xyzw[2]*rhs.m_xyzw[3]); + result.m_wxyz[0] = (m_wxyz[0]*rhs.m_wxyz[0])-(m_wxyz[1]*rhs.m_wxyz[1])-(m_wxyz[2]*rhs.m_wxyz[2])-(m_wxyz[3]*rhs.m_wxyz[3]); + result.m_wxyz[1] = (m_wxyz[0]*rhs.m_wxyz[1])+(m_wxyz[1]*rhs.m_wxyz[0])+(m_wxyz[2]*rhs.m_wxyz[3])-(m_wxyz[3]*rhs.m_wxyz[2]); + result.m_wxyz[2] = (m_wxyz[0]*rhs.m_wxyz[2])-(m_wxyz[1]*rhs.m_wxyz[3])+(m_wxyz[2]*rhs.m_wxyz[0])+(m_wxyz[3]*rhs.m_wxyz[1]); + result.m_wxyz[3] = (m_wxyz[0]*rhs.m_wxyz[3])+(m_wxyz[1]*rhs.m_wxyz[2])-(m_wxyz[2]*rhs.m_wxyz[1])+(m_wxyz[3]*rhs.m_wxyz[0]); return result; } MQuaternion& MQuaternion::operator = (const MQuaternion &rhs) { - m_xyzw[3] = rhs.m_xyzw[3]; - m_xyzw[0] = rhs.m_xyzw[0]; - m_xyzw[1] = rhs.m_xyzw[1]; - m_xyzw[2] = rhs.m_xyzw[2]; + for (uint8_t i = 0; i < 4; ++i) + m_wxyz[i] = rhs.m_wxyz[i]; return (*this); } MQuaternion& MQuaternion::operator += (const MQuaternion &rhs) { - m_xyzw[3] += rhs.m_xyzw[3]; - m_xyzw[0] += rhs.m_xyzw[0]; - m_xyzw[1] += rhs.m_xyzw[1]; - m_xyzw[2] += rhs.m_xyzw[2]; + for (uint8_t i = 0; i < 4; ++i) + m_wxyz[i] += rhs.m_wxyz[i]; return (*this); } MQuaternion& MQuaternion::operator -= (const MQuaternion &rhs) { - m_xyzw[3] -= rhs.m_xyzw[3]; - m_xyzw[0] -= rhs.m_xyzw[0]; - m_xyzw[1] -= rhs.m_xyzw[1]; - m_xyzw[2] -= rhs.m_xyzw[2]; + for (uint8_t i = 0; i < 4; ++i) + m_wxyz[i] -= rhs.m_wxyz[i]; return (*this); } MQuaternion& MQuaternion::operator *= (const MQuaternion &rhs) { - m_xyzw[3] = (m_xyzw[3]*rhs.m_xyzw[3])-(m_xyzw[0]*rhs.m_xyzw[0])-(m_xyzw[1]*rhs.m_xyzw[1])-(m_xyzw[2]*rhs.m_xyzw[2]); - m_xyzw[0] = (m_xyzw[3]*rhs.m_xyzw[0])+(m_xyzw[0]*rhs.m_xyzw[3])+(m_xyzw[1]*rhs.m_xyzw[2])-(m_xyzw[2]*rhs.m_xyzw[1]); - m_xyzw[1] = (m_xyzw[3]*rhs.m_xyzw[1])-(m_xyzw[0]*rhs.m_xyzw[2])+(m_xyzw[1]*rhs.m_xyzw[3])+(m_xyzw[2]*rhs.m_xyzw[0]); - m_xyzw[2] = (m_xyzw[3]*rhs.m_xyzw[2])+(m_xyzw[0]*rhs.m_xyzw[1])-(m_xyzw[1]*rhs.m_xyzw[0])+(m_xyzw[2]*rhs.m_xyzw[3]); + m_wxyz[0] = (m_wxyz[0]*rhs.m_wxyz[0])-(m_wxyz[1]*rhs.m_wxyz[1])-(m_wxyz[2]*rhs.m_wxyz[2])-(m_wxyz[3]*rhs.m_wxyz[3]); + m_wxyz[1] = (m_wxyz[0]*rhs.m_wxyz[1])+(m_wxyz[1]*rhs.m_wxyz[0])+(m_wxyz[2]*rhs.m_wxyz[3])-(m_wxyz[3]*rhs.m_wxyz[2]); + m_wxyz[2] = (m_wxyz[0]*rhs.m_wxyz[2])-(m_wxyz[1]*rhs.m_wxyz[3])+(m_wxyz[2]*rhs.m_wxyz[0])+(m_wxyz[3]*rhs.m_wxyz[1]); + m_wxyz[3] = (m_wxyz[0]*rhs.m_wxyz[3])+(m_wxyz[1]*rhs.m_wxyz[2])-(m_wxyz[2]*rhs.m_wxyz[1])+(m_wxyz[3]*rhs.m_wxyz[0]); return (*this); } MQuaternion MQuaternion::operator * (const float &rhs) const { MQuaternion result; - result.m_xyzw[3] = m_xyzw[3]*rhs; - result.m_xyzw[0] = m_xyzw[0]*rhs; - result.m_xyzw[1] = m_xyzw[1]*rhs; - result.m_xyzw[2] = m_xyzw[2]*rhs; + for (uint8_t i = 0; i < 4; ++i) + result.m_wxyz[i] = m_wxyz[i]*rhs; return result; } MQuaternion MQuaternion::operator / (const float &rhs) const { MQuaternion result; - result.m_xyzw[3] = m_xyzw[3]/rhs; - result.m_xyzw[0] = m_xyzw[0]/rhs; - result.m_xyzw[1] = m_xyzw[1]/rhs; - result.m_xyzw[2] = m_xyzw[2]/rhs; + for (uint8_t i = 0; i < 4; ++i) + result.m_wxyz[i] = m_wxyz[i]/rhs; return result; } -MQuaternion& MQuaternion::operator *= (const float &rhs) { - m_xyzw[3] *= rhs; - m_xyzw[0] *= rhs; - m_xyzw[1] *= rhs; - m_xyzw[2] *= rhs; +MQuaternion& MQuaternion::operator *= (const float &rhs) +{ + for (uint8_t i = 0; i < 4; ++i) + m_wxyz[i] *= rhs; return (*this); } -MQuaternion& MQuaternion::operator /= (const float &rhs) { - m_xyzw[3] /= rhs; - m_xyzw[0] /= rhs; - m_xyzw[1] /= rhs; - m_xyzw[2] /= rhs; +MQuaternion& MQuaternion::operator /= (const float &rhs) +{ + for (uint8_t i = 0; i < 4; ++i) + m_wxyz[i] /= rhs; return (*this); } +bool MQuaternion::operator==(const MQuaternion &rhs) const +{ + for (uint8_t i = 0; i < 4; ++i) + if (m_wxyz[i] != rhs.m_wxyz[i]) return false; + return true; +} + +MercuryVertex MQuaternion::ToVertex() const +{ + MercuryVertex v(m_wxyz[1], m_wxyz[2], m_wxyz[3], m_wxyz[0]); + return v; +} + + + //Returns the Euclidian Inner Product of two MQuaternions (Similar to Vector Dot-Product) float innerProduct(const MQuaternion & a, const MQuaternion &b) { - return (a.m_xyzw[3]*b.m_xyzw[3])+(a.m_xyzw[0]*b.m_xyzw[0])+(a.m_xyzw[1]*b.m_xyzw[1])+(a.m_xyzw[2]*b.m_xyzw[2]); + return (a.m_wxyz[0]*b.m_wxyz[0])+(a.m_wxyz[1]*b.m_wxyz[1])+(a.m_wxyz[2]*b.m_wxyz[2])+(a.m_wxyz[3]*b.m_wxyz[3]); } //Returns the Euclidian Outer Product of two MQuaternions -MercuryVector outerProduct(MQuaternion a,MQuaternion b) +MercuryVertex outerProduct(MQuaternion a,MQuaternion b) { - MercuryVector result; - result.m_xyzw[0] = (a.m_xyzw[3]*b.m_xyzw[0])-(a.m_xyzw[0]*b.m_xyzw[3])-(a.m_xyzw[1]*b.m_xyzw[2])+(a.m_xyzw[2]*b.m_xyzw[1]); - result.m_xyzw[1] = (a.m_xyzw[3]*b.m_xyzw[1])+(a.m_xyzw[0]*b.m_xyzw[2])-(a.m_xyzw[1]*b.m_xyzw[3])-(a.m_xyzw[2]*b.m_xyzw[0]); - result.m_xyzw[2] = (a.m_xyzw[3]*b.m_xyzw[2])-(a.m_xyzw[0]*b.m_xyzw[1])+(a.m_xyzw[1]*b.m_xyzw[0])-(a.m_xyzw[2]*b.m_xyzw[3]); + MercuryVertex result; + result[0] = (a.m_wxyz[0]*b.m_wxyz[1])-(a.m_wxyz[1]*b.m_wxyz[0])-(a.m_wxyz[2]*b.m_wxyz[3])+(a.m_wxyz[3]*b.m_wxyz[2]); + result[1] = (a.m_wxyz[0]*b.m_wxyz[2])+(a.m_wxyz[1]*b.m_wxyz[3])-(a.m_wxyz[2]*b.m_wxyz[0])-(a.m_wxyz[3]*b.m_wxyz[1]); + result[2] = (a.m_wxyz[0]*b.m_wxyz[3])-(a.m_wxyz[1]*b.m_wxyz[2])+(a.m_wxyz[2]*b.m_wxyz[1])-(a.m_wxyz[3]*b.m_wxyz[0]); return result; } //Returns the Even Product of two MQuaternions MQuaternion evenProduct(MQuaternion a,MQuaternion b) { MQuaternion result; - result.m_xyzw[3] = (a.m_xyzw[3]*b.m_xyzw[3])-(a.m_xyzw[0]*b.m_xyzw[0])-(a.m_xyzw[1]*b.m_xyzw[1])-(a.m_xyzw[2]*b.m_xyzw[2]); - result.m_xyzw[0] = (a.m_xyzw[3]*b.m_xyzw[0])+(a.m_xyzw[0]*b.m_xyzw[3]); - result.m_xyzw[1] = (a.m_xyzw[3]*b.m_xyzw[1])+(a.m_xyzw[1]*b.m_xyzw[3]); - result.m_xyzw[2] = (a.m_xyzw[3]*b.m_xyzw[2])+(a.m_xyzw[2]*b.m_xyzw[3]); + result.m_wxyz[0] = (a.m_wxyz[0]*b.m_wxyz[0])-(a.m_wxyz[1]*b.m_wxyz[1])-(a.m_wxyz[2]*b.m_wxyz[2])-(a.m_wxyz[3]*b.m_wxyz[3]); + result.m_wxyz[1] = (a.m_wxyz[0]*b.m_wxyz[1])+(a.m_wxyz[1]*b.m_wxyz[0]); + result.m_wxyz[2] = (a.m_wxyz[0]*b.m_wxyz[2])+(a.m_wxyz[2]*b.m_wxyz[0]); + result.m_wxyz[3] = (a.m_wxyz[0]*b.m_wxyz[3])+(a.m_wxyz[3]*b.m_wxyz[0]); return result; } //Returns the Odd Product of two MQuaternions (Similar to Vector Cross-Product) -MercuryVector oddProduct(MQuaternion a,MQuaternion b) { - MercuryVector result; - result.m_xyzw[0] = (a.m_xyzw[1]*b.m_xyzw[2])-(a.m_xyzw[2]*b.m_xyzw[1]); - result.m_xyzw[1] = (a.m_xyzw[2]*b.m_xyzw[0])-(a.m_xyzw[0]*b.m_xyzw[2]); - result.m_xyzw[2] = (a.m_xyzw[0]*b.m_xyzw[1])-(a.m_xyzw[1]*b.m_xyzw[0]); +MercuryVertex oddProduct(MQuaternion a,MQuaternion b) { + MercuryVertex result; + result[0] = (a.m_wxyz[2]*b.m_wxyz[3])-(a.m_wxyz[3]*b.m_wxyz[2]); + result[1] = (a.m_wxyz[3]*b.m_wxyz[1])-(a.m_wxyz[1]*b.m_wxyz[3]); + result[2] = (a.m_wxyz[1]*b.m_wxyz[2])-(a.m_wxyz[2]*b.m_wxyz[1]); return result; } @@ -279,13 +280,6 @@ return ( (a*SIN((1-t)*Theta)) + (b*SIN(t*Theta)) ) / sinTheta; } -bool MQuaternion::operator==(const MQuaternion& p) const -{ - for (unsigned int i = 0; i < 4; ++i) - if (m_xyzw[i] != p.m_xyzw[i]) return false; - return true; -} - void AngleMatrix (const MercuryVector & angles, MercuryMatrix & matrix ) { float X = angles[0]*2*Q_PI/360; //Reduced calulation for speed @@ -320,6 +314,7 @@ matrix[3][3] = 1; } + /**************************************************************************** * Copyright (C) 2009 by Joshua Allen, Charles Lohr, Adam Lowman * * * Modified: Mercury2/src/MQuaternion.h =================================================================== --- Mercury2/src/MQuaternion.h 2009-05-26 03:38:08 UTC (rev 280) +++ Mercury2/src/MQuaternion.h 2009-05-31 00:53:17 UTC (rev 281) @@ -8,21 +8,20 @@ class MQuaternion { public: //Defines a Quaternion such that q = w + xi + yj + zk - float m_xyzw[4]; - MQuaternion(float W = 0, float X = 0, float Y = 0, float Z = 0); - MQuaternion(float* wxyz); - MQuaternion(const MercuryVertex& p); - + MQuaternion(); + MQuaternion(float W, float X, float Y, float Z); + MQuaternion(float W, const MercuryVertex& p); + ///Make this quaternion represent to a set of euler angles void SetEuler(const MercuryVertex& angles); - + ///Make the quaternion represent a given angle radians around an axis p void CreateFromAxisAngle(const MercuryVertex& p, const float radians); - + ///Access a component of the quaternion with the [] operator float & operator[] ( const int rhs ); const float & operator[] ( const int rhs ) const; - + ///Returns the magnitude float magnitude() const; ///Returns the normalized Quaternion @@ -38,8 +37,8 @@ ///Converts Quaternion to complete 4x4 Matrix void toMatrix4( MercuryMatrix & mat ) const; ///Convert the quaternion to a point. - MercuryVertex ToVertex() { return MercuryVertex( m_xyzw[0],m_xyzw[1],m_xyzw[2] ); } - + MercuryVertex ToVertex() const; + /****************************************************** * NOTE: Quaternion multipication is not commutative * * Therefore the / operator could imply for a/b * @@ -57,9 +56,11 @@ MQuaternion& operator *= (const float &rhs); MQuaternion& operator /= (const float &rhs); - bool operator==(const MQuaternion& p) const; - inline bool operator!=(const MQuaternion& p) const { return !(*this == p); } - + bool operator==(const MQuaternion &rhs) const; + inline bool operator!=(const MQuaternion &rhs) const { return !(*this == rhs); } + +// private: + FloatRow m_wxyz; } M_ALIGN(32); ///Produce a matrix out of a rotation x, then y then z (how Mercury does it) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-31 00:54:23
|
Revision: 282 http://hgengine.svn.sourceforge.net/hgengine/?rev=282&view=rev Author: axlecrusher Date: 2009-05-31 00:54:15 +0000 (Sun, 31 May 2009) Log Message: ----------- updates Modified Paths: -------------- Mercury2/src/Camera.cpp Mercury2/src/Camera.h Mercury2/src/Viewport.cpp Modified: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp 2009-05-31 00:53:17 UTC (rev 281) +++ Mercury2/src/Camera.cpp 2009-05-31 00:54:15 UTC (rev 282) @@ -8,6 +8,8 @@ :TransformNode() { REGISTER_FOR_MESSAGE( INPUTEVENT_MOUSE ); + + REGISTER_FOR_MESSAGE( INPUTEVENT_KEYBOARD ); } void CameraNode::ComputeMatrix() @@ -16,8 +18,10 @@ MercuryMatrix local; -// local.RotateXYZ( m_rotation*-1 ); -// m_rotation. + m_lookAt = m_rotation * MQuaternion(0,0,0,1) * m_rotation.reciprocal(); +// m_lookAt. + m_lookAt.ToVertex().Print(); + AngleMatrix( m_rotation.ToVertex()*-1, local); local.Translate( m_position*-1 ); @@ -30,25 +34,56 @@ { MouseInput* m = (MouseInput*)data; +// MercuryVertex r; +// MQuaternion rot, d(0,0,1,0); + MQuaternion r = m_rotation; r[0] += m->dy/30.0f; r[1] += m->dx/30.0f; +// r = r.normalize(); +// r = r * m_lookAt * r.reciprocal(); +// r = r.normalize(); +// r += m_rotation; + +// r.ToVertex().Print(); +// r += m_rotation; +// r[3] = 1; +// rot.SetEuler( r ); SetRotation(r); } + if (message == INPUTEVENT_KEYBOARD) + { + MQuaternion r = m_rotation; + + KeyboardInput* k = (KeyboardInput*)data; + switch(k->key) + { + case 25: + r[0] += 1*k->isDown; + break; + case 39: + r[0] -= 1*k->isDown; + break; + } + SetRotation(r); + } } void CameraNode::Update(float dTime) { - MercuryVector p = GetPosition(); - + MercuryVector p;// = GetPosition(); +/* if ( KeyboardInput::IsKeyDown(25) ) p[2] -= dTime*2; if ( KeyboardInput::IsKeyDown(38) ) p[0] -= dTime*2; if ( KeyboardInput::IsKeyDown(39) ) p[2] += dTime*2; if ( KeyboardInput::IsKeyDown(40) ) p[0] += dTime*2; + + p *= m_lookAt.ToVertex(); + p += GetPosition(); + SetPosition( p ); + */ - SetPosition( p ); - TransformNode::Update( dTime ); } Modified: Mercury2/src/Camera.h =================================================================== --- Mercury2/src/Camera.h 2009-05-31 00:53:17 UTC (rev 281) +++ Mercury2/src/Camera.h 2009-05-31 00:54:15 UTC (rev 282) @@ -2,6 +2,7 @@ #define CAMERA_H #include <TransformNode.h> +#include <MQuaternion.h> class CameraNode : public TransformNode { @@ -13,6 +14,7 @@ GENRTTI(CameraNode); private: + MQuaternion m_lookAt; }; #endif Modified: Mercury2/src/Viewport.cpp =================================================================== --- Mercury2/src/Viewport.cpp 2009-05-31 00:53:17 UTC (rev 281) +++ Mercury2/src/Viewport.cpp 2009-05-31 00:54:15 UTC (rev 282) @@ -30,8 +30,8 @@ glMatrixMode(GL_MODELVIEW); //compute the position of the eye - EYE = MercuryVertex(0,0,0,1); - EYE = matrix * EYE; +// EYE = MercuryVertex(0,0,0,1); //wrong +// EYE = matrix * EYE; VIEWMATRIX = matrix; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-31 01:24:43
|
Revision: 283 http://hgengine.svn.sourceforge.net/hgengine/?rev=283&view=rev Author: axlecrusher Date: 2009-05-31 01:24:34 +0000 (Sun, 31 May 2009) Log Message: ----------- eliminate MQuaternion [] operator confusion Modified Paths: -------------- Mercury2/src/Camera.cpp Mercury2/src/MQuaternion.cpp Mercury2/src/MQuaternion.h Mercury2/src/TransformNode.cpp Mercury2/src/TransformNode.h Modified: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp 2009-05-31 00:54:15 UTC (rev 282) +++ Mercury2/src/Camera.cpp 2009-05-31 01:24:34 UTC (rev 283) @@ -18,12 +18,11 @@ MercuryMatrix local; - m_lookAt = m_rotation * MQuaternion(0,0,0,1) * m_rotation.reciprocal(); -// m_lookAt. - m_lookAt.ToVertex().Print(); + m_lookAt = GetRotation() * MQuaternion(1, MercuryVector(0,0,1) ) * GetRotation().reciprocal(); + m_lookAt.Print(); - AngleMatrix( m_rotation.ToVertex()*-1, local); - local.Translate( m_position*-1 ); + AngleMatrix( GetRotation().ToVertex()*-1, local); + local.Translate( GetPosition()*-1 ); m_globalMatrix = GetParentMatrix() * local; } @@ -37,9 +36,9 @@ // MercuryVertex r; // MQuaternion rot, d(0,0,1,0); - MQuaternion r = m_rotation; - r[0] += m->dy/30.0f; - r[1] += m->dx/30.0f; + MQuaternion r = GetRotation(); + r[MQuaternion::X] += m->dy/30.0f; + r[MQuaternion::Y] += m->dx/30.0f; // r = r.normalize(); // r = r * m_lookAt * r.reciprocal(); @@ -54,16 +53,16 @@ } if (message == INPUTEVENT_KEYBOARD) { - MQuaternion r = m_rotation; + MQuaternion r = GetRotation(); KeyboardInput* k = (KeyboardInput*)data; switch(k->key) { case 25: - r[0] += 1*k->isDown; + r[MQuaternion::X] += 1; break; case 39: - r[0] -= 1*k->isDown; + r[MQuaternion::X] -= 1; break; } SetRotation(r); Modified: Mercury2/src/MQuaternion.cpp =================================================================== --- Mercury2/src/MQuaternion.cpp 2009-05-31 00:54:15 UTC (rev 282) +++ Mercury2/src/MQuaternion.cpp 2009-05-31 01:24:34 UTC (rev 283) @@ -3,7 +3,7 @@ MQuaternion::MQuaternion() { - m_wxyz[0] = 0; + m_wxyz[0] = 1; m_wxyz[1] = 0; m_wxyz[2] = 0; m_wxyz[3] = 0; @@ -25,7 +25,7 @@ m_wxyz[3] = p[2]; } -float & MQuaternion::operator [] (int i) +float & MQuaternion::operator [] (WXYZ i) { return m_wxyz[i]; //haha we won't even get here. } @@ -221,6 +221,10 @@ return v; } +void MQuaternion::Print(const MString& s) const +{ + printf("%s: %f %f %f %f\n", s.c_str(), m_wxyz[0], m_wxyz[1], m_wxyz[2], m_wxyz[3]); +} //Returns the Euclidian Inner Product of two MQuaternions (Similar to Vector Dot-Product) Modified: Mercury2/src/MQuaternion.h =================================================================== --- Mercury2/src/MQuaternion.h 2009-05-31 00:54:15 UTC (rev 282) +++ Mercury2/src/MQuaternion.h 2009-05-31 01:24:34 UTC (rev 283) @@ -7,6 +7,8 @@ ///Mathematical Quaternion (Used for Rotation) class MQuaternion { public: + enum WXYZ { W = 0, X, Y, Z }; + //Defines a Quaternion such that q = w + xi + yj + zk MQuaternion(); MQuaternion(float W, float X, float Y, float Z); @@ -19,9 +21,9 @@ void CreateFromAxisAngle(const MercuryVertex& p, const float radians); ///Access a component of the quaternion with the [] operator - float & operator[] ( const int rhs ); - const float & operator[] ( const int rhs ) const; - + float & operator[] ( const WXYZ rhs ); + const float & operator[] ( const WXYZ rhs ) const; + ///Returns the magnitude float magnitude() const; ///Returns the normalized Quaternion @@ -58,7 +60,9 @@ bool operator==(const MQuaternion &rhs) const; inline bool operator!=(const MQuaternion &rhs) const { return !(*this == rhs); } - + + void Print(const MString& s = "MQuaternion") const; + // private: FloatRow m_wxyz; } M_ALIGN(32); Modified: Mercury2/src/TransformNode.cpp =================================================================== --- Mercury2/src/TransformNode.cpp 2009-05-31 00:54:15 UTC (rev 282) +++ Mercury2/src/TransformNode.cpp 2009-05-31 01:24:34 UTC (rev 283) @@ -4,7 +4,7 @@ REGISTER_NODE_TYPE(RotatorNode); TransformNode::TransformNode() - :m_scale( MercuryVertex(1,1,1) ) + :m_scale( MercuryVertex(1,1,1) ), m_rotation(1,0,0,0) { SetTaint( true ); //taint because of the scale set above } @@ -55,7 +55,7 @@ // local.Identity(); local.Transotale( m_position[0], m_position[1], m_position[2], - m_rotation[0], m_rotation[1], m_rotation[2], + m_rotation[MQuaternion::X], m_rotation[MQuaternion::Y], m_rotation[MQuaternion::Z], m_scale[0], m_scale[1], m_scale[2] ); m_globalMatrix = GetParentMatrix() * local; @@ -98,13 +98,13 @@ //only change the values that exist in the XML if ( !node.Attribute("rotx").empty() ) - rot[0] = StrToFloat( node.Attribute("rotx") ); + rot[MQuaternion::X] = StrToFloat( node.Attribute("rotx") ); if ( !node.Attribute("roty").empty() ) - rot[1] = StrToFloat( node.Attribute("roty") ); + rot[MQuaternion::Y] = StrToFloat( node.Attribute("roty") ); if ( !node.Attribute("rotz").empty() ) - rot[2] = StrToFloat( node.Attribute("rotz") ); + rot[MQuaternion::Z] = StrToFloat( node.Attribute("rotz") ); if ( !node.Attribute("scalex").empty() ) scale.SetX( StrToFloat( node.Attribute("scalex") ) ); @@ -150,9 +150,9 @@ void RotatorNode::Update(float dTime) { - MQuaternion r = m_rotation; - r[0] += (dTime)*25; - r[1] += (dTime)*75; + MQuaternion r = GetRotation(); + r[MQuaternion::X] += (dTime)*25; + r[MQuaternion::Y] += (dTime)*75; SetRotation( r ); Modified: Mercury2/src/TransformNode.h =================================================================== --- Mercury2/src/TransformNode.h 2009-05-31 00:54:15 UTC (rev 282) +++ Mercury2/src/TransformNode.h 2009-05-31 01:24:34 UTC (rev 283) @@ -39,12 +39,13 @@ private: void RippleTaintDown(); -// MercuryMatrix m_localMatrix; - protected: + //use of accessor required MercuryVertex m_scale; MercuryVertex m_position; -// MercuryVertex m_rotation; MQuaternion m_rotation; + +// MercuryMatrix m_localMatrix; + protected: MercuryMatrix m_globalMatrix; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-31 04:04:36
|
Revision: 285 http://hgengine.svn.sourceforge.net/hgengine/?rev=285&view=rev Author: axlecrusher Date: 2009-05-31 04:04:35 +0000 (Sun, 31 May 2009) Log Message: ----------- updates Modified Paths: -------------- Mercury2/src/MQuaternion.cpp Mercury2/src/MQuaternion.h Modified: Mercury2/src/MQuaternion.cpp =================================================================== --- Mercury2/src/MQuaternion.cpp 2009-05-31 01:25:41 UTC (rev 284) +++ Mercury2/src/MQuaternion.cpp 2009-05-31 04:04:35 UTC (rev 285) @@ -1,5 +1,6 @@ #include <MQuaternion.h> #include <MercuryMath.h> +#include <MercuryMatrix.h> MQuaternion::MQuaternion() { @@ -60,6 +61,24 @@ m_wxyz[3] = sn * p[2]; } +void MQuaternion::ToAxisAngle(float& angle, float& x, float& y, float& z) const +{ + float scale = SQRT(x*x + y*y + z*z); + + //prevent infinite axis + if (scale == 0) + { + x=y=0; z=1; + angle = 0; + return; + } + + angle = 2*acos(m_wxyz[0]); + x = m_wxyz[1] / scale; + y = m_wxyz[2] / scale; + z = m_wxyz[3] / scale; +} + //Returns the magnitude float MQuaternion::magnitude() const { return SQRT((m_wxyz[0]*m_wxyz[0])+(m_wxyz[1]*m_wxyz[1])+(m_wxyz[2]*m_wxyz[2])+(m_wxyz[3]*m_wxyz[3])); @@ -215,7 +234,7 @@ return true; } -MercuryVertex MQuaternion::ToVertex() const +MercuryVertex MQuaternion::ToVector() const { MercuryVertex v(m_wxyz[1], m_wxyz[2], m_wxyz[3], m_wxyz[0]); return v; @@ -226,7 +245,12 @@ printf("%s: %f %f %f %f\n", s.c_str(), m_wxyz[0], m_wxyz[1], m_wxyz[2], m_wxyz[3]); } +MercuryVector MQuaternion::operator * (const MercuryVector &rhs) const +{ + return (*this * MQuaternion(0, rhs) * reciprocal()).ToVector(); +} + //Returns the Euclidian Inner Product of two MQuaternions (Similar to Vector Dot-Product) float innerProduct(const MQuaternion & a, const MQuaternion &b) { Modified: Mercury2/src/MQuaternion.h =================================================================== --- Mercury2/src/MQuaternion.h 2009-05-31 01:25:41 UTC (rev 284) +++ Mercury2/src/MQuaternion.h 2009-05-31 04:04:35 UTC (rev 285) @@ -2,8 +2,10 @@ #define MQUATERNION_H #include <MercuryVertex.h> -#include <MercuryMatrix.h> +#include <MercuryUtil.h> +class MercuryMatrix; + ///Mathematical Quaternion (Used for Rotation) class MQuaternion { public: @@ -19,6 +21,7 @@ ///Make the quaternion represent a given angle radians around an axis p void CreateFromAxisAngle(const MercuryVertex& p, const float radians); + void ToAxisAngle(float& angle, float& x, float& y, float& z) const; ///Access a component of the quaternion with the [] operator float & operator[] ( const WXYZ rhs ); @@ -39,7 +42,7 @@ ///Converts Quaternion to complete 4x4 Matrix void toMatrix4( MercuryMatrix & mat ) const; ///Convert the quaternion to a point. - MercuryVertex ToVertex() const; + MercuryVertex ToVector() const; /****************************************************** * NOTE: Quaternion multipication is not commutative * @@ -58,6 +61,8 @@ MQuaternion& operator *= (const float &rhs); MQuaternion& operator /= (const float &rhs); + MercuryVector operator * (const MercuryVector &rhs) const; + bool operator==(const MQuaternion &rhs) const; inline bool operator!=(const MQuaternion &rhs) const { return !(*this == rhs); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-31 04:26:39
|
Revision: 288 http://hgengine.svn.sourceforge.net/hgengine/?rev=288&view=rev Author: axlecrusher Date: 2009-05-31 04:26:04 +0000 (Sun, 31 May 2009) Log Message: ----------- make CreatFromAngleAxis static Modified Paths: -------------- Mercury2/src/MQuaternion.cpp Mercury2/src/MQuaternion.h Modified: Mercury2/src/MQuaternion.cpp =================================================================== --- Mercury2/src/MQuaternion.cpp 2009-05-31 04:18:08 UTC (rev 287) +++ Mercury2/src/MQuaternion.cpp 2009-05-31 04:26:04 UTC (rev 288) @@ -52,8 +52,15 @@ m_wxyz[3] = cx*cy*sz-sx*sy*cz;//q4 } -void MQuaternion::CreateFromAxisAngle(const MercuryVertex& p, const float radians) +MQuaternion MQuaternion::CreateFromAxisAngle(const MercuryVertex& p, const float radians) { + MQuaternion q; + q.FromAxisAngle(p, radians); + return q; +} + +void MQuaternion::FromAxisAngle(const MercuryVertex& p, const float radians) +{ float sn = SIN(radians/2.0f); m_wxyz[0] = COS(radians/2.0f); m_wxyz[1] = sn * p[0]; Modified: Mercury2/src/MQuaternion.h =================================================================== --- Mercury2/src/MQuaternion.h 2009-05-31 04:18:08 UTC (rev 287) +++ Mercury2/src/MQuaternion.h 2009-05-31 04:26:04 UTC (rev 288) @@ -20,7 +20,8 @@ void SetEuler(const MercuryVertex& angles); ///Make the quaternion represent a given angle radians around an axis p - void CreateFromAxisAngle(const MercuryVertex& p, const float radians); + static MQuaternion CreateFromAxisAngle(const MercuryVertex& p, const float radians); + void FromAxisAngle(const MercuryVertex& p, const float radians); void ToAxisAngle(float& angle, float& x, float& y, float& z) const; ///Access a component of the quaternion with the [] operator This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-31 14:26:37
|
Revision: 293 http://hgengine.svn.sourceforge.net/hgengine/?rev=293&view=rev Author: axlecrusher Date: 2009-05-31 14:26:36 +0000 (Sun, 31 May 2009) Log Message: ----------- quaternion has to be rebuilt each time to prevent unintended roll Modified Paths: -------------- Mercury2/src/Camera.cpp Mercury2/src/Camera.h Modified: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp 2009-05-31 04:56:37 UTC (rev 292) +++ Mercury2/src/Camera.cpp 2009-05-31 14:26:36 UTC (rev 293) @@ -5,11 +5,9 @@ REGISTER_NODE_TYPE(CameraNode); CameraNode::CameraNode() - :TransformNode() + :TransformNode(), m_x(0), m_y(0) { REGISTER_FOR_MESSAGE( INPUTEVENT_MOUSE ); - - REGISTER_FOR_MESSAGE( INPUTEVENT_KEYBOARD ); } void CameraNode::ComputeMatrix() @@ -19,12 +17,11 @@ MercuryMatrix local; MQuaternion r( GetRotation().normalize() ); - - m_lookAt = MercuryVector(0,0,1); + + m_lookAt = MercuryVector(0,0,-1); //by default camera looks down world Z m_lookAt = m_lookAt.Rotate( r ); m_lookAt.NormalizeSelf(); -// m_lookAt.Print(); - + r[MQuaternion::W] *= -1; //reverse angle for camera r.toMatrix4( local ); @@ -39,12 +36,16 @@ { MouseInput* m = (MouseInput*)data; - MQuaternion qx = MQuaternion::CreateFromAxisAngle(MercuryVector(1,0,0), m->dy/1200.0f); - MQuaternion qy = MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), m->dx/1200.0f); + m_y += m->dy/1200.0f; + m_x += m->dx/1200.0f; - MQuaternion rot = GetRotation(); - rot = rot * qx * qy; - SetRotation(rot); + MercuryVector Xaxis = m_lookAt.CrossProduct( MercuryVector(0,1,0) ); + Xaxis.NormalizeSelf(); + + MQuaternion qx = MQuaternion::CreateFromAxisAngle(Xaxis, m_y); + MQuaternion qy = MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), m_x); + + SetRotation(qx * qy); } } @@ -53,10 +54,11 @@ MercuryVector p = GetPosition(); float a = 0; - if ( KeyboardInput::IsKeyDown(25) ) a -= dTime*2; - if ( KeyboardInput::IsKeyDown(39) ) a += dTime*2; + if ( KeyboardInput::IsKeyDown(25) ) a += dTime*2; + if ( KeyboardInput::IsKeyDown(39) ) a -= dTime*2; p += m_lookAt * a; +// p.SetY(0); //lock to ground SetPosition( p ); TransformNode::Update( dTime ); Modified: Mercury2/src/Camera.h =================================================================== --- Mercury2/src/Camera.h 2009-05-31 04:56:37 UTC (rev 292) +++ Mercury2/src/Camera.h 2009-05-31 14:26:36 UTC (rev 293) @@ -15,6 +15,7 @@ GENRTTI(CameraNode); private: MercuryVector m_lookAt; + float m_x, m_y; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-31 22:46:43
|
Revision: 299 http://hgengine.svn.sourceforge.net/hgengine/?rev=299&view=rev Author: axlecrusher Date: 2009-05-31 22:46:35 +0000 (Sun, 31 May 2009) Log Message: ----------- just clamp values Modified Paths: -------------- Mercury2/src/Camera.cpp Mercury2/src/MercuryUtil.h Modified: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp 2009-05-31 22:29:07 UTC (rev 298) +++ Mercury2/src/Camera.cpp 2009-05-31 22:46:35 UTC (rev 299) @@ -46,17 +46,10 @@ { MouseInput* m = (MouseInput*)data; - //keep m_y within [-PI -> PI] - if( m_y < -Q_PI ) m_y += Q_PI*2.; - if( m_y > Q_PI ) m_y -= Q_PI*2.; - //if m_y is < -PI/2 or m_y > PI/2 one must invert the axes - m_y += m->dy/1200.0f; + m_x += m->dx/1200.0f; - if (ABS(m_y) > Q_PI/2) - m_x -= m->dx/1200.0f; - else - m_x += m->dx/1200.0f; + m_y = Clamp(-Q_PI/2, Q_PI/2, m_y); MQuaternion qLeftRight = MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), m_x); MercuryVector LocalX = MercuryVector( 1, 0, 0 ); Modified: Mercury2/src/MercuryUtil.h =================================================================== --- Mercury2/src/MercuryUtil.h 2009-05-31 22:29:07 UTC (rev 298) +++ Mercury2/src/MercuryUtil.h 2009-05-31 22:46:35 UTC (rev 299) @@ -45,6 +45,14 @@ return t1<t2?t1:t2; } +template<typename T> +const T& Clamp(const T& min, const T& max, const T& value) +{ + if (value > max) return max; + if (value < min) return min; + return value; +} + //This counter is used with singletons to //ensure proper destruction order of the //singleton This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-03 01:22:27
|
Revision: 301 http://hgengine.svn.sourceforge.net/hgengine/?rev=301&view=rev Author: axlecrusher Date: 2009-06-03 01:22:25 +0000 (Wed, 03 Jun 2009) Log Message: ----------- construct from string Modified Paths: -------------- Mercury2/src/MercuryVertex.cpp Mercury2/src/MercuryVertex.h Modified: Mercury2/src/MercuryVertex.cpp =================================================================== --- Mercury2/src/MercuryVertex.cpp 2009-06-01 00:17:40 UTC (rev 300) +++ Mercury2/src/MercuryVertex.cpp 2009-06-03 01:22:25 UTC (rev 301) @@ -121,6 +121,14 @@ return (q * MQuaternion(0, *this) * q.reciprocal()).ToVector(); } +MercuryVertex MercuryVertex::CreateFromString(const MString& s) +{ + float x,y,z; + sscanf(s.c_str(), "%f,%f,%f", &x, &y, &z); + return MercuryVertex(x,y,z); +} + + /**************************************************************************** * Copyright (C) 2009 by Joshua Allen * * * Modified: Mercury2/src/MercuryVertex.h =================================================================== --- Mercury2/src/MercuryVertex.h 2009-06-01 00:17:40 UTC (rev 300) +++ Mercury2/src/MercuryVertex.h 2009-06-03 01:22:25 UTC (rev 301) @@ -83,6 +83,8 @@ void Print(const MString& s = "Vertex") const; MercuryVertex Rotate(const MQuaternion& q) const; + + static MercuryVertex CreateFromString(const MString& s); // float (*this)[3]; FloatRow m_xyzw; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-04 00:11:32
|
Revision: 302 http://hgengine.svn.sourceforge.net/hgengine/?rev=302&view=rev Author: axlecrusher Date: 2009-06-04 00:11:19 +0000 (Thu, 04 Jun 2009) Log Message: ----------- updates, trying to fix broken rotations Modified Paths: -------------- Mercury2/src/Camera.cpp Mercury2/src/MQuaternion.cpp Mercury2/src/MQuaternion.h Mercury2/src/MercuryMatrix.cpp Mercury2/src/TransformNode.cpp Modified: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp 2009-06-03 01:22:25 UTC (rev 301) +++ Mercury2/src/Camera.cpp 2009-06-04 00:11:19 UTC (rev 302) @@ -26,7 +26,7 @@ m_lookAt.NormalizeSelf(); LOOKAT = m_lookAt; - r[MQuaternion::W] *= -1; //reverse angle for camera + r.W() *= -1; //reverse angle for camera //rotate then translate since we are a camera r.toMatrix4( local ); Modified: Mercury2/src/MQuaternion.cpp =================================================================== --- Mercury2/src/MQuaternion.cpp 2009-06-03 01:22:25 UTC (rev 301) +++ Mercury2/src/MQuaternion.cpp 2009-06-04 00:11:19 UTC (rev 302) @@ -61,11 +61,15 @@ void MQuaternion::FromAxisAngle(const MercuryVertex& p, const float radians) { + MercuryVertex v( p.Normalize() ); + float sn = SIN(radians/2.0f); m_wxyz[0] = COS(radians/2.0f); m_wxyz[1] = sn * p[0]; m_wxyz[2] = sn * p[1]; m_wxyz[3] = sn * p[2]; + + *this = this->normalize(); } void MQuaternion::ToAxisAngle(float& angle, float& x, float& y, float& z) const @@ -115,28 +119,33 @@ //Converts MQuaternion to 4x4 Matrix(3x3 Spatial) void MQuaternion::toMatrix( MercuryMatrix &matrix ) const { - float X = 2*m_wxyz[1]*m_wxyz[1]; //Reduced calulation for speed - float Y = 2*m_wxyz[2]*m_wxyz[2]; - float Z = 2*m_wxyz[3]*m_wxyz[3]; - float a = 2*m_wxyz[0]*m_wxyz[1]; - float b = 2*m_wxyz[0]*m_wxyz[2]; - float c = 2*m_wxyz[0]*m_wxyz[3]; - float d = 2*m_wxyz[1]*m_wxyz[2]; - float e = 2*m_wxyz[1]*m_wxyz[3]; - float f = 2*m_wxyz[2]*m_wxyz[3]; + MQuaternion q( this->normalize() ); + + //Reduced calulation for speed + float xx = 2*q.X()*q.X(); + float xy = 2*q.X()*q.Y(); + float xz = 2*q.X()*q.Z(); + float xw = 2*q.X()*q.W(); + + float yy = 2*q.Y()*q.Y(); + float yz = 2*q.Y()*q.Z(); + float yw = 2*q.Y()*q.W(); + + float zz = 2*q.Z()*q.Z(); + float zw = 2*q.Z()*q.W(); //row major - matrix[0][0] = 1-Y-Z; - matrix[0][1] = d-c; - matrix[0][2] = e+b; + matrix[0][0] = 1-yy-zz; + matrix[0][1] = xy-zw; + matrix[0][2] = xz+yw; - matrix[1][0] = d+c; - matrix[1][1] = 1-X-Z; - matrix[1][2] = f-a; + matrix[1][0] = xy+zw; + matrix[1][1] = 1-xx-zz; + matrix[1][2] = yz-xw; - matrix[2][0] = e-b; - matrix[2][1] = f+a; - matrix[2][2] = 1-X-Y; + matrix[2][0] = xz-yw; + matrix[2][1] = yz+xw; + matrix[2][2] = 1-xx-yy; } void MQuaternion::toMatrix4( MercuryMatrix &matrix ) const { Modified: Mercury2/src/MQuaternion.h =================================================================== --- Mercury2/src/MQuaternion.h 2009-06-03 01:22:25 UTC (rev 301) +++ Mercury2/src/MQuaternion.h 2009-06-04 00:11:19 UTC (rev 302) @@ -9,7 +9,7 @@ ///Mathematical Quaternion (Used for Rotation) class MQuaternion { public: - enum WXYZ { W = 0, X, Y, Z }; + enum WXYZ { QW = 0, QX, QY, QZ }; //Defines a Quaternion such that q = w + xi + yj + zk MQuaternion(); @@ -67,6 +67,11 @@ void Print(const MString& s = "MQuaternion") const; + inline float& W() { return m_wxyz[0]; } + inline float& X() { return m_wxyz[1]; } + inline float& Y() { return m_wxyz[2]; } + inline float& Z() { return m_wxyz[3]; } + // private: FloatRow m_wxyz; } M_ALIGN(32); Modified: Mercury2/src/MercuryMatrix.cpp =================================================================== --- Mercury2/src/MercuryMatrix.cpp 2009-06-03 01:22:25 UTC (rev 301) +++ Mercury2/src/MercuryMatrix.cpp 2009-06-04 00:11:19 UTC (rev 302) @@ -123,7 +123,7 @@ void MercuryMatrix::Rotate(const MQuaternion& q) { MercuryMatrix m; - q.normalize().toMatrix4( m ); + q.toMatrix4( m ); *this *= m; } Modified: Mercury2/src/TransformNode.cpp =================================================================== --- Mercury2/src/TransformNode.cpp 2009-06-03 01:22:25 UTC (rev 301) +++ Mercury2/src/TransformNode.cpp 2009-06-04 00:11:19 UTC (rev 302) @@ -104,13 +104,13 @@ //only change the values that exist in the XML if ( !node.Attribute("rotx").empty() ) - rot *= MQuaternion::CreateFromAxisAngle(MercuryVector(1,0,0), StrToFloat( node.Attribute("rotx") )); + rot *= MQuaternion::CreateFromAxisAngle(MercuryVector(1,0,0), StrToFloat( node.Attribute("rotx") )*DEGRAD ); if ( !node.Attribute("roty").empty() ) - rot *= MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), StrToFloat( node.Attribute("roty") )); + rot *= MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), StrToFloat( node.Attribute("roty") )*DEGRAD ); if ( !node.Attribute("rotz").empty() ) - rot *= MQuaternion::CreateFromAxisAngle(MercuryVector(0,0,1), StrToFloat( node.Attribute("rotz") )); + rot *= MQuaternion::CreateFromAxisAngle(MercuryVector(0,0,1), StrToFloat( node.Attribute("rotz") )*DEGRAD ); if ( !node.Attribute("scalex").empty() ) scale.SetX( StrToFloat( node.Attribute("scalex") ) ); @@ -157,8 +157,8 @@ void RotatorNode::Update(float dTime) { MQuaternion r = GetRotation(); - r[MQuaternion::X] += (dTime)*25; - r[MQuaternion::Y] += (dTime)*75; + r.X() += (dTime)*25; + r.Y() += (dTime)*75; SetRotation( r ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-04 00:12:01
|
Revision: 303 http://hgengine.svn.sourceforge.net/hgengine/?rev=303&view=rev Author: axlecrusher Date: 2009-06-04 00:11:52 +0000 (Thu, 04 Jun 2009) Log Message: ----------- show axes Modified Paths: -------------- Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryVBO.cpp Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-06-04 00:11:19 UTC (rev 302) +++ Mercury2/src/MercuryAsset.cpp 2009-06-04 00:11:52 UTC (rev 303) @@ -1,6 +1,8 @@ #include <MercuryAsset.h> #include <RenderableNode.h> +#include <GLHeaders.h> + MercuryAsset::MercuryAsset() :m_isInstanced(false), m_boundingVolume(NULL), m_loadState(NONE) { @@ -35,6 +37,22 @@ SetLoadState( LOADED ); } +void MercuryAsset::DrawAxes() +{ + glBegin(GL_LINES); + glColor3f(1,0,0); + glVertex3f(0,0,0); + glVertex3f(0.5,0,0); + glColor3f(0,1,0); + glVertex3f(0,0,0); + glVertex3f(0,0.5,0); + glColor3f(0,0,1); + glVertex3f(0,0,0); + glVertex3f(0,0,0.5); + glColor3f(1,1,1); + glEnd(); +} + AssetFactory& AssetFactory::GetInstance() { static AssetFactory* instance = NULL; Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-06-04 00:11:19 UTC (rev 302) +++ Mercury2/src/MercuryAsset.h 2009-06-04 00:11:52 UTC (rev 303) @@ -40,6 +40,8 @@ inline const BoundingVolume* GetBoundingVolume() const { return m_boundingVolume; } inline const MString& Path() const { return m_path; } + + void DrawAxes(); protected: void SetLoadState(LoadState ls); //thread safe LoadState GetLoadState(); //thread safe Modified: Mercury2/src/MercuryVBO.cpp =================================================================== --- Mercury2/src/MercuryVBO.cpp 2009-06-04 00:11:19 UTC (rev 302) +++ Mercury2/src/MercuryVBO.cpp 2009-06-04 00:11:52 UTC (rev 303) @@ -57,6 +57,7 @@ m_lastVBOrendered = this; if (m_boundingVolume && SHOWBOUNDINGVOLUME) m_boundingVolume->Render(); + DrawAxes(); } void MercuryVBO::InitVBO() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-04 01:02:54
|
Revision: 306 http://hgengine.svn.sourceforge.net/hgengine/?rev=306&view=rev Author: axlecrusher Date: 2009-06-04 01:02:38 +0000 (Thu, 04 Jun 2009) Log Message: ----------- updates Modified Paths: -------------- Mercury2/src/MQuaternion.cpp Mercury2/src/MQuaternion.h Modified: Mercury2/src/MQuaternion.cpp =================================================================== --- Mercury2/src/MQuaternion.cpp 2009-06-04 00:34:24 UTC (rev 305) +++ Mercury2/src/MQuaternion.cpp 2009-06-04 01:02:38 UTC (rev 306) @@ -16,6 +16,7 @@ m_wxyz[1] = X; m_wxyz[2] = Y; m_wxyz[3] = Z; + *this = this->normalize(); } MQuaternion::MQuaternion(float W, const MercuryVertex& p) @@ -24,13 +25,9 @@ m_wxyz[1] = p[0]; m_wxyz[2] = p[1]; m_wxyz[3] = p[2]; + *this = this->normalize(); } -float & MQuaternion::operator [] (WXYZ i) -{ - return m_wxyz[i]; //haha we won't even get here. -} - void MQuaternion::SetEuler(const MercuryVertex& angles) { float X = angles[0]/2.0f; //roll @@ -50,6 +47,8 @@ m_wxyz[1] = sx*cy*cz-cx*sy*sz;//q2 m_wxyz[2] = cx*sy*cz+sx*cy*sz;//q3 m_wxyz[3] = cx*cy*sz-sx*sy*cz;//q4 + + *this = this->normalize(); } MQuaternion MQuaternion::CreateFromAxisAngle(const MercuryVertex& p, const float radians) @@ -65,9 +64,9 @@ float sn = SIN(radians/2.0f); m_wxyz[0] = COS(radians/2.0f); - m_wxyz[1] = sn * p[0]; - m_wxyz[2] = sn * p[1]; - m_wxyz[3] = sn * p[2]; + m_wxyz[1] = sn * v[0]; + m_wxyz[2] = sn * v[1]; + m_wxyz[3] = sn * v[2]; *this = this->normalize(); } Modified: Mercury2/src/MQuaternion.h =================================================================== --- Mercury2/src/MQuaternion.h 2009-06-04 00:34:24 UTC (rev 305) +++ Mercury2/src/MQuaternion.h 2009-06-04 01:02:38 UTC (rev 306) @@ -25,8 +25,8 @@ void ToAxisAngle(float& angle, float& x, float& y, float& z) const; ///Access a component of the quaternion with the [] operator - float & operator[] ( const WXYZ rhs ); - const float & operator[] ( const WXYZ rhs ) const; + inline float & operator[] ( const WXYZ i ) { return m_wxyz[i]; } + inline const float & operator[] ( const WXYZ i ) const { return m_wxyz[i]; } ///Returns the magnitude float magnitude() const; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-13 01:10:49
|
Revision: 312 http://hgengine.svn.sourceforge.net/hgengine/?rev=312&view=rev Author: axlecrusher Date: 2009-06-13 01:10:48 +0000 (Sat, 13 Jun 2009) Log Message: ----------- broken FBO Added Paths: ----------- Mercury2/src/MercuryFBO.cpp Mercury2/src/MercuryFBO.h Mercury2/src/RenderBuffer.cpp Mercury2/src/RenderBuffer.h Added: Mercury2/src/MercuryFBO.cpp =================================================================== --- Mercury2/src/MercuryFBO.cpp (rev 0) +++ Mercury2/src/MercuryFBO.cpp 2009-06-13 01:10:48 UTC (rev 312) @@ -0,0 +1,87 @@ +#include <MercuryFBO.h> +#include <GLHeaders.h> + +REGISTER_NODE_TYPE(MercuryFBO); + +MercuryFBO::MercuryFBO() + :m_fboID(0), m_initiated(false) +{ +} + +MercuryFBO::~MercuryFBO() +{ + if (m_fboID != 0) glDeleteFramebuffersEXT(1, &m_fboID); +} + +void MercuryFBO::InitFBOBeforeRender() +{ + m_initiated = true; + glGenFramebuffersEXT(1, &m_fboID); +} + +void MercuryFBO::PreRender(const MercuryMatrix& matrix) +{ + if ( !m_initiated ) InitFBOBeforeRender(); + RenderableNode::PreRender(matrix); +} + +void MercuryFBO::Render(const MercuryMatrix& matrix) +{ + if (m_lastRendered != m_fboID) + { + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fboID); + m_lastRendered = m_fboID; +// m_lastInStask = m_lastRendered; + } + +// glPushAttrib(GL_VIEWPORT_BIT); + // glViewport(0,0,width, height); + + RenderableNode::Render(matrix); +} + +void MercuryFBO::PostRender(const MercuryMatrix& matrix) +{ +// glPopAttrib(); + +// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_lastInStask); +// m_lastRendered = m_lastInStask; + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); //unbind + m_lastRendered = 0; + + RenderableNode::PostRender(matrix); +} + +uint32_t MercuryFBO::m_lastRendered = NULL; + +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen * + * * + * * + * All rights reserved. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the following disclaimer. * + * * 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. * + * * Neither the name of the Mercury Engine nor the names of its * + * contributors may be used to endorse or promote products derived * + * from this software without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "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 THE COPYRIGHT * + * OWNER 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. * + ***************************************************************************/ Added: Mercury2/src/MercuryFBO.h =================================================================== --- Mercury2/src/MercuryFBO.h (rev 0) +++ Mercury2/src/MercuryFBO.h 2009-06-13 01:10:48 UTC (rev 312) @@ -0,0 +1,64 @@ +#ifndef MERCURYFBO_H +#define MERCURYFBO_H + +#include <RenderableNode.h> + +class MercuryFBO : public RenderableNode +{ + public: + MercuryFBO(); + virtual ~MercuryFBO(); + + virtual void PreRender(const MercuryMatrix& matrix); + virtual void Render(const MercuryMatrix& matrix); + virtual void PostRender(const MercuryMatrix& matrix); + + GENRTTI(MercuryFBO); + + private: + void InitFBOBeforeRender(); + + uint32_t m_fboID; + bool m_initiated; + static uint32_t m_lastRendered; + + uint32_t m_lastInStask; + + protected: +// AlignedBuffer<float> m_vertexData; +// AlignedBuffer<uint16_t> m_indexData; +}; + +#endif + +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen * + * * + * * + * All rights reserved. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the following disclaimer. * + * * 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. * + * * Neither the name of the Mercury Engine nor the names of its * + * contributors may be used to endorse or promote products derived * + * from this software without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "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 THE COPYRIGHT * + * OWNER 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. * + ***************************************************************************/ Added: Mercury2/src/RenderBuffer.cpp =================================================================== --- Mercury2/src/RenderBuffer.cpp (rev 0) +++ Mercury2/src/RenderBuffer.cpp 2009-06-13 01:10:48 UTC (rev 312) @@ -0,0 +1,228 @@ +#include <RenderBuffer.h> +#include <GLHeaders.h> +#include <MercuryWindow.h> +#include <RenderableNode.h> + +#include <Texture.h> + +REGISTER_ASSET_TYPE(RenderBuffer); + +RenderBuffer::RenderBuffer() + :MercuryAsset(), m_bufferID(0), m_textureID(0), m_initiated(false), m_width(0), m_height(0), m_type(NONE), m_bound(false) +{ +} + +RenderBuffer::~RenderBuffer() +{ + if (m_bufferID != 0) glDeleteRenderbuffersEXT(1, &m_bufferID); +} + +void RenderBuffer::Init(MercuryNode* node) +{ + MercuryAsset::Init( node ); + + RenderableNode* rn = RenderableNode::Cast( node ); + if ( rn ) + { + rn->AddPreRender( this ); + rn->AddPostRender( this ); + } +} + +void RenderBuffer::PreRender(const MercuryNode* node) +{ + if ( !m_initiated ) InitRenderBuffer(); +} + +void RenderBuffer::Render(const MercuryNode* node) +{ + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_bufferID); + if ( NeedResize() ) AllocateSpace(); + + //attach to FBO +// if ( !m_bound ) + { + m_bound = true; + if ( m_type == TEXTURE ) + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GLAttachPoint(), GL_TEXTURE_2D, m_textureID, 0); + else + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GLAttachPoint(), GL_RENDERBUFFER_EXT, m_bufferID); + } + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + +void RenderBuffer::PostRender(const MercuryNode* node) +{ + static uint32_t t = time(NULL); + if ( (m_type == TEXTURE) && (time(NULL) > (t+3))) +// if (false) + { + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + +// printf("active %d\n", Texture::NumberActiveTextures() ); + + //this works with a "normal" texture, FBO texture is still white + glActiveTexture( GL_TEXTURE0 ); + glClientActiveTextureARB(GL_TEXTURE0); + glEnable( GL_TEXTURE_2D ); + glBindTexture(GL_TEXTURE_2D, m_textureID); + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + + + glBegin(GL_QUADS); + glTexCoord2d(0,1); + glVertex3i(-1, -1, -1); + + glTexCoord2d(1,1); + glVertex3i(1, -1, -1); + + glTexCoord2d(1,0); + glVertex3i(1, 1, -1); + + glTexCoord2d(0,0); + glVertex3i(-1, 1, -1); + glEnd(); + + + glBindTexture(GL_TEXTURE_2D, 0); +// glActiveTexture( GL_TEXTURE0 ); +// glClientActiveTextureARB(GL_TEXTURE0); +// glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisable( GL_TEXTURE_2D ); + + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + } +} + +void RenderBuffer::InitRenderBuffer() +{ + m_initiated = true; + glGenRenderbuffersEXT(1, &m_bufferID); + + if (m_type == TEXTURE) + { + glGenTextures(1, &m_textureID); + printf("texture rb %d\n", m_textureID); + } +} + +void RenderBuffer::AllocateSpace() +{ + m_width = MercuryWindow::GetCurrentWindow()->Width(); + m_height = MercuryWindow::GetCurrentWindow()->Height(); + + if (m_type == TEXTURE) + { + glBindTexture(GL_TEXTURE_2D, m_textureID); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + } + else + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GLType(), m_width, m_height); +} + +bool RenderBuffer::NeedResize() +{ + int width = MercuryWindow::GetCurrentWindow()->Width(); + int height = MercuryWindow::GetCurrentWindow()->Height(); + return (width != m_width)||(height != m_height); +} + +int RenderBuffer::GLType() +{ + switch( m_type ) + { + case TEXTURE: + case COLOR: + return GL_RGBA; + case DEPTH: + return GL_DEPTH_COMPONENT; + case STENCIL: + return GL_STENCIL_INDEX; + default: + return 0; + } +} + +int RenderBuffer::GLAttachPoint() +{ + switch( m_type ) + { + case TEXTURE: + case COLOR: + return GL_COLOR_ATTACHMENT0_EXT; + case DEPTH: + return GL_DEPTH_ATTACHMENT_EXT; + case STENCIL: + return GL_STENCIL_ATTACHMENT_EXT; + default: + return 0; + } +} + +void RenderBuffer::LoadFromXML(const XMLNode& node) +{ + MString t = node.Attribute("buffertype"); + + if ( t == "color" ) + { + m_type = COLOR; + } + else if ( t == "depth" ) + { + m_type = DEPTH; + } + else if ( t == "stencil" ) + { + m_type = STENCIL; + } + else if ( t == "texture" ) + { + m_type = TEXTURE; + } +} + +RenderBuffer* RenderBuffer::Generate() +{ + return new RenderBuffer(); +} + +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen * + * * + * * + * All rights reserved. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the following disclaimer. * + * * 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. * + * * Neither the name of the Mercury Engine nor the names of its * + * contributors may be used to endorse or promote products derived * + * from this software without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "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 THE COPYRIGHT * + * OWNER 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. * + ***************************************************************************/ Added: Mercury2/src/RenderBuffer.h =================================================================== --- Mercury2/src/RenderBuffer.h (rev 0) +++ Mercury2/src/RenderBuffer.h 2009-06-13 01:10:48 UTC (rev 312) @@ -0,0 +1,85 @@ +#ifndef RENDERBUFFER_H +#define RENDERBUFFER_H + +#include <MercuryAsset.h> + +class RenderBuffer : public MercuryAsset +{ + public: + enum RBType + { + NONE, + COLOR, + DEPTH, + STENCIL, + TEXTURE + }; + + RenderBuffer(); + virtual ~RenderBuffer(); + + virtual void Init(MercuryNode* node); + + virtual void PreRender(const MercuryNode* node); + virtual void Render(const MercuryNode* node); + virtual void PostRender(const MercuryNode* node); + virtual void LoadFromXML(const XMLNode& node); + + static RenderBuffer* Generate(); + + private: + virtual void InitRenderBuffer(); + void AllocateSpace(); + bool NeedResize(); + + int GLType(); + int GLAttachPoint(); + + uint32_t m_bufferID; + uint32_t m_textureID; + bool m_initiated; + int m_width, m_height; + RBType m_type; + + bool m_bound; + +// static void* m_lastRendered; + + protected: +// AlignedBuffer<float> m_vertexData; +// AlignedBuffer<uint16_t> m_indexData; +}; + +#endif + +/**************************************************************************** + * Copyright (C) 2009 by Joshua Allen * + * * + * * + * All rights reserved. * + * * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * Redistributions of source code must retain the above copyright * + * notice, this list of conditions and the following disclaimer. * + * * 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. * + * * Neither the name of the Mercury Engine nor the names of its * + * contributors may be used to endorse or promote products derived * + * from this software without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * + * "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 THE COPYRIGHT * + * OWNER 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. * + ***************************************************************************/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-14 13:07:40
|
Revision: 323 http://hgengine.svn.sourceforge.net/hgengine/?rev=323&view=rev Author: axlecrusher Date: 2009-06-14 13:07:39 +0000 (Sun, 14 Jun 2009) Log Message: ----------- udpates Modified Paths: -------------- Mercury2/src/MercuryFBO.cpp Mercury2/src/MercuryFBO.h Modified: Mercury2/src/MercuryFBO.cpp =================================================================== --- Mercury2/src/MercuryFBO.cpp 2009-06-14 13:05:36 UTC (rev 322) +++ Mercury2/src/MercuryFBO.cpp 2009-06-14 13:07:39 UTC (rev 323) @@ -61,7 +61,6 @@ for (uint8_t i = 0; i < m_numTextures; ++i) glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + i, GL_TEXTURE_2D, m_textures[i]->TextureID(), 0 ); - if( m_useDepth ) glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthBufferID ); } @@ -92,29 +91,27 @@ MString n = ssprintf("%s_%d", m_name.c_str(), i); m_textures[i]->MakeDynamic(m_width, m_height,n); } - Bind(); } + Bind(); + CHECKFBO; //Incomplete FBO + GLERRORCHECK; } - GLERRORCHECK; RenderableNode::PreRender(matrix); } void MercuryFBO::Render(const MercuryMatrix& matrix) { - if (m_lastRendered != m_fboID) - { - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fboID); -// CHECKFBO; //Incomplete FBO - GLERRORCHECK; - m_lastRendered = m_fboID; -// m_lastInStask = m_lastRendered; - } - - GLERRORCHECK; + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fboID); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GLERRORCHECK; + const GLenum buffers[8] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT, + GL_COLOR_ATTACHMENT3_EXT, GL_COLOR_ATTACHMENT4_EXT, GL_COLOR_ATTACHMENT5_EXT, + GL_COLOR_ATTACHMENT6_EXT, GL_COLOR_ATTACHMENT7_EXT }; + + glDrawBuffersARB( m_numTextures, buffers ); + glPushAttrib(GL_VIEWPORT_BIT); if ( !m_useScreenSize ) glViewport(0,0,m_width, m_height); @@ -126,21 +123,23 @@ void MercuryFBO::PostRender(const MercuryMatrix& matrix) { - GLERRORCHECK; glPopAttrib(); - -// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_lastInStask); -// m_lastRendered = m_lastInStask; RenderableNode::PostRender(matrix); - GLERRORCHECK; - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); //unbind +// for( uint8_t i = 0; i < m_numTextures; i++ ) +// { +// glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + i, GL_TEXTURE_2D, 0, 0 ); +// glActiveTextureARB( GL_TEXTURE0_ARB + i ); +// glDisable( GL_TEXTURE_2D ); +// } + glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); +// glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, 0 ); CHECKFBO; GLERRORCHECK; - m_lastRendered = 0; +// m_lastRendered = 0; } void MercuryFBO::LoadFromXML(const XMLNode& node) @@ -163,7 +162,7 @@ RenderableNode::LoadFromXML(node); } -uint32_t MercuryFBO::m_lastRendered = NULL; +//uint32_t MercuryFBO::m_lastRendered = NULL; /**************************************************************************** * Copyright (C) 2009 by Joshua Allen * Modified: Mercury2/src/MercuryFBO.h =================================================================== --- Mercury2/src/MercuryFBO.h 2009-06-14 13:05:36 UTC (rev 322) +++ Mercury2/src/MercuryFBO.h 2009-06-14 13:07:39 UTC (rev 323) @@ -38,7 +38,7 @@ MAutoPtr< Texture > m_textures[4]; uint8_t m_numTextures; - static uint32_t m_lastRendered; +// static uint32_t m_lastRendered; // uint32_t m_lastInStask; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-14 15:14:36
|
Revision: 326 http://hgengine.svn.sourceforge.net/hgengine/?rev=326&view=rev Author: axlecrusher Date: 2009-06-14 13:55:32 +0000 (Sun, 14 Jun 2009) Log Message: ----------- fix shader uniforms Modified Paths: -------------- Mercury2/src/Shader.cpp Mercury2/src/Shader.h Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-06-14 13:08:31 UTC (rev 325) +++ Mercury2/src/Shader.cpp 2009-06-14 13:55:32 UTC (rev 326) @@ -327,6 +327,7 @@ glGetActiveUniformARB( iProgramID, i, 1024, &bufflen, &size, &type, buffer ); buffer[bufflen] = 0; m_vShaderTabs[i] = SHADERATTRIBUTES.GetHandle( buffer ); + m_vShaderTabs[i]->name = buffer; } return true; } @@ -407,17 +408,19 @@ for( unsigned i = 0; i < m_vShaderTabs.size(); ++i ) { + int location = glGetUniformLocationARB( iProgramID, m_vShaderTabs[i]->name.c_str() ); + ShaderAttribute * sa = m_vShaderTabs[i]; - switch( sa->typ ) + switch( sa->type ) { case ShaderAttribute::TYPE_INT: case ShaderAttribute::TYPE_SAMPLER: - glUniform1iARB( i, sa->sau.iInt ); + glUniform1iARB( location, sa->value.iInt ); GLERRORCHECK; break; case ShaderAttribute::TYPE_FLOAT: case ShaderAttribute::TYPE_FLOATV4: - glUniform4fvARB( i, 4, &sa->sau.fFloatV4[0] ); + glUniform4fvARB( location, 4, &sa->value.fFloatV4[0] ); GLERRORCHECK; break; }; Modified: Mercury2/src/Shader.h =================================================================== --- Mercury2/src/Shader.h 2009-06-14 13:08:31 UTC (rev 325) +++ Mercury2/src/Shader.h 2009-06-14 13:55:32 UTC (rev 326) @@ -9,7 +9,7 @@ class ShaderAttribute { public: - ShaderAttribute() : typ( TYPE_INT ) { sau.iInt = 0; } + ShaderAttribute() : type( TYPE_INT ) { value.iInt = 0; } ///Type of ShaderAttribute for shader enum ShaderAttributeTyp @@ -18,7 +18,7 @@ TYPE_SAMPLER, ///Synonomous to 'sampler2D' when passing into a shader TYPE_FLOAT, ///Synonomous to 'float' when passing into a shader TYPE_FLOATV4 ///Synonomous to 'vec4' when passing into a shader - } typ; + } type; ///Actual data for value. union ShaderAttributeVal @@ -27,7 +27,9 @@ unsigned int iSampler; ///Synonomous to 'sampler2D' float fFloat; ///Synonomous to 'float' float fFloatV4[4]; ///Synonomous to 'vec4' - } sau; + } value; + + MString name; }; ///Shader Attribute Retainer This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-14 19:31:10
|
Revision: 332 http://hgengine.svn.sourceforge.net/hgengine/?rev=332&view=rev Author: axlecrusher Date: 2009-06-14 19:31:09 +0000 (Sun, 14 Jun 2009) Log Message: ----------- shader work Modified Paths: -------------- Mercury2/src/Shader.cpp Mercury2/src/Shader.h Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-06-14 19:21:19 UTC (rev 331) +++ Mercury2/src/Shader.cpp 2009-06-14 19:31:09 UTC (rev 332) @@ -72,8 +72,8 @@ void Shader::PostRender(const MercuryNode* node) { CurrentShader = OriginalShader; - if( OriginalShader ) - OriginalShader->ActivateShader(); + if( CurrentShader ) + CurrentShader->ActivateShader(); else DeactivateShader(); } @@ -314,7 +314,7 @@ } //Build the list of uniform tabs. - int iNumUniforms; +/* int iNumUniforms; glGetObjectParameterivARB( iProgramID, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &iNumUniforms ); m_vShaderTabs.resize( iNumUniforms ); for( int i = 0; i < iNumUniforms; ++i ) @@ -328,7 +328,7 @@ m_vShaderTabs[i] = SHADERATTRIBUTES.GetHandle( buffer ); m_vShaderTabs[i]->name = buffer; } - return true; +*/ return true; } void Shader::DestroyShader() @@ -404,30 +404,33 @@ void Shader::ActivateShader() { - if (iProgramID == 0) return; + if ( !iProgramID ) return; glUseProgramObjectARB( iProgramID ); GLERRORCHECK; - +/* for( unsigned i = 0; i < m_vShaderTabs.size(); ++i ) { int location = glGetUniformLocationARB( iProgramID, m_vShaderTabs[i]->name.c_str() ); - + ShaderAttribute * sa = m_vShaderTabs[i]; - switch( sa->type ) + if ( sa->ShaderControlled ) { - case ShaderAttribute::TYPE_INT: - case ShaderAttribute::TYPE_SAMPLER: - glUniform1iARB( location, sa->value.iInt ); - GLERRORCHECK; - break; - case ShaderAttribute::TYPE_FLOAT: - case ShaderAttribute::TYPE_FLOATV4: - glUniform4fvARB( location, 4, &sa->value.fFloatV4[0] ); - GLERRORCHECK; - break; - }; - } + switch( sa->type ) + { + case ShaderAttribute::TYPE_INT: + case ShaderAttribute::TYPE_SAMPLER: + glUniform1iARB( location, sa->value.iInt ); + GLERRORCHECK; + break; + case ShaderAttribute::TYPE_FLOAT: + case ShaderAttribute::TYPE_FLOATV4: + glUniform4fvARB( location, 4, &sa->value.fFloatV4[0] ); + GLERRORCHECK; + break; + }; + } + }*/ } void Shader::DeactivateShader() @@ -436,7 +439,13 @@ GLERRORCHECK; } +int32_t Shader::GetUniformLocation(const MString& n) +{ + if ( !iProgramID ) return -1; + return glGetUniformLocationARB( iProgramID, n.c_str() ); +} + /* * Copyright (c) 2009 Charles Lohr * All rights reserved. Modified: Mercury2/src/Shader.h =================================================================== --- Mercury2/src/Shader.h 2009-06-14 19:21:19 UTC (rev 331) +++ Mercury2/src/Shader.h 2009-06-14 19:31:09 UTC (rev 332) @@ -9,7 +9,7 @@ class ShaderAttribute { public: - ShaderAttribute() : type( TYPE_INT ) { value.iInt = 0; } + ShaderAttribute() : type( TYPE_INT ) { value.iInt = 0; ShaderControlled=0;} ///Type of ShaderAttribute for shader enum ShaderAttributeTyp @@ -30,6 +30,7 @@ } value; MString name; + bool ShaderControlled; }; ///Shader Attribute Retainer @@ -70,9 +71,11 @@ virtual void PostRender(const MercuryNode* node); static Shader* Generate() { return new Shader; } virtual void LoadFromXML(const XMLNode& node); + int32_t GetUniformLocation(const MString& n); ///Explicitly get the OpenGL ProgramID in the event you need it for advanced techniques unsigned int GetProgramID() { return iProgramID; } + inline static Shader* GetCurrentShader() { return CurrentShader; } private: void LoadShader( const MString& path, float priority ); @@ -143,7 +146,7 @@ through all attributes currently set up by dereferencing the pointers in the attributes repository. */ - std::vector< ShaderAttribute * > m_vShaderTabs; +// std::vector< ShaderAttribute * > m_vShaderTabs; ///Name of the shader MString sShaderName; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-14 20:16:56
|
Revision: 335 http://hgengine.svn.sourceforge.net/hgengine/?rev=335&view=rev Author: axlecrusher Date: 2009-06-14 20:16:34 +0000 (Sun, 14 Jun 2009) Log Message: ----------- faster get uniform Modified Paths: -------------- Mercury2/src/Shader.cpp Mercury2/src/Shader.h Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-06-14 19:46:39 UTC (rev 334) +++ Mercury2/src/Shader.cpp 2009-06-14 20:16:34 UTC (rev 335) @@ -314,9 +314,9 @@ } //Build the list of uniform tabs. -/* int iNumUniforms; + int iNumUniforms; glGetObjectParameterivARB( iProgramID, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &iNumUniforms ); - m_vShaderTabs.resize( iNumUniforms ); + m_uniforms.clear(); for( int i = 0; i < iNumUniforms; ++i ) { char buffer[1024]; @@ -325,10 +325,9 @@ GLenum type; glGetActiveUniformARB( iProgramID, i, 1024, &bufflen, &size, &type, buffer ); buffer[bufflen] = 0; - m_vShaderTabs[i] = SHADERATTRIBUTES.GetHandle( buffer ); - m_vShaderTabs[i]->name = buffer; + m_uniforms[buffer] = glGetUniformLocationARB( iProgramID, buffer ); } -*/ return true; + return true; } void Shader::DestroyShader() @@ -442,8 +441,9 @@ int32_t Shader::GetUniformLocation(const MString& n) { if ( !iProgramID ) return -1; - return glGetUniformLocationARB( iProgramID, n.c_str() ); - + std::map< MString, int >::iterator i = m_uniforms.find(n); + if ( i == m_uniforms.end() ) return -1; + return i->second; } /* Modified: Mercury2/src/Shader.h =================================================================== --- Mercury2/src/Shader.h 2009-06-14 19:46:39 UTC (rev 334) +++ Mercury2/src/Shader.h 2009-06-14 20:16:34 UTC (rev 335) @@ -147,6 +147,7 @@ the pointers in the attributes repository. */ // std::vector< ShaderAttribute * > m_vShaderTabs; + std::map< MString, int > m_uniforms; ///Name of the shader MString sShaderName; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-14 21:53:51
|
Revision: 337 http://hgengine.svn.sourceforge.net/hgengine/?rev=337&view=rev Author: axlecrusher Date: 2009-06-14 21:53:47 +0000 (Sun, 14 Jun 2009) Log Message: ----------- fix UV mapping so FBO works straight out of the buffer Modified Paths: -------------- Mercury2/src/FullscreenQuad.cpp Mercury2/src/Quad.cpp Modified: Mercury2/src/FullscreenQuad.cpp =================================================================== --- Mercury2/src/FullscreenQuad.cpp 2009-06-14 20:32:37 UTC (rev 336) +++ Mercury2/src/FullscreenQuad.cpp 2009-06-14 21:53:47 UTC (rev 337) @@ -12,12 +12,6 @@ void FullscreenQuad::Render(const MercuryNode* node) { - //reverse texture mapping for - glMatrixMode(GL_TEXTURE); - glPushMatrix(); - glLoadIdentity(); - glRotatef(180,1,0,0); - glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadMatrixf( m_matrix.Ptr() ); @@ -29,7 +23,6 @@ Quad::Render( node ); glPopMatrix(); - glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); } Modified: Mercury2/src/Quad.cpp =================================================================== --- Mercury2/src/Quad.cpp 2009-06-14 20:32:37 UTC (rev 336) +++ Mercury2/src/Quad.cpp 2009-06-14 21:53:47 UTC (rev 337) @@ -14,19 +14,21 @@ // float* buffer = m_vertexData.m_vertexData(); int i = 0; - m_vertexData[i++] = 0; m_vertexData[i++] = 1; + //UV oriented so 0,0 is lower left and 1,0 upper right. + //this makes it so FBO images render correctly right out of the buffer, no flip needed + m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = -1.0; m_vertexData[i++] = -0.5; m_vertexData[i++] = -0.5; m_vertexData[i++] = 0.0; - m_vertexData[i++] = 1; m_vertexData[i++] = 1; + m_vertexData[i++] = 1; m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = -1.0; m_vertexData[i++] = 0.5; m_vertexData[i++] = -0.5; m_vertexData[i++] = 0.0; - m_vertexData[i++] = 1; m_vertexData[i++] = 0; + m_vertexData[i++] = 1; m_vertexData[i++] = 1; m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = -1.0; m_vertexData[i++] = 0.5; m_vertexData[i++] = 0.5; m_vertexData[i++] = 0.0; - m_vertexData[i++] = 0; m_vertexData[i++] = 0; + m_vertexData[i++] = 0; m_vertexData[i++] = 1; m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = -1.0; m_vertexData[i++] = -0.5; m_vertexData[i++] = 0.5; m_vertexData[i++] = 0.0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-16 02:50:28
|
Revision: 341 http://hgengine.svn.sourceforge.net/hgengine/?rev=341&view=rev Author: axlecrusher Date: 2009-06-16 00:27:10 +0000 (Tue, 16 Jun 2009) Log Message: ----------- use a global uniform register Modified Paths: -------------- Mercury2/src/RenderGraph.cpp Mercury2/src/Shader.cpp Mercury2/src/Shader.h Mercury2/src/Texture.cpp Modified: Mercury2/src/RenderGraph.cpp =================================================================== --- Mercury2/src/RenderGraph.cpp 2009-06-15 00:08:01 UTC (rev 340) +++ Mercury2/src/RenderGraph.cpp 2009-06-16 00:27:10 UTC (rev 341) @@ -8,6 +8,7 @@ void RenderGraphEntry::Render() { MercuryMatrix modelView; + ShaderAttribute sa; if (m_node) { @@ -17,18 +18,11 @@ modelView.Transpose(); glLoadMatrixf( modelView.Ptr() ); - - Shader* currentShader = Shader::GetCurrentShader(); - if ( currentShader ) - { - int location = currentShader->GetUniformLocation("HG_ModelMatrix"); - if ( location != -1 ) - { - glUniformMatrix4fv(location, 1, 1,m_matrix->Ptr()); - GLERRORCHECK; - } - } + sa.type = ShaderAttribute::TYPE_MATRIX; + sa.value.matrix = m_matrix->Ptr(); + Shader::SetAttribute("HG_ModelMatrix", sa); + m_node->Render( modelView ); //calls on children assets } @@ -40,6 +34,7 @@ if (m_node) { glLoadMatrixf( modelView.Ptr() ); + Shader::SetAttribute("HG_ModelMatrix", sa); m_node->PostRender( modelView ); //calls on children assets } } Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-06-15 00:08:01 UTC (rev 340) +++ Mercury2/src/Shader.cpp 2009-06-16 00:27:10 UTC (rev 341) @@ -173,6 +173,7 @@ } free( Buffer ); } + return LinkShaders(); } @@ -327,6 +328,13 @@ glGetActiveUniformARB( iProgramID, i, 1024, &bufflen, &size, &type, buffer ); buffer[bufflen] = 0; m_uniforms[buffer] = glGetUniformLocationARB( iProgramID, buffer ); + + //load in global data if it exists + std::map< MString, ShaderAttribute >::iterator sai = m_globalAttributes.find( buffer ); + if (sai != m_globalAttributes.end()) + { + SetAttributeInternal(sai->first, sai->second); + } } return true; } @@ -408,29 +416,8 @@ glUseProgramObjectARB( iProgramID ); GLERRORCHECK; -/* - for( unsigned i = 0; i < m_vShaderTabs.size(); ++i ) - { - int location = glGetUniformLocationARB( iProgramID, m_vShaderTabs[i]->name.c_str() ); - - ShaderAttribute * sa = m_vShaderTabs[i]; - if ( sa->ShaderControlled ) - { - switch( sa->type ) - { - case ShaderAttribute::TYPE_INT: - case ShaderAttribute::TYPE_SAMPLER: - glUniform1iARB( location, sa->value.iInt ); - GLERRORCHECK; - break; - case ShaderAttribute::TYPE_FLOAT: - case ShaderAttribute::TYPE_FLOATV4: - glUniform4fvARB( location, 4, &sa->value.fFloatV4[0] ); - GLERRORCHECK; - break; - }; - } - }*/ + + //set global attributes here } void Shader::DeactivateShader() @@ -447,6 +434,46 @@ return i->second; } +void Shader::SetAttribute(const MString& name, const ShaderAttribute& x) +{ + m_globalAttributes[name] = x; + + Shader *current = GetCurrentShader(); + if (current) current->SetAttributeInternal( name, x ); +} + +void Shader::RemoveAttribute(const MString& name) +{ + std::map< MString, ShaderAttribute>::iterator i = m_globalAttributes.find( name ); + if ( i != m_globalAttributes.end() ) m_globalAttributes.erase( i ); + //no sense in unsetting it in the current shader, what would we set it to? +} + +void Shader::SetAttributeInternal(const MString& name, const ShaderAttribute& x) +{ + int location = GetUniformLocation( name ); + + if ( location != -1 ) + { + switch( x.type ) + { + case ShaderAttribute::TYPE_INT: + case ShaderAttribute::TYPE_SAMPLER: + glUniform1iARB( location, x.value.iInt ); + break; + case ShaderAttribute::TYPE_FLOAT: + case ShaderAttribute::TYPE_FLOATV4: + glUniform4fvARB( location, 4, &x.value.fFloatV4[0] ); + break; + case ShaderAttribute::TYPE_MATRIX: + glUniformMatrix4fv(location, 1, 1, x.value.matrix); //transpase too + }; + GLERRORCHECK; + } +} + +std::map< MString, ShaderAttribute> Shader::m_globalAttributes; + /* * Copyright (c) 2009 Charles Lohr * All rights reserved. Modified: Mercury2/src/Shader.h =================================================================== --- Mercury2/src/Shader.h 2009-06-15 00:08:01 UTC (rev 340) +++ Mercury2/src/Shader.h 2009-06-16 00:27:10 UTC (rev 341) @@ -5,11 +5,13 @@ #include <map> #include <vector> +#include <MercuryMatrix.h> + ///Basic Attribute for all shaders class ShaderAttribute { public: - ShaderAttribute() : type( TYPE_INT ) { value.iInt = 0; ShaderControlled=0;} + ShaderAttribute() : type( TYPE_INT ) { value.iInt = 0; } ///Type of ShaderAttribute for shader enum ShaderAttributeTyp @@ -17,7 +19,8 @@ TYPE_INT, ///Synonomous to 'int' when passing into a shader TYPE_SAMPLER, ///Synonomous to 'sampler2D' when passing into a shader TYPE_FLOAT, ///Synonomous to 'float' when passing into a shader - TYPE_FLOATV4 ///Synonomous to 'vec4' when passing into a shader + TYPE_FLOATV4, ///Synonomous to 'vec4' when passing into a shader + TYPE_MATRIX ///Synonomous to 'mat4' when passing into a shader } type; ///Actual data for value. @@ -27,10 +30,8 @@ unsigned int iSampler; ///Synonomous to 'sampler2D' float fFloat; ///Synonomous to 'float' float fFloatV4[4]; ///Synonomous to 'vec4' + const float* matrix; ///Synonomous to 'mat4' } value; - - MString name; - bool ShaderControlled; }; ///Shader Attribute Retainer @@ -71,7 +72,9 @@ virtual void PostRender(const MercuryNode* node); static Shader* Generate() { return new Shader; } virtual void LoadFromXML(const XMLNode& node); - int32_t GetUniformLocation(const MString& n); + + static void SetAttribute(const MString& name, const ShaderAttribute& x); + static void RemoveAttribute(const MString& name); ///Explicitly get the OpenGL ProgramID in the event you need it for advanced techniques unsigned int GetProgramID() { return iProgramID; } @@ -79,6 +82,10 @@ private: void LoadShader( const MString& path, float priority ); + int32_t GetUniformLocation(const MString& n); + + void SetAttributeInternal(const MString& name, const ShaderAttribute& x); + ///Suggested function for loading shaders. /** This function looks for {sShaderName}.vert and {sShaderName}.frag. It will attempt to load, compile and link the files. If any errors are found, they will @@ -142,11 +149,7 @@ unsigned int fragmentShader; ///Shader attributes - /** This is the system that helps make it possible to blast - through all attributes currently set up by dereferencing - the pointers in the attributes repository. - */ -// std::vector< ShaderAttribute * > m_vShaderTabs; + /** These are the attributes linked into the shader */ std::map< MString, int > m_uniforms; ///Name of the shader @@ -160,6 +163,9 @@ ///Original Shader (to re-enable when leaving) Shader * OriginalShader; + + //global uniform that should be applied to all shaders + static std::map< MString, ShaderAttribute > m_globalAttributes; }; #endif Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-06-15 00:08:01 UTC (rev 340) +++ Mercury2/src/Texture.cpp 2009-06-16 00:27:10 UTC (rev 341) @@ -132,17 +132,10 @@ GLERRORCHECK; - Shader* currentShader = Shader::GetCurrentShader(); - if ( currentShader ) - { - MString uname = ssprintf("HG_Texture%d", m_activeTextures); - int location = currentShader->GetUniformLocation( uname ); - if ( location != -1 ) - { - glUniform1i(location,m_activeTextures); - GLERRORCHECK; - } - } + ShaderAttribute sa; + sa.type = ShaderAttribute::TYPE_SAMPLER; + sa.value.iSampler = m_textureResource; + Shader::SetAttribute( ssprintf("HG_Texture%d", m_activeTextures), sa); ++m_activeTextures; ++m_textureBinds; @@ -155,6 +148,9 @@ glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisable( GL_TEXTURE_2D ); GLERRORCHECK; + + Shader::RemoveAttribute( ssprintf("HG_Texture%d", m_activeTextures) ); + --m_activeTextures; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-17 01:06:16
|
Revision: 344 http://hgengine.svn.sourceforge.net/hgengine/?rev=344&view=rev Author: axlecrusher Date: 2009-06-17 01:06:15 +0000 (Wed, 17 Jun 2009) Log Message: ----------- use list Modified Paths: -------------- Mercury2/src/Shader.cpp Mercury2/src/Shader.h Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-06-17 01:05:04 UTC (rev 343) +++ Mercury2/src/Shader.cpp 2009-06-17 01:06:15 UTC (rev 344) @@ -327,7 +327,9 @@ GLenum type; glGetActiveUniformARB( iProgramID, i, 1024, &bufflen, &size, &type, buffer ); buffer[bufflen] = 0; - m_uniforms[buffer] = glGetUniformLocationARB( iProgramID, buffer ); +// m_uniforms[buffer] = glGetUniformLocationARB( iProgramID, buffer ); + int location = glGetUniformLocationARB( iProgramID, buffer ); + m_uniforms.push_back( std::pair<MString,int> (buffer, location) ); } return true; } @@ -411,7 +413,7 @@ GLERRORCHECK; //set attributes here - std::map< MString, int >::iterator ui = m_uniforms.begin(); + std::list< std::pair< MString, int > >::iterator ui = m_uniforms.begin(); for (;ui != m_uniforms.end(); ++ui) { std::map< MString, ShaderAttribute >::iterator sai = m_globalAttributes.find( ui->first ); @@ -431,9 +433,11 @@ int32_t Shader::GetUniformLocation(const MString& n) { if ( !iProgramID ) return -1; - std::map< MString, int >::iterator i = m_uniforms.find(n); - if ( i == m_uniforms.end() ) return -1; - return i->second; + + std::list< std::pair< MString, int > >::iterator i = m_uniforms.begin(); + for (;i != m_uniforms.end(); ++i) + if (i->first == n) return i->second; + return -1; } void Shader::SetAttribute(const MString& name, const ShaderAttribute& x) Modified: Mercury2/src/Shader.h =================================================================== --- Mercury2/src/Shader.h 2009-06-17 01:05:04 UTC (rev 343) +++ Mercury2/src/Shader.h 2009-06-17 01:06:15 UTC (rev 344) @@ -149,8 +149,10 @@ unsigned int fragmentShader; ///Shader attributes - /** These are the attributes linked into the shader */ - std::map< MString, int > m_uniforms; + /** These are the attributes linked into the shader. + There are so few uniforms in a shader that a list with + a linear search should be faster than a tree*/ + std::list< std::pair< MString, int > > m_uniforms; ///Name of the shader MString sShaderName; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-21 02:53:08
|
Revision: 350 http://hgengine.svn.sourceforge.net/hgengine/?rev=350&view=rev Author: axlecrusher Date: 2009-06-21 01:49:14 +0000 (Sun, 21 Jun 2009) Log Message: ----------- no more renderable node Modified Paths: -------------- Mercury2/src/BoundingBox.h Mercury2/src/Mercury2.cpp Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryFBO.cpp Mercury2/src/MercuryFBO.h Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Mercury2/src/RenderGraph.cpp Mercury2/src/RenderGraph.h Mercury2/src/Shader.cpp Mercury2/src/Texture.cpp Mercury2/src/Viewport.cpp Mercury2/src/Viewport.h Modified: Mercury2/src/BoundingBox.h =================================================================== --- Mercury2/src/BoundingBox.h 2009-06-21 01:44:12 UTC (rev 349) +++ Mercury2/src/BoundingBox.h 2009-06-21 01:49:14 UTC (rev 350) @@ -1,7 +1,7 @@ #ifndef BOUNDINGBOX_H #define BOUNDINGBOX_H -#include <MercuryNode.h> +//#include <MercuryNode.h> #include <MercuryVertex.h> #include <MercuryMatrix.h> #include <Frustum.h> Modified: Mercury2/src/Mercury2.cpp =================================================================== --- Mercury2/src/Mercury2.cpp 2009-06-21 01:44:12 UTC (rev 349) +++ Mercury2/src/Mercury2.cpp 2009-06-21 01:49:14 UTC (rev 350) @@ -1,12 +1,12 @@ #include <MercuryWindow.h> #include <Quad.h> -#include <RenderableNode.h> +//#include <RenderableNode.h> #include <Viewport.h> #include <TransformNode.h> #include <XMLParser.h> -#include <RenderableNode.h> +//#include <RenderableNode.h> #include <MercuryCrash.h> #include <MercuryBacktrace.h> @@ -82,8 +82,10 @@ } w->Clear(); - renderGraph.Render(); +// renderGraph.Render(); // RenderableNode::RecursiveRender(root); +// printf("\n"); + root->RecursiveRender(); w->SwapBuffers(); ++m_count; Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-06-21 01:44:12 UTC (rev 349) +++ Mercury2/src/MercuryAsset.cpp 2009-06-21 01:49:14 UTC (rev 350) @@ -1,6 +1,6 @@ #include <MercuryAsset.h> -#include <RenderableNode.h> - +//#include <RenderableNode.h> +#include <MercuryNode.h> #include <GLHeaders.h> MercuryAsset::MercuryAsset() @@ -15,9 +15,8 @@ void MercuryAsset::Init(MercuryNode* node) { - RenderableNode* rn; - if ( (rn=RenderableNode::Cast( node )) ) - rn->AddRender(this); +// RenderableNode* rn; + if ( node ) node->AddRender(this); } void MercuryAsset::SetLoadState(LoadState ls) Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-06-21 01:44:12 UTC (rev 349) +++ Mercury2/src/MercuryAsset.h 2009-06-21 01:49:14 UTC (rev 350) @@ -2,13 +2,16 @@ #define MERCURYASSET_H #include <MAutoPtr.h> -#include <MercuryNode.h> #include <MessageHandler.h> -#include <map> #include <MercuryMatrix.h> #include <BoundingBox.h> #include <MSemaphore.h> +#include <XMLParser.h> +#include <Callback.h> +#include <map> +#include <list> + enum LoadState { LOADING, @@ -16,6 +19,8 @@ NONE }; +class MercuryNode; + /* Assets are stored in renderable nodes with MAuto pointers. The renderable nodes handle the memory management */ Modified: Mercury2/src/MercuryFBO.cpp =================================================================== --- Mercury2/src/MercuryFBO.cpp 2009-06-21 01:44:12 UTC (rev 349) +++ Mercury2/src/MercuryFBO.cpp 2009-06-21 01:49:14 UTC (rev 350) @@ -97,7 +97,7 @@ GLERRORCHECK; } - RenderableNode::PreRender(matrix); + MercuryNode::PreRender(matrix); } void MercuryFBO::Render(const MercuryMatrix& matrix) @@ -117,7 +117,7 @@ if ( !m_useScreenSize ) glViewport(0,0,m_width, m_height); GLERRORCHECK; - RenderableNode::Render(matrix); + MercuryNode::Render(matrix); GLERRORCHECK; } @@ -125,7 +125,7 @@ { glPopAttrib(); - RenderableNode::PostRender(matrix); + MercuryNode::PostRender(matrix); // for( uint8_t i = 0; i < m_numTextures; i++ ) // { @@ -159,7 +159,7 @@ if ( !node.Attribute("usescreensize").empty() ) m_useScreenSize = node.Attribute("usescreensize") == "true"?true:false; - RenderableNode::LoadFromXML(node); + MercuryNode::LoadFromXML(node); } //uint32_t MercuryFBO::m_lastRendered = NULL; Modified: Mercury2/src/MercuryFBO.h =================================================================== --- Mercury2/src/MercuryFBO.h 2009-06-21 01:44:12 UTC (rev 349) +++ Mercury2/src/MercuryFBO.h 2009-06-21 01:49:14 UTC (rev 350) @@ -1,10 +1,10 @@ #ifndef MERCURYFBO_H #define MERCURYFBO_H -#include <RenderableNode.h> +#include <MercuryNode.h> #include <Texture.h> -class MercuryFBO : public RenderableNode +class MercuryFBO : public MercuryNode { public: MercuryFBO(); Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-06-21 01:44:12 UTC (rev 349) +++ Mercury2/src/MercuryNode.cpp 2009-06-21 01:49:14 UTC (rev 350) @@ -1,13 +1,19 @@ #include <MercuryNode.h> #include <MercuryUtil.h> #include <UpdateThreader.h> +#include <TransformNode.h> +#include <Viewport.h> + +#include <GLHeaders.h> +#include <Shader.h> + using namespace std; REGISTER_NODE_TYPE(MercuryNode); MercuryNode::MercuryNode() - :m_parent(NULL), m_prevSibling(NULL), m_nextSibling(NULL) + :m_parent(NULL), m_prevSibling(NULL), m_nextSibling(NULL), m_hidden(false) { } @@ -98,6 +104,36 @@ child->RecursiveUpdate(dTime); } +void MercuryNode::RecursiveRender() +{ + MercuryMatrix modelView; + ShaderAttribute sa; + + MercuryMatrix matrix = FindGlobalMatrix(); + + PreRender( matrix ); //calls on children assets + modelView = ManipulateMatrix( matrix ); + if ( IsHidden() || IsCulled(modelView) ) return; + modelView.Transpose(); + + glLoadMatrixf( modelView.Ptr() ); + + sa.type = ShaderAttribute::TYPE_MATRIX; + sa.value.matrix = matrix.Ptr(); + Shader::SetAttribute("HG_ModelMatrix", sa); + + Render( modelView ); //calls on children assets + + //call render on other render graph entries under me + std::list< MercuryNode* >::iterator i; + for (i = m_children.begin(); i != m_children.end(); ++i ) + (*i)->RecursiveRender(); + + glLoadMatrixf( modelView.Ptr() ); + Shader::SetAttribute("HG_ModelMatrix", sa); + PostRender( modelView ); //calls on children assets +} + void MercuryNode::ThreadedUpdate(float dTime) { //XXX EXPERIMENTAL @@ -111,6 +147,10 @@ void MercuryNode::LoadFromXML(const XMLNode& node) { SetName( node.Attribute("name") ); + + if ( !node.Attribute("hidden").empty() ) + m_hidden = node.Attribute("hidden")=="true"?true:false; + //Not much to do here except run through all the children nodes for (XMLNode child = node.Child(); child.IsValid(); child = child.NextNode()) { @@ -121,9 +161,121 @@ node->LoadFromXML( child ); this->AddChild( node ); } + else if ( child.Name() == "asset" ) + { + MString key = child.Attribute("file"); + MAutoPtr< MercuryAsset > asset( AssetFactory::GetInstance().Generate( child.Attribute("type"), key ) ); + if ( asset.IsValid() ) + { + asset->LoadFromXML( child ); + this->AddAsset( asset ); + asset->Init( this ); + } + } } } + +void MercuryNode::PreRender(const MercuryMatrix& matrix) +{ + list< MercuryAsset* >::iterator i; + for (i = m_prerender.begin(); i != m_prerender.end(); ++i ) + (*i)->PreRender(this); +} + +void MercuryNode::Render(const MercuryMatrix& matrix) +{ + list< MercuryAsset* >::iterator i; + for (i = m_render.begin(); i != m_render.end(); ++i ) + (*i)->Render(this); +} + +void MercuryNode::PostRender(const MercuryMatrix& matrix) +{ + list< MercuryAsset* >::iterator i; + for (i = m_postrender.begin(); i != m_postrender.end(); ++i ) + (*i)->PostRender(this); +} + +const MercuryMatrix& MercuryNode::FindGlobalMatrix() const +{ + const MercuryNode* n = NULL; + const TransformNode* tn; + for (n = this; n; n = n->Parent()) + { + tn = TransformNode::Cast(n); + if ( tn ) + return tn->GetGlobalMatrix(); + } + + return MercuryMatrix::Identity(); +} + +void MercuryNode::AddPreRender(MercuryAsset* asset) +{ +#ifdef MCHECKASSETS + if ( !IsInAssetList(asset) ) //yell and scream + assert(!"Asset does not exist in list!"); +#endif + + m_prerender.push_back(asset); +} + +void MercuryNode::AddRender(MercuryAsset* asset) +{ +#ifdef MCHECKASSETS + if ( !IsInAssetList(asset) ) //yell and scream + assert(!"Asset does not exist in list!"); +#endif + + m_render.push_back(asset); +} +void MercuryNode::AddPostRender(MercuryAsset* asset) +{ +#ifdef MCHECKASSETS + if ( !IsInAssetList(asset) ) //yell and scream + assert(!"Asset does not exist in list!"); +#endif + + m_postrender.push_back(asset); +} + +bool MercuryNode::IsInAssetList( MercuryAsset* asset ) const +{ + std::list< MAutoPtr< MercuryAsset > >::const_iterator i; + for (i = m_assets.begin(); i != m_assets.end(); ++i ) + if ( (*i) == asset ) return true; + return false; +} + +bool MercuryNode::IsCulled(const MercuryMatrix& matrix) +{ + bool clip = false; + + std::list< MAutoPtr< MercuryAsset > >::iterator i; + for (i = m_assets.begin(); i != m_assets.end(); ++i ) + { + const BoundingVolume* bv = (*i)->GetBoundingVolume(); + if (bv) + { + BoundingVolume* v = bv->SpawnClone(); + v->Transform( matrix ); + clip = v->Clip( *FRUSTUM ); + delete v; + if ( clip == false ) return false; + } + else + return false; + } + return clip; +} + +MercuryMatrix MercuryNode::ManipulateMatrix(const MercuryMatrix& matrix) +{ + return VIEWMATRIX * matrix; +} + + NodeFactory& NodeFactory::GetInstance() { static NodeFactory* instance = NULL; Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-06-21 01:44:12 UTC (rev 349) +++ Mercury2/src/MercuryNode.h 2009-06-21 01:49:14 UTC (rev 350) @@ -8,6 +8,8 @@ #include <MercuryUtil.h> #include <MessageHandler.h> +#include <MercuryAsset.h> + /** This is the basic node of the scene graph. It is not intended to be instanced. Each node exists as a single entity in the scene graph. **/ @@ -44,6 +46,9 @@ virtual void RecursiveUpdate(float dTime); void ThreadedUpdate(float dTime); + + void RecursiveRender(); + ///Run on parent when a child is added virtual void OnAddChild() {}; @@ -65,6 +70,25 @@ inline void SetName(const MString& name) { m_name = name; } inline MString GetName() const { return m_name; } + inline void AddAsset(MAutoPtr< MercuryAsset > asset) { m_assets.push_back(asset); } + + void AddPreRender(MercuryAsset* asset); + void AddRender(MercuryAsset* asset); + void AddPostRender(MercuryAsset* asset); + + virtual void PreRender(const MercuryMatrix& matrix); + virtual void Render(const MercuryMatrix& matrix); + virtual void PostRender(const MercuryMatrix& matrix); + + ///This will get the world space matrix + const MercuryMatrix& FindGlobalMatrix() const; + + virtual bool IsCulled(const MercuryMatrix& matrix); + bool IsHidden() { return m_hidden; } + + virtual MercuryMatrix ManipulateMatrix(const MercuryMatrix& matrix); + + protected: std::list< MercuryNode* > m_children; //These nodes are unique, not instanced MercuryNode* m_parent; @@ -73,7 +97,19 @@ static bool m_rebuildRenderGraph; MString m_name; - + bool m_hidden; + private: + bool IsInAssetList(MercuryAsset* asset) const; + + //The asset is actually stored here + std::list< MAutoPtr< MercuryAsset > > m_assets; + + //we will just use normal pointers here because we don't want to waste too much time + //dereferencing the autopointer. As a precaution when assets are added to these lists, + //they must exist in m_assets. + std::list< MercuryAsset* > m_prerender; + std::list< MercuryAsset* > m_render; + std::list< MercuryAsset* > m_postrender; }; class NodeFactory Modified: Mercury2/src/RenderGraph.cpp =================================================================== --- Mercury2/src/RenderGraph.cpp 2009-06-21 01:44:12 UTC (rev 349) +++ Mercury2/src/RenderGraph.cpp 2009-06-21 01:49:14 UTC (rev 350) @@ -49,12 +49,12 @@ void RenderGraph::Build( MercuryNode* node, RenderGraphEntry& entry) { RenderGraphEntry* lastEntry = &entry; - RenderableNode* rn = RenderableNode::Cast(node); +// MercuryNode* rn = MercuryNode::Cast(node); - if ( rn ) + if ( node ) { //found a new renderable - entry.m_children.push_back( RenderGraphEntry(&rn->FindGlobalMatrix(), rn) ); + entry.m_children.push_back( RenderGraphEntry(&(node->FindGlobalMatrix()), node) ); lastEntry = &(entry.m_children.back()); } Modified: Mercury2/src/RenderGraph.h =================================================================== --- Mercury2/src/RenderGraph.h 2009-06-21 01:44:12 UTC (rev 349) +++ Mercury2/src/RenderGraph.h 2009-06-21 01:49:14 UTC (rev 350) @@ -2,7 +2,7 @@ #define RENDERGRAPH_H #include <MercuryNode.h> -#include <RenderableNode.h> +//#include <RenderableNode.h> class RenderGraphEntry { @@ -14,14 +14,14 @@ m_matrix = &MercuryMatrix::Identity(); } - RenderGraphEntry(const MercuryMatrix* matrix, RenderableNode* node) + RenderGraphEntry(const MercuryMatrix* matrix, MercuryNode* node) :m_node(node), m_matrix(matrix) {} void AddChild(RenderGraphEntry entry); void Render(); private: - RenderableNode* m_node; //we don't own this, no new or free + MercuryNode* m_node; //we don't own this, no new or free std::list< RenderGraphEntry > m_children; const MercuryMatrix* m_matrix; }; Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-06-21 01:44:12 UTC (rev 349) +++ Mercury2/src/Shader.cpp 2009-06-21 01:49:14 UTC (rev 350) @@ -1,5 +1,5 @@ #include <Shader.h> -#include <RenderableNode.h> +#include <MercuryNode.h> #include <MercuryFile.h> #include <GLHeaders.h> @@ -44,9 +44,8 @@ void Shader::Init(MercuryNode* node) { MercuryAsset::Init( node ); - RenderableNode* rn = RenderableNode::Cast( node ); - if ( rn ) - rn->AddPostRender( this ); +// RenderableNode* rn = RenderableNode::Cast( node ); + if ( node ) node->AddPostRender( this ); } void Shader::Render(const MercuryNode* node) Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-06-21 01:44:12 UTC (rev 349) +++ Mercury2/src/Texture.cpp 2009-06-21 01:49:14 UTC (rev 350) @@ -1,7 +1,7 @@ #include <Texture.h> -#include <RenderableNode.h> +//#include <RenderableNode.h> #include <ImageLoader.h> - +#include <MercuryNode.h> #include <GLHeaders.h> #include <Shader.h> @@ -38,9 +38,8 @@ { MercuryAsset::Init( node ); - RenderableNode* rn = RenderableNode::Cast( node ); - if ( rn ) - rn->AddPostRender( this ); +// RenderableNode* rn = RenderableNode::Cast( node ); + if ( node ) node->AddPostRender( this ); } void Texture::LoadFromRaw() Modified: Mercury2/src/Viewport.cpp =================================================================== --- Mercury2/src/Viewport.cpp 2009-06-21 01:44:12 UTC (rev 349) +++ Mercury2/src/Viewport.cpp 2009-06-21 01:49:14 UTC (rev 350) @@ -65,7 +65,7 @@ StrToFloat(node.Attribute("near")), StrToFloat(node.Attribute("far"))); - RenderableNode::LoadFromXML(node); + MercuryNode::LoadFromXML(node); } Modified: Mercury2/src/Viewport.h =================================================================== --- Mercury2/src/Viewport.h 2009-06-21 01:44:12 UTC (rev 349) +++ Mercury2/src/Viewport.h 2009-06-21 01:49:14 UTC (rev 350) @@ -1,7 +1,7 @@ #ifndef VIEWPORT_H #define VIEWPORT_H -#include <RenderableNode.h> +#include <MercuryNode.h> #include <MercuryMatrix.h> #include <MercuryVertex.h> #include <MercuryPlane.h> @@ -12,7 +12,7 @@ extern MercuryVertex EYE; extern MercuryVector LOOKAT; -class Viewport : public RenderableNode +class Viewport : public MercuryNode { public: Viewport(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-21 02:53:20
|
Revision: 353 http://hgengine.svn.sourceforge.net/hgengine/?rev=353&view=rev Author: axlecrusher Date: 2009-06-21 01:54:13 +0000 (Sun, 21 Jun 2009) Log Message: ----------- remove Removed Paths: ------------- Mercury2/src/RenderableNode.cpp Mercury2/src/RenderableNode.h Deleted: Mercury2/src/RenderableNode.cpp =================================================================== --- Mercury2/src/RenderableNode.cpp 2009-06-21 01:52:15 UTC (rev 352) +++ Mercury2/src/RenderableNode.cpp 2009-06-21 01:54:13 UTC (rev 353) @@ -1,188 +0,0 @@ -#include <RenderableNode.h> -#include <assert.h> -#include <GLHeaders.h> -#include <TransformNode.h> -//#include <unistd.h> -#include <Viewport.h> - -using namespace std; - -REGISTER_NODE_TYPE(RenderableNode); - -RenderableNode::RenderableNode() - :m_hidden(false) -{ -} - -RenderableNode::~RenderableNode() -{ - m_prerender.clear(); - m_render.clear(); - m_postrender.clear(); -} - -void RenderableNode::Update(float dTime) -{ - /* - MercuryMatrix m = FindGlobalMatrix(); - - std::list< MAutoPtr< MercuryAsset > >::iterator i; - for (i = m_assets.begin(); i != m_assets.end(); ++i ) - { - const BoundingVolume* v = (*i)->GetBoundingVolume(); - if (v) - { - BoundingVolume* nv = v->SpawnClone(); - nv->Transform(m); - SAFE_DELETE(nv); - //do some stuff to figure out if this node is culled - } - } - */ -} - -void RenderableNode::PreRender(const MercuryMatrix& matrix) -{ - list< MercuryAsset* >::iterator i; - for (i = m_prerender.begin(); i != m_prerender.end(); ++i ) - (*i)->PreRender(this); -} - -void RenderableNode::Render(const MercuryMatrix& matrix) -{ - list< MercuryAsset* >::iterator i; - for (i = m_render.begin(); i != m_render.end(); ++i ) - (*i)->Render(this); -} - -void RenderableNode::PostRender(const MercuryMatrix& matrix) -{ - list< MercuryAsset* >::iterator i; - for (i = m_postrender.begin(); i != m_postrender.end(); ++i ) - (*i)->PostRender(this); -} - -const MercuryMatrix& RenderableNode::FindGlobalMatrix() const -{ - MercuryNode* n = NULL; - TransformNode* tn; - for (n = Parent(); n; n = n->Parent()) - { - tn = TransformNode::Cast(n); - if ( tn ) - return tn->GetGlobalMatrix(); - } - - return MercuryMatrix::Identity(); -} - -void RenderableNode::AddPreRender(MercuryAsset* asset) -{ -#ifdef MCHECKASSETS - if ( !IsInAssetList(asset) ) //yell and scream - assert(!"Asset does not exist in list!"); -#endif - - m_prerender.push_back(asset); -} - -void RenderableNode::AddRender(MercuryAsset* asset) -{ -#ifdef MCHECKASSETS - if ( !IsInAssetList(asset) ) //yell and scream - assert(!"Asset does not exist in list!"); -#endif - - m_render.push_back(asset); -} -void RenderableNode::AddPostRender(MercuryAsset* asset) -{ -#ifdef MCHECKASSETS - if ( !IsInAssetList(asset) ) //yell and scream - assert(!"Asset does not exist in list!"); -#endif - - m_postrender.push_back(asset); -} - -bool RenderableNode::IsInAssetList( MercuryAsset* asset ) const -{ - std::list< MAutoPtr< MercuryAsset > >::const_iterator i; - for (i = m_assets.begin(); i != m_assets.end(); ++i ) - if ( (*i) == asset ) return true; - return false; -} - -void RenderableNode::LoadFromXML(const XMLNode& node) -{ - if ( !node.Attribute("hidden").empty() ) - m_hidden = node.Attribute("hidden")=="true"?true:false; - - for (XMLNode child = node.Child(); child.IsValid(); child = child.NextNode()) - { - if ( child.Name() == "asset" ) - { - MString key = child.Attribute("file"); - MAutoPtr< MercuryAsset > asset( AssetFactory::GetInstance().Generate( child.Attribute("type"), key ) ); - if ( asset.IsValid() ) - { - asset->LoadFromXML( child ); - this->AddAsset( asset ); - asset->Init( this ); - } - } - } - - MercuryNode::LoadFromXML( node ); -} - -bool RenderableNode::IsCulled(const MercuryMatrix& matrix) -{ - bool clip = false; - - std::list< MAutoPtr< MercuryAsset > >::iterator i; - for (i = m_assets.begin(); i != m_assets.end(); ++i ) - { - const BoundingVolume* bv = (*i)->GetBoundingVolume(); - if (bv) - { - BoundingVolume* v = bv->SpawnClone(); - v->Transform( matrix ); - clip = v->Clip( *FRUSTUM ); - delete v; - if ( clip == false ) return false; - } - else - return false; - } - return clip; -} - -MercuryMatrix RenderableNode::ManipulateMatrix(const MercuryMatrix& matrix) -{ - return VIEWMATRIX * matrix; -} - -/*************************************************************************** - * Copyright (C) 2008 by Joshua Allen * - * * - * * - * All rights reserved. * - * * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * - * * 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. * - * * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. * - * * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * - * "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 THE COPYRIGHT OWNER 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. * - ***************************************************************************/ Deleted: Mercury2/src/RenderableNode.h =================================================================== --- Mercury2/src/RenderableNode.h 2009-06-21 01:52:15 UTC (rev 352) +++ Mercury2/src/RenderableNode.h 2009-06-21 01:54:13 UTC (rev 353) @@ -1,83 +0,0 @@ -#ifndef RENDERABLENODE_H -#define RENDERABLENODE_H - -#include <MercuryNode.h> -#include <MAutoPtr.h> -#include <MercuryAsset.h> -#include <MercuryMatrix.h> -#include <MSemaphore.h> -#include <Mint.h> - -#define MCHECKASSETS - -class RenderableNode : public MercuryNode -{ - public: - RenderableNode(); - ~RenderableNode(); - - virtual void Update(float dTime); - - inline void AddAsset(MAutoPtr< MercuryAsset > asset) { m_assets.push_back(asset); } - - void AddPreRender(MercuryAsset* asset); - void AddRender(MercuryAsset* asset); - void AddPostRender(MercuryAsset* asset); - - ///This will get the world space matrix - virtual void PreRender(const MercuryMatrix& matrix); - - virtual void Render(const MercuryMatrix& matrix); - - virtual void PostRender(const MercuryMatrix& matrix); - - virtual void LoadFromXML(const XMLNode& node); - - const MercuryMatrix& FindGlobalMatrix() const; - - virtual bool IsCulled(const MercuryMatrix& matrix); - bool IsHidden() { return m_hidden; } - - virtual MercuryMatrix ManipulateMatrix(const MercuryMatrix& matrix); - - GENRTTI(RenderableNode); - protected: - bool m_hidden; - private: - bool IsInAssetList(MercuryAsset* asset) const; - - //The asset is actually stored here - std::list< MAutoPtr< MercuryAsset > > m_assets; - - //we will just use normal pointers here because we don't want to waste too much time - //dereferencing the autopointer. As a precaution when assets are added to these lists, - //they must exist in m_assets. - std::list< MercuryAsset* > m_prerender; - std::list< MercuryAsset* > m_render; - std::list< MercuryAsset* > m_postrender; -}; - -#endif -/*************************************************************************** - * Copyright (C) 2008 by Joshua Allen * - * * - * * - * All rights reserved. * - * * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * - * * 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. * - * * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. * - * * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * - * "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 THE COPYRIGHT OWNER 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. * - ***************************************************************************/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-21 13:06:47
|
Revision: 356 http://hgengine.svn.sourceforge.net/hgengine/?rev=356&view=rev Author: axlecrusher Date: 2009-06-21 13:06:46 +0000 (Sun, 21 Jun 2009) Log Message: ----------- unneeded Modified Paths: -------------- Mercury2/src/Shader.cpp Mercury2/src/Shader.h Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-06-21 02:57:59 UTC (rev 355) +++ Mercury2/src/Shader.cpp 2009-06-21 13:06:46 UTC (rev 356) @@ -11,8 +11,7 @@ REGISTER_ASSET_TYPE( Shader ); -ShaderAttributesSet SHADERATTRIBUTES; -Shader * Shader::CurrentShader; +Shader * Shader::CurrentShader = NULL; ShaderAttribute * ShaderAttributesSet::GetHandle( const MString & sName ) { Modified: Mercury2/src/Shader.h =================================================================== --- Mercury2/src/Shader.h 2009-06-21 02:57:59 UTC (rev 355) +++ Mercury2/src/Shader.h 2009-06-21 13:06:46 UTC (rev 356) @@ -50,8 +50,6 @@ std::map< MString, ShaderAttribute * > m_AllShaderAttributes; }; -extern ShaderAttributesSet SHADERATTRIBUTES; - ///Basic element for turning shaders on and off /** This class helps aide in the loading and use of shaders. It allows loading of files through the LoadShader() function that actively looks for .frag and .vert files. By use @@ -161,7 +159,7 @@ float fPriority; ///Global static shader (so shaders can recursively activate and deactivate shaders) - static Shader * CurrentShader; + static Shader* CurrentShader; ///Original Shader (to re-enable when leaving) Shader * OriginalShader; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-06-21 14:01:13
|
Revision: 357 http://hgengine.svn.sourceforge.net/hgengine/?rev=357&view=rev Author: axlecrusher Date: 2009-06-21 13:49:48 +0000 (Sun, 21 Jun 2009) Log Message: ----------- don't use pair Modified Paths: -------------- Mercury2/src/Shader.cpp Mercury2/src/Shader.h Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-06-21 13:06:46 UTC (rev 356) +++ Mercury2/src/Shader.cpp 2009-06-21 13:49:48 UTC (rev 357) @@ -327,7 +327,7 @@ buffer[bufflen] = 0; // m_uniforms[buffer] = glGetUniformLocationARB( iProgramID, buffer ); int location = glGetUniformLocationARB( iProgramID, buffer ); - m_uniforms.push_back( std::pair<MString,int> (buffer, location) ); + m_uniforms.push_back( UniformMap(buffer, location) ); } return true; } @@ -411,10 +411,10 @@ GLERRORCHECK; //set attributes here - std::list< std::pair< MString, int > >::iterator ui = m_uniforms.begin(); + std::list< UniformMap >::iterator ui = m_uniforms.begin(); for (;ui != m_uniforms.end(); ++ui) { - std::map< MString, ShaderAttribute >::iterator sai = m_globalAttributes.find( ui->first ); + std::map< MString, ShaderAttribute >::iterator sai = m_globalAttributes.find( ui->name ); if (sai != m_globalAttributes.end()) { SetAttributeInternal(sai->first, sai->second); @@ -432,9 +432,9 @@ { if ( !iProgramID ) return -1; - std::list< std::pair< MString, int > >::iterator i = m_uniforms.begin(); + std::list< UniformMap >::iterator i = m_uniforms.begin(); for (;i != m_uniforms.end(); ++i) - if (i->first == n) return i->second; + if (i->name == n) return i->id; return -1; } Modified: Mercury2/src/Shader.h =================================================================== --- Mercury2/src/Shader.h 2009-06-21 13:06:46 UTC (rev 356) +++ Mercury2/src/Shader.h 2009-06-21 13:49:48 UTC (rev 357) @@ -50,6 +50,16 @@ std::map< MString, ShaderAttribute * > m_AllShaderAttributes; }; +class UniformMap +{ + public: + UniformMap(MString n, int i) + :name(n), id(i) + {} + MString name; + int id; +}; + ///Basic element for turning shaders on and off /** This class helps aide in the loading and use of shaders. It allows loading of files through the LoadShader() function that actively looks for .frag and .vert files. By use @@ -150,7 +160,7 @@ /** These are the attributes linked into the shader. There are so few uniforms in a shader that a list with a linear search should be faster than a tree*/ - std::list< std::pair< MString, int > > m_uniforms; + std::list< UniformMap > m_uniforms; ///Name of the shader MString sShaderName; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |