Jelajahi Sumber

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

Ivan Safrin 13 tahun lalu
induk
melakukan
2fd2c4cf5a

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

@@ -37,7 +37,25 @@ namespace Polycode {
 	public:
 	public:
 		String propName;
 		String propName;
 		String propValue;		
 		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.
 	* 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;	
 			bool enableScissor;	
 			Polycode::Rectangle scissorBox;			
 			Polycode::Rectangle scissorBox;			
 		
 		
+			Vector3 position;
+			Vector3 scale;		
+			Rotation rotation;
+	
 		protected:
 		protected:
 		
 		
 			void *userData;
 			void *userData;
@@ -602,25 +624,21 @@ namespace Polycode {
 			Vector3 childCenter;
 			Vector3 childCenter;
 			Number bBoxRadius;		
 			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 qYaw;
 			Quaternion qPitch;
 			Quaternion qPitch;
 			Quaternion qRoll;			
 			Quaternion qRoll;			
-			Quaternion rotationQuat;	
-		
+			Quaternion rotationQuat;
+			
+			
+			bool lockMatrix;
+			bool matrixDirty;
+			Matrix4 transformMatrix;		
+			Number matrixAdj;		
+			Entity *parentEntity;
 		
 		
 			Renderer *renderer;
 			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);
 		void setHitbox(Number width, Number height, Number left, Number top);
 		void setHitbox(Number width, Number height, Number left, Number top);
 
 
+		Number width;
+		Number height;
+
 	protected:
 	protected:
 	
 	
 		bool focusable;
 		bool focusable;
@@ -195,8 +198,6 @@ class _PolyExport ScreenEntity : public Entity, public EventDispatcher {
 		Number dragOffsetY;
 		Number dragOffsetY;
 		
 		
 		bool mouseOver;
 		bool mouseOver;
-		Number width;
-		Number height;
 
 
 		Rectangle hit;
 		Rectangle hit;
 		
 		

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

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