From 2f52f3c441c4c1b526ab9ee3f0eb944f117ae43e Mon Sep 17 00:00:00 2001
From: Shon Ferguson <shonferg@users.sourceforge.net>
Date: Sun, 16 Jul 2006 03:37:07 +0000
Subject: [PATCH] Added a != operator to Vector3. Initialized TexCoord values
 to 0.0f. Added Visibility flag functions to NiAVObject.cpp Fixed
 NiTexturingProperty::SetTexture to set the internal hasXTexture variables
 correctly.

---
 nif_math.cpp                | 13 +++++++++++--
 nif_math.h                  |  9 +++++++--
 obj/NiAVObject.cpp          | 16 ++++++++++++++++
 obj/NiAVObject.h            | 10 ++++++++++
 obj/NiTexturingProperty.cpp |  8 ++++++++
 5 files changed, 52 insertions(+), 4 deletions(-)

diff --git a/nif_math.cpp b/nif_math.cpp
index 2d059de3..a6c3d6bd 100644
--- a/nif_math.cpp
+++ b/nif_math.cpp
@@ -100,6 +100,13 @@ bool Vector3::operator==( const Vector3 & rh) const {
 		return false;
 }
 
+bool Vector3::operator!=( const Vector3 & rh) const {
+	if (rh.x == x && rh.y == y && rh.z == z)
+		return false;
+	else
+		return true;
+}
+
 float Vector3::DotProduct( const Vector3 & rh) const {
 	return x * rh.x + y * rh.y + z * rh.z;
 }
@@ -251,14 +258,16 @@ Matrix33 Matrix44::GetRotation() const {
 	return m;
 }
 
-Vector3 Matrix44::GetScale() const {
+float Matrix44::GetScale() const {
 	const Matrix44 & m = *this;
 	float scale[3];
 	for (int r = 0; r < 3; ++r) {
 		//Get scale for this row
 		scale[r] = Vector3( m[r][0], m[r][1], m[r][2] ).Magnitude();
 	}
-	return Vector3( scale[0], scale[1], scale[2] );
+	 
+	//averate the scale since NIF doesn't support discreet scaling
+	return (scale[0] + scale[1] + scale[2]) / 3.0f;
 }
 
 
diff --git a/nif_math.h b/nif_math.h
index ab10fd88..413a82e0 100644
--- a/nif_math.h
+++ b/nif_math.h
@@ -36,7 +36,7 @@ struct NIFLIB_API TexCoord {
 	float v; /*!< The V value in this coordinate pair. */ 
 
 	/*! Default constructor	*/
-	TexCoord() {}
+	TexCoord() : u(0.0f), v(0.0f) {}
 
 	/*! This constructor can be used to set all values in this structure during initialization
 	 * \param u The value to set U to.
@@ -219,6 +219,11 @@ struct NIFLIB_API Vector3 {
 	 */
 	bool operator==( const Vector3 & rh ) const;
 
+	/* Tests the inequality of two Vector3 structures.  Vectors are considered equal if all
+	 * three components are equal.
+	 */
+	bool operator!=( const Vector3 & rh ) const;
+
 	/* Computes the dot product of two vectors; the angle between two vectors.
 	 * \param rh The vector to perform the dot product with
 	 * \return The angle in radians between this vector and the one given
@@ -758,7 +763,7 @@ struct Matrix44 {
 	NIFLIB_API float Adjoint( int skip_r, int skip_c ) const;
 
 	NIFLIB_API Matrix33 GetRotation() const;
-	NIFLIB_API Vector3 GetScale() const;
+	NIFLIB_API float GetScale() const;
 	NIFLIB_API Vector3 GetTranslation() const;
 
 	//undocumented, may be removed
diff --git a/obj/NiAVObject.cpp b/obj/NiAVObject.cpp
index ba3a931f..e621bf72 100644
--- a/obj/NiAVObject.cpp
+++ b/obj/NiAVObject.cpp
@@ -177,3 +177,19 @@ void NiAVObject::SetHidden(bool value)
 {
    flags = NIFLIB_MASK_FLAG(flags, value, 0, 0x01);
 }
+
+void NiAVObject::SetLocalTransform( const Matrix44 & n ) {
+	n.Decompose( translation, rotation, scale );
+}
+
+bool NiAVObject::GetVisibility() const {
+	return !( flags & 1 );
+}
+
+void NiAVObject::SetVisibility( bool n ) {
+	//Only do anything if the value is different from what it already is
+	if ( GetVisibility() != n ) {
+		//Flip the bit
+		flags ^= 1;
+	}
+}
diff --git a/obj/NiAVObject.h b/obj/NiAVObject.h
index 9078e0d6..582b362f 100644
--- a/obj/NiAVObject.h
+++ b/obj/NiAVObject.h
@@ -49,6 +49,13 @@ public:
 	 */
 	Matrix44 GetLocalTransform() const;
 
+	/*! 
+	 * This is a conveniance function that allows you to set the rotation, scale, and translation of an AV object with a 4x4 matrix transform.
+	 * \n A 4x4 transformation matrix to set the AVObject's transform attributes with.
+	 * \sa INode::GetLocalTransform
+	 */
+	void SetLocalTransform( const Matrix44 & n );
+
 	/*! 
 	 * This function will return a transform matrix that represents the location of this node in world space.  In other words, it concatenates all parent transforms up to the root of the scene to give the ultimate combined transform from the origin for this node.
 	 * \return The 4x4 world transform matrix of this node.
@@ -82,6 +89,9 @@ public:
 	Vector3 GetVelocity() const;
 	void SetVelocity( const Vector3 & n );
 
+	bool GetVisibility() const;
+	void SetVisibility( bool n );
+
 	void SetCollisionObject(Ref<NiCollisionObject> &);
 
    typedef enum CollisionType
diff --git a/obj/NiTexturingProperty.cpp b/obj/NiTexturingProperty.cpp
index 584dee30..1c5c03f7 100644
--- a/obj/NiTexturingProperty.cpp
+++ b/obj/NiTexturingProperty.cpp
@@ -159,27 +159,35 @@ void NiTexturingProperty::SetTexture( int n, TexDesc & new_val ) {
 	//Copy the values to the right texture
 	switch (n) {
 		case BASE_MAP:
+			hasBaseTexture = true;
 			baseTexture = new_val;
 			break;
 		case DARK_MAP:
+			hasDarkTexture = true;
 			darkTexture = new_val;
 			break;
 		case DETAIL_MAP:
+			hasDetailTexture = true;
 			detailTexture = new_val;
 			break;
 		case GLOSS_MAP:
+			hasGlossTexture = true;
 			glossTexture = new_val;
 			break;
 		case GLOW_MAP:
+			hasGlowTexture = true;
 			glowTexture = new_val;
 			break;
 		case BUMP_MAP:
+			hasBumpMapTexture = true;
 			bumpMapTexture = new_val;
 			break;
 		case DECAL_0_MAP:
+			hasDecal0Texture = true;
 			decal0Texture = new_val;
 			break;
 		case DECAL_1_MAP:
+			hasDecal1Texture = true;
 			decal1Texture = new_val;
 			break;
 	};
-- 
GitLab