Exemple #1
0
void ZViewpoint::zviewpointHandleMsgFly( ZMsg *msg ) {
	static float viewpointMouseLast[2];
	static int dragging = 0;

	float newzviewpointScale = 0.f;
	int scaleChange = 0;

	if( (zmsgIs(type,ZUIMouseClickOn) || zmsgIs(type,MouseClick)) && zmsgIs(dir,D) && (zmsgIs(which,R) || zmsgIs(which,M)) && zmsgI(shift) && zmsgI(ctrl) && zmsgI(alt) ) {
		// RESET
		memset( &zviewpointTrans, 0, sizeof(zviewpointTrans) );
		zviewpointRotQuat.fromAxisAngle( FVec3::XAxis, 0.f );
		zviewpointScale = 1.f;
	}

	char button = msg->getS( "which", "X" ) [0]; 

//	if( (zmsgIs(type,ZUIMouseClickOn) || zmsgIs(type,MouseClick)) && zmsgIs(dir,D) && zmsgIs(which,M) ) {
	if( (zmsgIs(type,ZUIMouseClickOn) || zmsgIs(type,MouseClick)) && zmsgIs(dir,D) && button==zviewpointRotateButton ) {
		dragging = zMouseMsgRequestExclusiveDrag( "type=Viewpoint_MouseDrag" );
	}

	if( zmsgIs(type,Viewpoint_MouseDrag) ) {
		if( zmsgI(releaseDrag) ) {
			zMouseMsgCancelExclusiveDrag();
		}
		else {
			int _deltaX = zMouseMsgX - zMouseMsgLastX;
			int _deltaY = zMouseMsgY - zMouseMsgLastY;

			FQuat deltaX( FVec3::XAxis, -0.01f * _deltaX );
			FQuat deltaY( FVec3::YAxis, +0.01f * _deltaY );
			FQuat deltaZ;

			deltaX.mul( zviewpointRotQuat );
			deltaY.mul( deltaX );
			deltaZ.mul( deltaY );
			zviewpointRotQuat = deltaZ;
		}
	}
}
Exemple #2
0
void ZViewpoint::zviewpointRotateTrackball( float dx, float dy, float side ) {
	// ROTATE: this was originally in the message handler for trackball mode
	// reponse to mouse drag.  I factored out to here so that I can call this
	// code in response to arrow keys to step-rotate the object about a given 
	// axis. (tfb)

	// COMPUTE the world axises about which we are spinning (i.e. the screen axis)
	FMat4 ref( zviewpointReferenceModel.m );
	FMat4 rot = zviewpointRotQuat.mat();
	rot.transpose();
	ref.cat( rot );
	ref.setTrans( FVec3::Origin );
	ref.orthoNormalize();
	ref.inverse();
		// ref is now the transform that will take a point in eye-coordinates and
		// transform it to its original pre-viewing-transform world coordinates. tfb

	FVec3 xEye = ref.mul( FVec3::XAxis );
	FVec3 yEye = ref.mul( FVec3::YAxis );
	FVec3 zEye = ref.mul( FVec3::ZAxis );

	FQuat deltaX( xEye, dy );
	if( !zviewpointPermitRotX ) deltaX.identity();
	FQuat deltaY( yEye,  dx );
	if( !zviewpointPermitRotY ) deltaY.identity();
	FQuat deltaZ;
	if( side != 0 ) {
		deltaX.identity();
		deltaY.identity();
		deltaZ.fromAxisAngle( zEye, side * -dy );
	}
	if( !zviewpointPermitRotZ ) deltaZ.identity();

	// QUATERNION multiply the delta by the origial to get the new
	deltaX.mul( zviewpointRotQuat );
	deltaY.mul( deltaX );
	deltaZ.mul( deltaY );
	zviewpointRotQuat = deltaZ;
}