Double/Float precision & speed

BlitzMax Forums/BlitzMax Programming/Double/Float precision & speed

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

For curositys sake, here's the Move method from my entity system, and the 2 matrix/vector functions it calls. Maybe it's inevitable that there will be 'some' precision loss as there's a fair amount of calculations going on.

	Method Move(px:Float,py:Float,pz:Float,world:Byte=False)
		If world=False Or Self.gparent=Null ' No parent means local=world position
			
			' Set this entitys Matrix as the current GL Matrix
			' Do the translation, then update the entitys Matrix
			Self.setGLMatrix()
			glTranslatef(px,py,pz)
			Self.getGLMatrix()
		
		Else
			Local v:Vec3=Vec3.Create(px,py,pz)
			Local tmat:Mat4=Mat4.Create()
			tmat.Copy(mat) ' Copy this entitys GL Matrix
			
			'If the entity has a parent, multiply it's Matrix
			'all the way up the parent chain
			Local pa:gEntity=Self.gparent
			While pa
				tmat.Multiply(pa.mat)
				pa=pa.gparent
			Wend
			
			'transform the movement vector into World space
			v.iMatMulV(tmat.m)

			'As per local, apply the movement/translation
			Self.setGLMatrix()
			glTranslatef(v.x,v.y,v.z)
			Self.getGLMatrix()
		End If
	End Method
	
	
	' From my Mat4 Type.........
	Method Multiply(mat:Mat4)
		Local Tempmat:Float[16]
		Tempmat[0] = m[0] * mat.m[0] + m[1] * mat.m[4] + m[2] * mat.m[8] + m[3] * mat.m[12]
		Tempmat[1] = m[0] * mat.m[1] + m[1] * mat.m[5] + m[2] * mat.m[9] + m[3] * mat.m[13]
		Tempmat[2] = m[0] * mat.m[2] + m[1] * mat.m[6] + m[2] * mat.m[10] + m[3] * mat.m[14]
		Tempmat[3] = m[0] * mat.m[3] + m[1] * mat.m[7] + m[2] * mat.m[11] + m[3] * mat.m[15]
	
		Tempmat[4] = m[4] * mat.m[0] + m[5] * mat.m[4] + m[6] * mat.m[8] + m[7] * mat.m[12]
		Tempmat[5] = m[4] * mat.m[1] + m[5] * mat.m[5] + m[6] * mat.m[9] + m[7] * mat.m[13]
		Tempmat[6] = m[4] * mat.m[2] + m[5] * mat.m[6] + m[6] * mat.m[10] + m[7] * mat.m[14]
		Tempmat[7] = m[4] * mat.m[3] + m[5] * mat.m[7] + m[6] * mat.m[11] + m[7] * mat.m[15]
	
		Tempmat[8] = m[8] * mat.m[0] + m[9] * mat.m[4] + m[10] * mat.m[8] + m[11] * mat.m[12]
		Tempmat[9] = m[8] * mat.m[1] + m[9] * mat.m[5] + m[10] * mat.m[9] + m[11] * mat.m[13]
		Tempmat[10] = m[8] * mat.m[2] + m[9] * mat.m[6] + m[10] * mat.m[10] + m[11] * mat.m[14]
		Tempmat[11] = m[8] * mat.m[3] + m[9] * mat.m[7] + m[10] * mat.m[11] + m[11] * mat.m[15]
	
		Tempmat[12] = m[12] * mat.m[0] + m[13] * mat.m[4] + m[14] * mat.m[8] + m[15] * mat.m[12]
		Tempmat[13] = m[12] * mat.m[1] + m[13] * mat.m[5] + m[14] * mat.m[9] + m[15] * mat.m[13]
		Tempmat[14] = m[12] * mat.m[2] + m[13] * mat.m[6] + m[14] * mat.m[10] + m[15] * mat.m[14]
		Tempmat[15] = m[12] * mat.m[3] + m[13] * mat.m[7] + m[14] * mat.m[11] + m[15] * mat.m[15]
		For Local i:Byte=0 To 15
			m[i]=Tempmat[i]
		Next
	End Method
	
	' From my Vec3 Type
	Method iMatMulV(m:Float[])
		Local tmp:Float[3]
		tmp[0] = x*m[0] + y*m[1] + z*m[2]
		tmp[1] = x*m[4] + y*m[5] + z*m[6]
		tmp[2] = x*m[8] + y*m[9] + z*m[10]

		x = tmp[0]
		y = tmp[1]
		z = tmp[2]
	End Method