small vector3 patch

Started by
3 comments, last by Wavesonics 14 years, 10 months ago
i was using the vector3 test code and noticed a typo in the code that rendered my distance function useless. see yourself:

Index: add_on/scriptmath3d/scriptmath3d.cpp
===================================================================
--- add_on/scriptmath3d/scriptmath3d.cpp	(revision 311)
+++ add_on/scriptmath3d/scriptmath3d.cpp	(working copy)
@@ -82,17 +82,22 @@
 	return sqrtf(x*x + y*y + z*z);
 }
 
+float Vector3::distance(Vector3 &v) const
+{
+	return (*this-v).length();
+}
+
 Vector3 operator+(const Vector3 &a, const Vector3 &b)
 {
 	// Return a new object as a script handle
-	Vector3 res(a.x + b.x, a.y + b.y, a.z + b.y);
+	Vector3 res(a.x + b.x, a.y + b.y, a.z + b.z);
 	return res;
 }
 
 Vector3 operator-(const Vector3 &a, const Vector3 &b)
 {
 	// Return a new object as a script handle
-	Vector3 res(a.x - b.x, a.y - b.y, a.z - b.y);
+	Vector3 res(a.x - b.x, a.y - b.y, a.z - b.z);
 	return res;
 }
 
@@ -292,6 +297,7 @@
 
 	// Register the object methods
 	r = engine->RegisterObjectMethod("vector3", "float length() const", asMETHOD(Vector3,length), asCALL_THISCALL); assert( r >= 0 );
+	r = engine->RegisterObjectMethod("vector3", "float distance(vector3 &in) const", asMETHOD(Vector3,distance), asCALL_THISCALL); assert( r >= 0 );
 }
 
 void RegisterScriptMath3D_Generic(asIScriptEngine *engine)
Index: add_on/scriptmath3d/scriptmath3d.h
===================================================================
--- add_on/scriptmath3d/scriptmath3d.h	(revision 311)
+++ add_on/scriptmath3d/scriptmath3d.h	(working copy)
@@ -22,6 +22,7 @@
 	Vector3 &operator/=(float scalar);
 
 	float length() const;
+	float distance(Vector3 &v) const;
 
 	friend bool operator==(const Vector3 &a, const Vector3 &b);
 	friend bool operator!=(const Vector3 &a, const Vector3 &b);
[Edited by - tdev on June 22, 2009 3:00:43 PM]
Advertisement
Thanks. I've fixed the bug you reported.

I didn't actually apply the patch, as vector3 add-on is more of an example rather than a useable add-on library. I might actually remove it as an add-on in a future version.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Why not just continue building it out like this to the point where it is usable? IMO having a strong library of addons is critical for AS.

I was even thinking about creating a full 3D math addon with 3d vector upgrades, a registered Quaternion class, and so on. What do you think?
==============================
A Developers Blog | Dark Rock Studios - My Site
I agree that having a strong library of add-ons is critical to the success of AngelScript. But I really don't think it is appropriate to bundle AngelScript with a math library. I do not want people to replace whatever math library they use but rather register the one they already use, for example D3DX, or PhysX, etc.

For myself, I am actually writing my own math library, that I am registering with AngelScript. You can find the math library in my toolbox. Once the math library is more mature, I'll probably put up the AngelScript registration of it too.

You can find code for registering PhysX' math library on the wiki.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Quote:For myself, I am actually writing my own math library


Of course you are :P

That sounds awesome though, good show!
==============================
A Developers Blog | Dark Rock Studios - My Site

This topic is closed to new replies.

Advertisement