All pastes #759759 Raw Edit

Something

public text v1 · immutable
·published 2007-11-03 14:20 UTC
rendered paste body
Is this correct?

to rotate any node around another nodes local axis:

we need to work out how much to rotate the nodes along the GLOBAL axis.
>
Orientate temp node at same orientation as the parent node.
Get rotation matrix. Store rotation matrix.

Rotate parent node.

Get new rotation matrix. subtract stored matrix from this matrix.

we now have a matrix containing the amount to rotate in WORLD SPACE.

ok, now we itterate the rest of the nodes.



for each one, get their rotation matrix, multiply it with the stored one to rotate it around the parents axis.

done.


Code follows. it does not work. I can't see any flaws myself:

---------------------

	Method Rotate(yaw:Float, pitch:Float, roll:Float, Space:Int) 
		Local node:TSceneNode
		node = Self.lastentity.getParentSceneNode() 
		Local orient:TQuaternion
		Local thisnoderotmatrix:TMatrix3 = TMatrix3.createEmpty() 
		Local startrot:TMatrix3 = TMatrix3.createempty()    	'Starting orientation
		Local endrot:TMatrix3 = TMatrix3.createempty()    		'Orientation after rotation
		Local rotateby:TMatrix3 = TMatrix3.createEmpty()  		'Difference between the above two- IE, the matrix to use to rotate.
		
		Local neworientation:TQuaternion = TQuaternion.CreateEmpty() 

		If tempnode = Null Then tempnode = MainSceneManager.createSceneNode() 
		tempnode.setOrientation(node.getOrientation()) 
		tempnode.getOrientation().ToRotationMatrix(startrot) 
		tempnode.rotate(yaw, pitch, roll, 1, space) 
		tempnode.getOrientation().ToRotationMatrix(endrot) 
		rotateby = endrot.sub(startrot) 
		
		'First, deal with the "parent" node.
		
		node.rotate(yaw, pitch, roll, 1, space) 
		
		'OK, multiple rotations in 3d using quaternions result in floating point errors, which eventually
		'makes the quat/matrix invalid.
		'Normalising the quaternion ensures proper values are retained
		'and this prevents weird scaling issues.
				
		orient = node.getOrientation()  		' get the orientation in a quat. 
		orient.normalise()       				'normalise this quat.
		node.setOrientation(orient)  	   		'set the orientation using this normalised vector.
		
		For Local Extd:TExtendedData = EachIn objectlist 			'Itterate each extended data object in the selection
			If extd.entity.pointer <> Self.lastentity.pointer Then	'and if it is not the "parent" node, 
				If Extd.disabletranslation = False Then 			'and if this node has not had translation disabled then it can be manipulated here.
				
				Local thisnode:TSceneNode = extd.Entity.getParentSceneNode() 	'get this entities scene node.
				thisnode.getOrientation().ToRotationMatrix(thisnoderotmatrix)  	'get the nodes rotation matrix and put it in thisnoderotmatrix.
				Local newrot:TMatrix3 = thisnoderotmatrix.mul(rotateby)  		'multiply thisnoderotmatrix with the matrix we want to ratate with.
				neworientation.FromRotationMatrix(newrot)  						'convert this matrix to a quat.
				thisnode.setOrientation(neworientation)  						'Set the orientation.
				
				'Normalise the orientation quat.
				orient = thisnode.getOrientation() 	' get the orientation in a quat. 
				orient.normalise() 					'normalise this quat.
				thisnode.setOrientation(orient)  	'set the orientation using this normalised vector.
				EndIf
			EndIf
		Next
	End Method