Need Opinion on this please
BlitzMax Forums/BlitzMax Programming/Need Opinion on this please
| ||
I've been looking at way to make my vector lib more versatile. Take a look at this vector method and give me your opinion on any speed issues it might create. It basically lets you write vector addition in 2 different ways. If no v2 vector is specified then it ignores it etc.
' Purpose: Add Vectors
' Returns: Self
' Example 1: v1=v1+v2 would be written v1.Add( v2 )
' Example 2: v1=v2+v3 would be written v1.Add( v2, v3)
Method Add( v1:TVector3, v2:TVector3 )
If v2
self.x = v1.x + v2.x
self.y = v1.y + v2.y
self.z = v1.z + v2.z
else
self.x :+ v1.x
self.y :+ v1.y
self.z :+ v1.z
endif
End Function
|
| ||
| Write 2 different methods for that. As vector math is speed critical, any unneeded IF shouldn't be present. |
| ||
| True. If you were calling Add a few hundred times a cycle I guess that IF would add up pretty fast. |
| ||
| Method Add( v1:TVector3, v2:TVector3 = NULL) |
| ||
| Another solution is to write your maths code in C++.. class vec3{ public: float x,y,z; void Add(vec3 *v1,vec3 *v2){x=v1->x+v2->x; y=v1->y+v2->y; z=v1->z+v2->z;} void Add(vec3 *v1){x+=v1->x; y+=v1->y; z+=v1->z;} }; ignoring any typos, it shouldnt be too hard to get something like this work.. might even be jst as well locating an existing maths lib/physics lib..etc |