Update leenkx/Sources/iron/math/Quat.hx
This commit is contained in:
		| @ -66,12 +66,32 @@ class Quat { | ||||
| 	} | ||||
|  | ||||
| 	public inline function fromAxisAngle(axis: Vec4, angle: FastFloat): Quat { | ||||
| 		var s: FastFloat = Math.sin(angle * 0.5); | ||||
| 		x = axis.x * s; | ||||
| 		y = axis.y * s; | ||||
| 		z = axis.z * s; | ||||
| 		w = Math.cos(angle * 0.5); | ||||
| 		return normalize(); | ||||
| 		//var s: FastFloat = Math.sin(angle * 0.5); | ||||
| 		//x = axis.x * s; | ||||
| 		//y = axis.y * s; | ||||
| 		//z = axis.z * s; | ||||
| 		//w = Math.cos(angle * 0.5); | ||||
| 		//return normalize(); | ||||
| 		// Normalize the axis vector first | ||||
| 		var axisLen = Math.sqrt(axis.x * axis.x + axis.y * axis.y + axis.z * axis.z); | ||||
| 		if (axisLen > 0.00001) { | ||||
| 			var aL = 1.0 / axisLen; | ||||
| 			var nX = axis.x * aL; | ||||
| 			var nY = axis.y * aL; | ||||
| 			var nZ = axis.z * aL; | ||||
| 			var halfAngle = angle * 0.5; | ||||
| 			var s: FastFloat = Math.sin(halfAngle); | ||||
| 			x = nX * s; | ||||
| 			y = nY * s; | ||||
| 			z = nZ * s; | ||||
| 			w = Math.cos(halfAngle); | ||||
| 		} else { | ||||
| 			x = 0.0; | ||||
| 			y = 0.0; | ||||
| 			z = 0.0; | ||||
| 			w = 1.0; | ||||
| 		} | ||||
| 		return this; | ||||
| 	} | ||||
|  | ||||
| 	public inline function toAxisAngle(axis: Vec4): FastFloat { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user