Просмотр исходного кода

Transform can now be set via public position,scale and rotation members in Entity. width and height now public in ScreenEntity

Ivan Safrin 13 лет назад
Родитель
Сommit
2fd2c4cf5a

+ 35 - 17
Core/Contents/Include/PolyEntity.h

@@ -37,7 +37,25 @@ namespace Polycode {
 	public:
 		String propName;
 		String propValue;		
-	};	
+	};
+
+	class _PolyExport Rotation {
+		public:
+			Rotation();
+						
+			Number pitch;
+			Number yaw;			
+			Number roll;		
+			
+			inline bool operator == ( const Rotation& r2)  {
+				return (r2.pitch == pitch && r2.roll == roll && r2.yaw == yaw);
+			}		
+
+			inline bool operator != ( const Rotation& r2)  {
+				return (r2.pitch != pitch || r2.yaw != yaw || r2.roll != roll);
+			}				
+			
+	};
 
 	/**
 	* Base class for both 2D and 3D objects in Polycode. It provides position and color transformations as well as hierarchy for all Polycode objects.
@@ -593,6 +611,10 @@ namespace Polycode {
 			bool enableScissor;	
 			Polycode::Rectangle scissorBox;			
 		
+			Vector3 position;
+			Vector3 scale;		
+			Rotation rotation;
+	
 		protected:
 		
 			void *userData;
@@ -602,25 +624,21 @@ namespace Polycode {
 			Vector3 childCenter;
 			Number bBoxRadius;		
 		
-			Vector3 position;
-			Vector3 scale;		
-		
-			bool lockMatrix;
-			bool matrixDirty;
-			Matrix4 transformMatrix;
-		
-			Number matrixAdj;
-			Number pitch;
-			Number yaw;			
-			Number roll;
-		
-			Entity *parentEntity;
-		
+			Vector3 _position;
+			Vector3 _scale;		
+			Rotation _rotation;
+			
 			Quaternion qYaw;
 			Quaternion qPitch;
 			Quaternion qRoll;			
-			Quaternion rotationQuat;	
-		
+			Quaternion rotationQuat;
+			
+			
+			bool lockMatrix;
+			bool matrixDirty;
+			Matrix4 transformMatrix;		
+			Number matrixAdj;		
+			Entity *parentEntity;
 		
 			Renderer *renderer;
 	};

+ 3 - 2
Core/Contents/Include/PolyScreenEntity.h

@@ -185,6 +185,9 @@ class _PolyExport ScreenEntity : public Entity, public EventDispatcher {
 		void setHitbox(Number width, Number height);
 		void setHitbox(Number width, Number height, Number left, Number top);
 
+		Number width;
+		Number height;
+
 	protected:
 	
 		bool focusable;
@@ -195,8 +198,6 @@ class _PolyExport ScreenEntity : public Entity, public EventDispatcher {
 		Number dragOffsetY;
 		
 		bool mouseOver;
-		Number width;
-		Number height;
 
 		Rectangle hit;
 		

+ 49 - 34
Core/Contents/Source/PolyEntity.cpp

@@ -24,12 +24,15 @@
 
 using namespace Polycode;
 
+Rotation::Rotation() {
+	pitch = 0;
+	yaw = 0;
+	roll = 0;		
+}
+
 Entity::Entity() {
 	userData = NULL;
 	scale.set(1,1,1);
-	pitch = 0;
-	yaw = 0;
-	roll = 0;
 	renderer = NULL;
 	enabled = true;
 	depthTest = true;
@@ -234,6 +237,23 @@ void Entity::doUpdates() {
 }
 
 void Entity::updateEntityMatrix() {	
+
+	if(_position != position) {
+		_position = position;
+		matrixDirty = true;
+	}
+
+	if(_scale != scale) {
+		_scale = scale;
+		matrixDirty = true;
+	}
+
+	if(_rotation != rotation) {
+		_rotation = rotation;
+		rebuildRotation();
+		matrixDirty = true;
+	}
+
 	if(matrixDirty)
 		rebuildTransformMatrix();
 	
@@ -255,7 +275,7 @@ Vector3 Entity::getCompoundScale() const {
 
 Matrix4 Entity::getConcatenatedRollMatrix() const {
 	Quaternion q;
-	q.createFromAxisAngle(0.0f, 0.0f, 1.0f, roll*matrixAdj);
+	q.createFromAxisAngle(0.0f, 0.0f, 1.0f, _rotation.roll*matrixAdj);
 	Matrix4 transformMatrix = q.createMatrix();	
 	
 	if(parentEntity != NULL) 
@@ -379,18 +399,6 @@ Quaternion Entity::getRotationQuat() const {
 	return rotationQuat;
 }
 
-void Entity::setPitch(Number pitch) {
-	this->pitch = pitch;
-	rebuildRotation();	
-	matrixDirty = true;
-}
-
-void Entity::setYaw(Number yaw) {
-	this->yaw = yaw;
-	rebuildRotation();	
-	matrixDirty = true;
-}
-
 Vector3 Entity::getScale() const {
 	return scale;
 }
@@ -410,31 +418,38 @@ const Matrix4& Entity::getTransformMatrix() const {
 }
 
 void Entity::Pitch(Number pitch) {
-	this->pitch += pitch;
-	rebuildRotation();	
+	rotation.pitch += pitch;
 	matrixDirty = true;
 }
 
 void Entity::Yaw(Number yaw) {
-	this->yaw += yaw;
-	rebuildRotation();	
+	rotation.yaw += yaw;
 	matrixDirty = true;
 }
 
 void Entity::Roll(Number roll) {
-	this->roll += roll;
-	rebuildRotation();
+	rotation.roll += roll;
 	matrixDirty = true;
 }
 
 void Entity::setRoll(Number roll) {
-	this->roll= roll;
-	rebuildRotation();
+	rotation.roll = roll;
 	matrixDirty = true;
 }
 
+void Entity::setPitch(Number pitch) {
+	rotation.pitch = pitch;
+	matrixDirty = true;
+}
+
+void Entity::setYaw(Number yaw) {
+	rotation.yaw = yaw;
+	matrixDirty = true;
+}
+
+
 void Entity::rebuildRotation() {
-	rotationQuat.fromAxes(pitch, yaw, roll);
+	rotationQuat.fromAxes(_rotation.pitch, _rotation.yaw, _rotation.roll);
 }
 
 String Entity::getEntityProp(const String& propName) {
@@ -458,15 +473,15 @@ void Entity::setParentEntity(Entity *entity) {
 }
 
 Number Entity::getPitch() const {
-	return pitch;
+	return rotation.pitch;
 }
 
 Number Entity::getYaw() const {
-	return yaw;
+	return rotation.yaw;
 }
 
 Number Entity::getRoll() const {
-	return roll;
+	return rotation.roll;
 }
 
 void Entity::setTransformByMatrixPure(const Matrix4& matrix) {
@@ -569,22 +584,22 @@ Vector3 Entity::getPosition() const {
 
 Number Entity::getCombinedPitch() const {
 	if(parentEntity != NULL)
-		return parentEntity->getCombinedPitch()+pitch;
+		return parentEntity->getCombinedPitch()+rotation.pitch;
 	else
-		return pitch;
+		return rotation.pitch;
 }
 
 Number Entity::getCombinedYaw() const {
 	if(parentEntity != NULL)
-		return parentEntity->getCombinedYaw()+yaw;
+		return parentEntity->getCombinedYaw()+rotation.yaw;
 	else
-		return yaw;
+		return rotation.yaw;
 }
 
 Number Entity::getCombinedRoll() const {
 	if(parentEntity != NULL)
-		return parentEntity->getCombinedRoll()+roll;
+		return parentEntity->getCombinedRoll()+rotation.roll;
 	else
-		return roll;
+		return rotation.roll;
 	
 }

+ 1 - 0
Core/Contents/Source/PolyScreenEntity.cpp

@@ -618,6 +618,7 @@ Vector2 ScreenEntity::getPosition2D() const {
 }
 
 Matrix4 ScreenEntity::buildPositionMatrix() {
+
 	Matrix4 posMatrix;
 	switch(positionMode) {
 		case POSITION_TOPLEFT: