示例#1
0
const CReal CReal::Inv() const
{
	if (isRational)
	{
		if (nRational.nNumerator>=0)
			return CReal(nRational.nDenominator,nRational.nNumerator);
		else
			return CReal(-int(nRational.nDenominator),-nRational.nNumerator);
	}
	else
		return CReal(1/nIrrational);
}
示例#2
0
gc<const CObject *> CReal::parseString(String::AbstractIterator &stri)
{
	double value = stringToDouble(stri);
	if (isnan(value))
		gcthrownew(EInvalidObjectValue(Message(InvalidRealValue)));
	return gcnew(CReal(value));
}
示例#3
0
CReal SnapReal( CReal Input, CReal SnapVal )
{
	int ival = int(Input/SnapVal);

	CReal ret( CReal(ival)*SnapVal );
		
	orkprintf( "SnapReal %f [%d] -> %f \n", Input, ival, ret );

	return ret;
}
示例#4
0
CManipRZ::CManipRZ(CManipManager& mgr)
	: CManipRot(mgr,CVector4( 0.0f, 0.0f, 1.0f))
{
	mmRotModel.SetRotateX( CFloat::Pi() / CReal(2.0f) );
	mColor = CColor4::Blue();
}
示例#5
0
CManipRX::CManipRX( CManipManager& mgr )
	: CManipRot(mgr,CVector4( 1.0f, 0.0f, 0.0f) )
{
	mmRotModel.SetRotateZ( CFloat::Pi() / CReal(2.0f) );
	mColor = CColor4::Red();
}
示例#6
0
bool CManipRot::UIEventHandler( const ui::Event& EV )
{	
	int ex = EV.miX;
	int ey = EV.miY;
	
	CVector2 posubp = EV.GetUnitCoordBP();

	CCamera *pcam = mManager.GetActiveCamera();
	
	bool brval = false;
			
	bool isshift = false; //CSystem::IsKeyDepressed(VK_SHIFT );
	bool isctrl = false; //CSystem::IsKeyDepressed(VK_CONTROL );
	
	switch( EV.miEventCode )
	{
		case ui::UIEV_PUSH:
		{	
			mManager.mManipHandler.Init(posubp, pcam->mCameraData.GetIVPMatrix(), pcam->QuatC );
			mBaseTransform = mManager.mCurTransform;

			SelectBestPlane(posubp);

			brval = true;
		}
		break;

		case ui::UIEV_RELEASE:
		{
			mManager.DisableManip();

			brval = true;
		}
		break;

		case ui::UIEV_DRAG:
		{
			IntersectWithPlanes( posubp );

			if ( CheckIntersect() )
			{	
				///////////////////////////////////////////
				// calc normalvectors from base:origin to point on activeintersection plane (in world space)
				const CVector3 & Origin = mBaseTransform.GetTransform().GetPosition();
				CVector3 D1 = (Origin-mActiveIntersection->mIntersectionPoint).Normal();
				CVector3 D0 = (Origin-mActiveIntersection->mBaseIntersectionPoint).Normal();
				///////////////////////////////////////////
				// calc matrix to put worldspace vector into plane local space
				CMatrix4 MatWldToObj = mBaseTransform.GetTransform().GetMatrix(); //GetRotation();
				MatWldToObj.Inverse();
				CVector4 bAxisAngle = mLocalRotationAxis; 
				CQuaternion brq;
				brq.FromAxisAngle(bAxisAngle);
				CMatrix4 MatObjToPln = brq.ToMatrix();
				MatObjToPln.Inverse();
				CMatrix4 MatWldToPln = MatObjToPln*MatWldToObj;
				//CMatrix4 MatInvRot = InvQuat.ToMatrix();
				///////////////////////////////////////////
				// calc plane local rotation
				CVector4 AxisAngle = mLocalRotationAxis; 
				CVector4 D0I = CVector4(D0,CReal(0.0f)).Transform(MatWldToPln);
				CVector4 D1I = CVector4(D1,CReal(0.0f)).Transform(MatWldToPln);
				//orkprintf( "D0 <%f %f %f>\n", float(D0.GetX()), float(D0.GetY()), float(D0.GetZ()) );
				//orkprintf( "D1 <%f %f %f>\n", float(D1.GetX()), float(D1.GetY()), float(D1.GetZ()) );
				//orkprintf( "D0I <%f %f %f>\n", float(D0I.GetX()), float(D0I.GetY()), float(D0I.GetZ()) );
				//orkprintf( "D1I <%f %f %f>\n", float(D1I.GetX()), float(D1I.GetY()), float(D1I.GetZ()) );
				AxisAngle.SetW( CalcAngle(D0I,D1I) );
				CQuaternion RotQ;
				RotQ.FromAxisAngle( AxisAngle );
				///////////////////
				// Rot Snap
				if( isshift )
				{	CReal SnapAngleVal( PI2/16.0f );
					CVector4 NewAxisAngle = RotQ.ToAxisAngle();
					CReal Angle = NewAxisAngle.GetW();
					Angle = SnapReal( Angle, SnapAngleVal );
					NewAxisAngle.SetW( Angle );
					RotQ.FromAxisAngle( NewAxisAngle );
				}
				///////////////////
				// accum rotation
				CQuaternion oq = mBaseTransform.GetTransform().GetRotation();
				CQuaternion NewQ = RotQ.Multiply(oq);
				///////////////////
				// Rot Reset To Identity
				if( isctrl && isshift )
				{
					NewQ.FromAxisAngle( CVector4( CReal(0.0f), CReal(1.0f), CReal(0.0f), CReal(0.0f) ) );
				}
				///////////////////
				TransformNode mset = mManager.mCurTransform;
				mset.GetTransform().SetRotation( NewQ );
				mManager.ApplyTransform( mset );
				///////////////////
			}

			brval = true;
		}
		break;

		default:
			break;
	}

	return brval;
}
示例#7
0
gc<const CObject *> CReal::deserializeData(IO::InputStream *stream)
{
	double value;
	stream->read(&value, sizeof(value));
	return gcnew(CReal(value));
}