示例#1
0
/*
============
idQuat::ToAngularVelocity
============
*/
Vec3D idQuat::ToAngularVelocity( void ) const {
	Vec3D vec;

	vec.x = x;
	vec.y = y;
	vec.z = z;
	vec.Normalize();
	return vec * Float_ACos( w );
}
示例#2
0
vfloat CVX_Sim::GetSumForceDir(CVX_FRegion* pRegion)
{
	//right now only fixed regions... (forced regions should be zero!)
	//get force only in dircetion of pull!
	Vec3D<> Res = GetSumForce(pRegion);

	Vec3D<> Dir = pRegion->Displace;
	if (Dir.Length2() == 0) return Res.Length(); //return magnitude of no direction...
	else {
		Dir.Normalize();
		return Res.Dot(Dir);
	}

}
示例#3
0
/*
=====================
idQuat::ToRotation
=====================
*/
Rotation idQuat::ToRotation( void ) const {
	Vec3D vec;
	FLOAT angle;

	vec.x = x;
	vec.y = y;
	vec.z = z;
	angle = Float_ACos( w );
	if ( angle == 0.0f ) {
		vec.Set( 0.0f, 0.0f, 1.0f );
	} else {
		//vec *= (1.0f / sin( angle ));
		vec.Normalize();
		vec.FixDegenerateNormal();
		angle *= 2.0f * mxRAD2DEG;
	}
	return Rotation( Vec3D::vec3_zero, vec, angle );
}
示例#4
0
void EdGizmo::OnMouseMove( const EdSceneViewport& viewport, const SMouseMoveEvent& args )
{
	AHitProxy* pHitProxy = viewport.objAtCursor;

	const bool bHighlightObjects = true;
	if( bHighlightObjects )
	{
		if( pHitProxy != nil )
		{
			APlaceable* pPlaceable = pHitProxy->IsPlaceable();
			m_hightlighted = pPlaceable;

			HGizmoAxis* pHGizmoAxis = SafeCast<HGizmoAxis>( pHitProxy );
			if( pHGizmoAxis != nil )
			{
				m_highlightedAxes = pHGizmoAxis->axis;
			}
			else
			{
				m_highlightedAxes = EGizmoAxis::GizmoAxis_None;
			}
		}
		else
		{
			m_hightlighted = nil;
		}
	}

	if( viewport.IsDraggingMouse() && m_selected != nil )
	{
		// gizmo pick point, in screen space
		Vec2D	pickPosNDC;
		PointToNDC( viewport, viewport.dragStartPosition.x(), viewport.dragStartPosition.y(), pickPosNDC );
		//DBGOUT("pickPosNDC: %f, %f\n",pickPosNDC.x,pickPosNDC.y);

		Vec2D	currPosNDC;
		PointToNDC( viewport, args.mouseX, args.mouseY, currPosNDC );
		//DBGOUT("currPosNDC: %f, %f\n",currPosNDC.x,currPosNDC.y);

		// we need to convert screen space delta to world space movement
		Vec2D	deltaNDC = currPosNDC - pickPosNDC;
		//dbgout << "delta=" << deltaNDC << dbgout.NewLine();

		switch( m_currentMode )
		{
		case EGizmoMode::Gizmo_Translate :
			if( m_currentAxis == GizmoAxis_None )
			{
				return;
			}
			if( m_currentAxis == GizmoAxis_All )
			{
L_TranslateAll:
				const rxView& eye = viewport.GetView();

				Ray3D	pickRay = GetEyeRay( viewport, currPosNDC );

				FLOAT	prevDist = (m_oldState.translation - eye.origin).LengthSqr();
				if( prevDist < VECTOR_EPSILON )
				{
					return;
				}
				prevDist = mxSqrt(prevDist);


				Vec3D	newEntityPos = eye.origin + pickRay.direction * prevDist;

				m_selected->SetOrigin( newEntityPos );
			}
			else
			{
				Vec3D	gizmoPickPos = F_Get_Translation_Gizmo_Pick_Point_In_World_Space( viewport, pickPosNDC, m_selected, m_currentAxis );
				//Vec3D	centerOfGizmo = m_selected->GetOrigin();
				Vec3D	pointOnGizmo = F_Get_Translation_Gizmo_Pick_Point_In_World_Space( viewport, currPosNDC, m_selected, m_currentAxis );
				Vec3D	translationDelta = pointOnGizmo - gizmoPickPos;

				const FLOAT MAX_TRANSLATION_DIST = 100.0f;
				translationDelta.Clamp(Vec3D(-MAX_TRANSLATION_DIST),Vec3D(MAX_TRANSLATION_DIST));

				Vec3D	newEntityPos = m_oldState.translation + translationDelta;

				m_selected->SetOrigin( newEntityPos );
			}
			break;

		case EGizmoMode::Gizmo_Scale :
			if( m_currentAxis == GizmoAxis_All )
			{
				goto L_TranslateAll;
			}
			else
			{
				//dbgout << "Scaling\n";
				FLOAT mag = deltaNDC.LengthFast();

				FLOAT	newEntityScale = m_oldState.scaleFactor + mag * signf(deltaNDC.x);
				newEntityScale = maxf(newEntityScale,0.01f);

				m_selected->SetScale( newEntityScale );
			}
			break;

		case EGizmoMode::Gizmo_Rotate :
			//if( m_currentAxis == GizmoAxis_None )
			//{
			//	return false;
			//}
			if( m_currentAxis == GizmoAxis_All )
			{
				goto L_TranslateAll;
			}
			else
			{
				//dbgout << "Rotating\n";
				mxUNDONE;
				static FLOAT	ROT_ARC_RADIUS = 1.0f;
				HOT_FLOAT(ROT_ARC_RADIUS);

				// starting point of rotation arc
				Vec3D	vDownPt = ConvertScreenPointToVector(
					viewport,
					viewport.dragStartPosition.x(), viewport.dragStartPosition.y(),
					ROT_ARC_RADIUS
					);

				// current point of rotation arc
				Vec3D	vCurrPt = ConvertScreenPointToVector(
					viewport,
					args.mouseX, args.mouseY,
					ROT_ARC_RADIUS
					);

#if 0
				Quat	qRot = QuatFromBallPoints( vDownPt, vCurrPt );
				qRot.Normalize();
#else
				Vec3D	axis = Cross( vDownPt, vCurrPt );
				axis.Normalize();

				F4		angle = AngleBetween( vDownPt, vCurrPt );
				Quat	qRot( axis, angle );
				qRot.Normalize();
#endif

				Quat	q = qRot * m_oldState.orientation;
				q.Normalize();

				m_selected->SetOrientation(q);
			}
			break;

			mxNO_SWITCH_DEFAULT;
		}
	}
}