Beispiel #1
0
BOOL CBoneDef::SetInitTM(IPhysiqueExport* pExport, const Matrix3& matMesh)
{
	BOOL bErr = false;
	R_ASSERT(pBone);
	R_ASSERT(Helper::IsBone(pBone,U.m_SkinAllowDummy));
	Matrix3 tmp;
	//Log("SetInitTM:",pBone->GetName());
	if(Helper::IsBipedBone(pBone))	{
		Helper::SetBipedUniform(pBone, TRUE, TRUE);
		bErr = CGINTM(pBone,pExport->GetInitNodeTM(pBone, tmp));
		if (bErr) tmp.IdentityMatrix();
		Helper::SetBipedUniform(pBone, FALSE, FALSE);
	} else {
		bErr = CGINTM(pBone,pExport->GetInitNodeTM(pBone, tmp));
		if (bErr) tmp.IdentityMatrix();
	}

	if (1){//!bErr){
		Helper::ConvertMatrix(tmp,matInit);
		matOffset.invert(matInit);
		//S matMesh
//		pBone->matOffset = matMesh * Inverse(pBone->matInit);
	}

	return 1;//!bErr;
}
int SphereObjCreateCallBack::proc(ViewExp *vpt,int msg, int point, int flags, IPoint2 m, Matrix3& mat ) 
{
   float r;
   Point3 p1,center;

   if (msg == MOUSE_FREEMOVE)
   {
      vpt->SnapPreview(m,m,NULL, SNAP_IN_3D);
   }

   if (msg==MOUSE_POINT||msg==MOUSE_MOVE) 
   {
      switch(point) 
      {
      case 0:  // only happens with MOUSE_POINT msg
         // Find the node and plug in the wire color
         {
            ULONG handle;
            ob->NotifyDependents(FOREVER, (PartID)&handle, REFMSG_GET_NODE_HANDLE);
            INode *node = GetCOREInterface()->GetINodeByHandle(handle);
            if (node) node->SetWireColor(RGB(255, 0, 0));
         }
         ob->pblock2->SetValue(PB_RADIUS,0,0.0f);
         ob->suspendSnap = TRUE;				
         sp0 = m;
         p0 = vpt->SnapPoint(m,m,NULL,SNAP_IN_3D);
         mat.SetTrans(p0);
         break;
      case 1:
         mat.IdentityMatrix();
         //mat.PreRotateZ(HALFPI);
         p1 = vpt->SnapPoint(m,m,NULL,SNAP_IN_3D);
         r = Length(p1-p0) / 7.0f;
         mat.SetTrans(p0);

         ob->pblock2->SetValue(PB_RADIUS,0,r);
         ob->pmapParam->Invalidate();

         if (flags&MOUSE_CTRL) 
         {
            float ang = (float)atan2(p1.y-p0.y,p1.x-p0.x);					
            mat.PreRotateZ(ob->ip->SnapAngle(ang));
         }

         if (msg==MOUSE_POINT) 
         {
            ob->suspendSnap = FALSE;
            return (Length(m-sp0)<3 || Length(p1-p0)<0.1f)?CREATE_ABORT:CREATE_STOP;
         }
         break;					   
      }
   }
   else
      if (msg == MOUSE_ABORT) 
      {		
         return CREATE_ABORT;
      }

      return TRUE;
}
// CAL-05/24/02: TODO: this should really go to core\decomp.cpp, and it should be optimized.
//		For now, it's defined locally in individual files in the ctrl project.
static void comp_affine( const AffineParts &ap, Matrix3 &mat )
{
	Matrix3 tm;
	
	mat.IdentityMatrix();
	mat.SetTrans( ap.t );

	if ( ap.f != 1.0f ) {				// has f component
		tm.SetScale( Point3( ap.f, ap.f, ap.f ) );
		mat = tm * mat;
	}

	if ( !ap.q.IsIdentity() ) {			// has q rotation component
		ap.q.MakeMatrix( tm );
		mat = tm * mat;
	}
	
	if ( ap.k.x != 1.0f || ap.k.y != 1.0f || ap.k.z != 1.0f ) {		// has k scale component
		tm.SetScale( ap.k );
		if ( !ap.u.IsIdentity() ) {			// has u rotation component
			Matrix3 utm;
			ap.u.MakeMatrix( utm );
			mat = Inverse( utm ) * tm * utm * mat;
		} else {
			mat = tm * mat;
		}
	}
}
Beispiel #4
0
StretchDeformer::StretchDeformer(TimeValue t, ModContext &mc,
                                 float stretch, float amplify, int naxis, 
                                 float from, float to, int doRegion,
                                 Matrix3& modmat, Matrix3& modinv) 
{
    Matrix3 mat;
    Interval valid;     
//    if (from==to) doRegion = FALSE;
    this->doRegion = doRegion;
    this->from = from;
    this->to   = to;
    time   = t; 

    tm = modmat;
    invtm = modinv;
    mat.IdentityMatrix();
        
    switch ( naxis ) {
    case 0: mat.RotateY( -HALFPI );      break; //X
    case 1: mat.RotateX( HALFPI );  break; //Y
    case 2: break;  //Z
    }
    SetAxis( mat );     
    assert (mc.box);
    bbox = *mc.box;
    CalcBulge(naxis, stretch, amplify);
} 
Beispiel #5
0
/*
  Need store the pose after simulation
*/
void MxActor::ActionAfterSimulation()
{
	// update pose to max node
	if(getInteractivity() != RB_DYNAMIC)
		return;

	// update rigid body's last pose
	//ccMaxNode* pn = ccMaxWorld::FindNode(m_node);
	assert(maxNodeActor);
	Matrix3 globalPose;
	globalPose.IdentityMatrix();

	if (m_bulletBody)
	{
		NxActorDesc&  actorDesc  = m_desc;

		btTransform localTrans;
		max2Bullet(actorDesc.localPose,localTrans);

		btTransform maxWorldTrans = m_bulletBody->getWorldTransform()*localTrans.inverse();

		bullet2Max(maxWorldTrans,globalPose);
		//@todo: need correction for boxes (off center etc)

		maxNodeActor->SetSimulatedPose(globalPose);
		Matrix3 poseTM = maxNodeActor->GetCurrentTM();
		SaveLastPose(poseTM);
	}
}
Beispiel #6
0
//The display function that is used to display the formation.
int FormationBhvr::Display(TimeValue t, ViewExp *vpt) 
{
    // setup

	int i,j;
   	
	if(DisplayFormation(t)==FALSE) return FALSE;

	if(GetFollowerCount(t)<=0) return FALSE;
	if(GetFollowerMatrixCount(t)<=0) return FALSE;

	INode *leaderNode;
	leaderNode = GetLeader(t);
	if(leaderNode==NULL) return FALSE;
	
	
	//check tgo see if we have created a default sphere for drawing yet...
    //if we haven't then create it..
	if (numpts == 0) 
		GetSpherePoints(Point3(0.0f,0.0f,0.0f), 1.0, SpherePts);

	
	GraphicsWindow *gw = vpt->getGW();
   
	//set the identity matrix...
	Matrix3 idMat;
	idMat.IdentityMatrix();
    gw->setTransform(idMat);

	gw->setColor(LINE_COLOR,.815f,.976f,1.0f);

	float scaleRadius = GetDisplayScale(t);
	
	//set the drawing radius values based upon what the radius size is.
	for (i=0; i<NUMAROUND * 3; i++) ScaledPts[i] = ((SpherePts[i] * scaleRadius));
	 
	//for each follower we need to increase the bounding box by it's
	//world position location...
	for(i =0;i<GetFollowerCount(t);i++)
	{
		INode *followerNode = GetFollower(t,i);
		if(followerNode) //if we have a a node...
		{
	
			Matrix3 leaderMat = GetCurrentMatrix(leaderNode,t);
			leaderMat.NoScale();
			Matrix3 followerMat = GetFollowerMatrix(t,i);
			Matrix3 worldSpace = followerMat *leaderMat;
			for (j=0; j<NUMAROUND * 3; j++) CurPts[j] = worldSpace*ScaledPts[j]; //adding the center to the point positions
			
		   	gw->polyline(NUMAROUND,&CurPts[0],NULL,NULL,TRUE,NULL);
		 	gw->polyline(NUMAROUND,&CurPts[NUMAROUND],NULL,NULL,TRUE,NULL);
    		gw->polyline(NUMAROUND,&CurPts[NUMAROUND * 2],NULL,NULL,TRUE,NULL);

		
		}
	}

	return TRUE;
}
Beispiel #7
0
Matrix3 plStaticEnvLayer::IGetViewTM( int i )
{
    Matrix3 m;
    m.IdentityMatrix();
    switch( i ) 
    {
        case kTopFace:
            m.RotateX( -M_PI );   
            break;
        case kBottomFace:
            break;
        case kLeftFace:
            m.RotateX( -.5f * M_PI ); 
            m.RotateY( -.5f * M_PI );
            break;
        case kRightFace:
            m.RotateX( -.5f * M_PI ); 
            m.RotateY( +.5f * M_PI );
            break;
        case kFrontFace:
            m.RotateX( -.5f * M_PI ); 
            m.RotateY( M_PI );
            break;
        case kBackFace:
            m.RotateX( -.5f * M_PI ); 
            break;
    }
    return m;
}
Beispiel #8
0
int WindObjCreateCallback::proc(
		ViewExp *vpt,int msg, int point, int flags, IPoint2 m, Matrix3& mat)
{
	if ( ! vpt || ! vpt->IsAlive() )
	{
		// why are we here
		DbgAssert(!_T("Invalid viewport!"));
		return FALSE;
	}

	if (msg==MOUSE_POINT||msg==MOUSE_MOVE) 
	{
#ifdef _3D_CREATE
		DWORD snapdim = SNAP_IN_3D;
#else
		DWORD snapdim = SNAP_IN_PLANE;
#endif
		switch(point) 
		{
			case 0:								
				sp0 = m;
				p0  = vpt->SnapPoint(m,m,NULL,snapdim);
				mat.SetTrans(p0);
				break;
			case 1:
				if (ob->ClassID()==Class_ID(GRAVITYOBJECT_CLASS_ID,0)) 
				{
					mat.IdentityMatrix();
					mat.RotateX(PI);
					mat.SetTrans(p0);
				}
				p1  = vpt->GetPointOnCP(m);
				ob->pblock2->SetValue(PB_DISPLENGTH,0,Length(p1-p0)/2.0f);
//				ob->pmapParam->Invalidate();
				wind_param_blk.InvalidateUI();
				if (msg==MOUSE_POINT) 
				{
					if (Length(m-sp0)<3) return CREATE_ABORT;
					else return CREATE_STOP;
				}
				break;
			}
	} 
	else 
	{
		if (msg == MOUSE_ABORT)	
		{
			return CREATE_ABORT;
		}
		else
		if (msg == MOUSE_FREEMOVE) 
		{
			vpt->SnapPreview(m,m);
		}
	}
	
	return TRUE;
}
Beispiel #9
0
BendDeformer::BendDeformer(
		TimeValue t, ModContext &mc,
		float angle, float dir, int naxis, 
		float from, float to, int doRegion,
		Matrix3& modmat, Matrix3& modinv) 
	{	
	this->doRegion = doRegion;
	this->from = from;
	this->to   = to;
	Matrix3 mat;
	Interval valid;	
	time   = t;	

	tm = modmat;
	invtm = modinv;
	mat.IdentityMatrix();
	
	switch (naxis) {
		case 0: mat.RotateY( -HALFPI );	 break; //X
		case 1: mat.RotateX( HALFPI );  break; //Y
		case 2: break;  //Z
		}
	mat.RotateZ(DegToRad(dir));	
	SetAxis(mat);	
	assert (mc.box);
	bbox = *mc.box;
	CalcR(naxis,DegToRad(angle));
	
	// Turn this off for a sec.
	this->doRegion = FALSE;
		
	float len  = to-from;
	float rat1, rat2;
	if (len==0.0f) {
		rat1 = rat2 = 1.0f;
	} else {
		rat1 = to/len;
		rat2 = from/len;
		}
	Point3 pt;
	tmAbove.IdentityMatrix();
	tmAbove.Translate(Point3(0.0f,0.0f,-to));
	tmAbove.RotateY(DegToRad(angle * rat1));
	tmAbove.Translate(Point3(0.0f,0.0f,to));
	pt = Point3(0.0f,0.0f,to);
	tmAbove.Translate((Map(0,pt*invtm)*tm)-pt);

	tmBelow.IdentityMatrix();
	tmBelow.Translate(Point3(0.0f,0.0f,-from));
	tmBelow.RotateY(DegToRad(angle * rat2));	
	tmBelow.Translate(Point3(0.0f,0.0f,from));
	pt = Point3(0.0f,0.0f,from);
	tmBelow.Translate((Map(0,pt*invtm)*tm)-pt);	
	
	this->doRegion = doRegion;

	} 
Beispiel #10
0
//This will set the formation
void FormationBhvr::SetFormation(TimeValue t)
{
	INode *node;
	Matrix3 tempMatrix;


	//Make sure that the leader is not part of the follower array..
	RemoveLeaderFromFormation(t);


	INode *leader =  GetLeader(t);

	if(leader==NULL)
		return;
	Matrix3 leaderPosition = GetCurrentMatrix(leader,t);
	leaderPosition.NoScale(); //kill any scale if we have it 
	leaderPosition.Invert();  //it's inverted...


	int numDelegates = GetFollowerCount(t);	

	//zero out the formation matrix that's used for saving it out.
	pblock->ZeroCount(follower_matrix1);
	pblock->ZeroCount(follower_matrix2);
	pblock->ZeroCount(follower_matrix3);
	pblock->ZeroCount(follower_matrix4);

	for(int i =0;i<numDelegates;i++)
	{

		node = GetFollower(t,i);
		if(node)
		{
			tempMatrix = GetCurrentMatrix(node,t);
			tempMatrix.NoScale();
			Matrix3 leaderMat =tempMatrix*leaderPosition;
			AppendFollowerMatrix(t,leaderMat);

			//killed because matrix3 wasn't working ...pblock->Append(follower_matrix,1,&leaderMat);
		 
		
		}
		else
		{
			//we still set up follower_matrix so that the counts
			//of the follower_matrix tab and the follower tab are equal.
			tempMatrix.IdentityMatrix();
			AppendFollowerMatrix(t,tempMatrix);

			//pblock->Append(follower_matrix,1,&tempMat);
	
		}
	}

}
void VRayCamera::buildMesh(void) {
  if (meshBuilt) return;

  int nverts = 16;
  int nfaces = 24;
  mesh.setNumVerts(nverts);
  mesh.setNumFaces(nfaces);
  float len = (float)5.0;
  float w = (float)8.0;
  float d = w*(float).8;
  float e = d*(float).5;
  float f = d*(float).8;
  float l = w*(float).8;

  mesh.setVert(0, Point3( -d, -d, -len));
  mesh.setVert(1, Point3(  d, -d, -len));
  mesh.setVert(2, Point3( -d,  d, -len));
  mesh.setVert(3, Point3(  d,  d, -len));
  mesh.setVert(4, Point3( -d, -d,  len));
  mesh.setVert(5, Point3(  d, -d,  len));
  mesh.setVert(6, Point3( -d,  d,  len));
  mesh.setVert(7, Point3(  d,  d,  len));
  MakeQuad(&(mesh.faces[ 0]), 0,2,3,1,  1);
  MakeQuad(&(mesh.faces[ 2]), 2,0,4,6,  2);
  MakeQuad(&(mesh.faces[ 4]), 3,2,6,7,  4);
  MakeQuad(&(mesh.faces[ 6]), 1,3,7,5,  8);
  MakeQuad(&(mesh.faces[ 8]), 0,1,5,4, 16);
  MakeQuad(&(mesh.faces[10]), 4,5,7,6, 32);

  mesh.setVert(8+0, Point3( -e, -e, len));
  mesh.setVert(8+1, Point3(  e, -e, len));
  mesh.setVert(8+2, Point3( -e,  e, len));
  mesh.setVert(8+3, Point3(  e,  e, len));
  mesh.setVert(8+4, Point3( -f, -f, len+l));
  mesh.setVert(8+5, Point3(  f, -f, len+l));
  mesh.setVert(8+6, Point3( -f,  f, len+l));
  mesh.setVert(8+7, Point3(  f,  f, len+l));

  Face* fbase = &mesh.faces[12];
  MakeQuad(&fbase[0], 0,2,3,1,  1, 8);
  MakeQuad(&fbase[2], 2,0,4,6,  2, 8);
  MakeQuad(&fbase[4], 3,2,6,7,  4, 8);
  MakeQuad(&fbase[6], 1,3,7,5,  8, 8);
  MakeQuad(&fbase[8], 0,1,5,4, 16, 8);
  MakeQuad(&fbase[10],4,5,7,6, 32, 8);

  // whoops- rotate 180 about x to get it facing the right way
  Matrix3 mat;
  mat.IdentityMatrix();
  mat.RotateX(DegToRad(180.0));
  for (int i=0; i<nverts; i++) mesh.getVert(i)=mat*mesh.getVert(i);
  mesh.buildNormals();
  mesh.EnableEdgeList(1);
  meshBuilt = true;
}
Beispiel #12
0
int CreateSWrapObjectProc::createmethod(
		ViewExp *vpt,int msg, int point, int flags, IPoint2 m, Matrix3& mat)
	{	Point3 d;

#ifdef _3D_CREATE
	DWORD snapdim = SNAP_IN_3D;
#else
	DWORD snapdim = SNAP_IN_PLANE;
#endif

#ifdef _OSNAP
	if (msg == MOUSE_FREEMOVE)
	{ vpt->SnapPreview(m,m,NULL, snapdim);
	}
#endif
	if (msg==MOUSE_POINT||msg==MOUSE_MOVE) {
		switch(point) {
			case 0:
				sp0 = m;
				p0  = vpt->SnapPoint(m,m,NULL,snapdim);
				mat.SetTrans(p0);
				SWrapObj->pblock->SetValue(PB_ICONSIZE,0,0.01f);
				SWrapObj->pmapParam->Invalidate();
				break;

			case 1: {
				mat.IdentityMatrix();
				sp1 = m;
				p1  = vpt->SnapPoint(m,m,NULL,snapdim);
				Point3 center = (p0+p1)/float(2);
				mat.SetTrans(center);
				SWrapObj->pblock->SetValue(PB_ICONSIZE,0,Length(p1-p0));
				SWrapObj->pmapParam->Invalidate();

				if (msg==MOUSE_POINT) {
					if (Length(m-sp0)<3) {						
						return CREATE_ABORT;
					} else {
					ICustButton *iBut = GetICustButton(GetDlgItem(SWrapObj->hParams,IDC_AP_WRAPBUTTON));
					iBut->Enable();
					ReleaseICustButton(iBut);
						return CREATE_STOP;
						}
					}
				break;
				}

			}
	} else {
		if (msg == MOUSE_ABORT)
			return CREATE_ABORT;
		}	
	return TRUE;
	}
void VRayCamera::getTM(TimeValue t, INode *node, ViewExp *vpt, Matrix3 &tm) {
  tm=node->GetObjectTM(t);

  AffineParts ap;
  decomp_affine(tm, &ap);
  tm.IdentityMatrix();
  tm.SetRotate(ap.q);
  tm.SetTrans(ap.t);

  float scaleFactor=vpt->NonScalingObjectSize()*vpt->GetVPWorldWidth(tm.GetTrans())/360.0f;
  tm.Scale(Point3(scaleFactor,scaleFactor,scaleFactor));
}
Beispiel #14
0
int GSphereObjCreateCallBack::proc(ViewExp *vpt, int msg, int point, int flags, IPoint2 m, Matrix3& mat ) {

	if ( ! vpt || ! vpt->IsAlive() )
	{
		// why are we here
		DbgAssert(!_T("Doing proc() on invalid viewport!"));
		return FALSE;
	}

	Point3 p1, center;

	if (msg == MOUSE_FREEMOVE)
	{
		vpt->SnapPreview(m, m, NULL, SNAP_IN_3D);
	}


	if (msg==MOUSE_POINT||msg==MOUSE_MOVE) {
		switch(point) {
		case 0:  // only happens with MOUSE_POINT msg
			ob->suspendSnap = TRUE;				
			sp0 = m;
			p0 = vpt->SnapPoint(m, m, NULL, SNAP_IN_3D);
			mat.SetTrans(p0);
			break;
		case 1:
			mat.IdentityMatrix();
			p1 = vpt->SnapPoint(m, m, NULL, SNAP_IN_3D);
			center = (p0+p1)/float(2);
			mat.SetTrans(center);
			mat.SetTrans(center);
			container_param_blk.InvalidateUI();

			if (flags&MOUSE_CTRL) {
				float ang = (float)atan2(p1.y-p0.y, p1.x-p0.x);					
				mat.PreRotateZ(ob->ip->SnapAngle(ang));
			}

			if (msg==MOUSE_POINT) {
				ob->suspendSnap = FALSE;
				return (Length(m-sp0)<3)?CREATE_ABORT:CREATE_STOP;
			}
			break;					   
		}
	} else {
		if (msg == MOUSE_ABORT) return CREATE_ABORT;
	}

	return TRUE;
}
Beispiel #15
0
int
APITestUtil::MakeTestXFormSurface(NURBSSet &nset, int p)
{
	NURBSXFormSurface *s = new NURBSXFormSurface();
	s->SetName(GetString(IDS_XFORM_SURFACE));
	s->SetNSet(&nset);

	s->SetParent(p);
	Matrix3 mat;
	mat.IdentityMatrix();
	mat.SetTrans(Point3(-150, 150, 0));
	s->SetXForm(0, mat);
	return nset.AppendObject(s);
}
Beispiel #16
0
void
APITestUtil::PointTests()
{
	// now let's build a test object
	NURBSSet nset;
	Matrix3 mat;
	mat.IdentityMatrix();


	// 6 types of points...

	// 1: build an independent point
	int indPnt = MakeTestPoint(nset);


	// 2: now a constrained point
	int ptPnt = MakeTestPointCPoint(nset, indPnt);



	// build a cv curve
	int cvCrv = MakeTestCVCurve(nset, mat);

	// 3: a constrained point on that curve
	int crvPnt = MakeTestCurveCPoint(nset, cvCrv);



	// build a cv surface
	int cvSurf = MakeTestCVSurface(nset, mat);

	// 4: a constrained point on that surface
	int srfPnt = MakeTestSurfCPoint(nset, cvSurf);

	// 5: Curve Curve intersection point
	int cvCrv1 = MakeTestCVCurve(nset, TransMatrix(Point3(65, 0, 0)) * RotateZMatrix(0.5));
	int intPoint = MakeTestCurveCurve(nset, cvCrv, cvCrv1, FALSE);

	// 6: Curve Surface intersection point.
	int cvCrv2 = MakeTestCVCurve(nset, RotateXMatrix(PI/2.0f) * TransMatrix(Point3(0, 0, -175)));
	int srfIntPoint = MakeTestCurveSurface(nset, cvSurf, cvCrv2);


	Object *obj = CreateNURBSObject(mpIp, &nset, mat);
	INode *node = mpIp->CreateObjectNode(obj);
	node->SetName(GetString(IDS_PNT_TEST_OBJECT));
	mpIp->RedrawViews(mpIp->GetTime());
}
Beispiel #17
0
int
FogCreateCallBack::proc(ViewExp *vpt,int msg, int point, int flags,
                               IPoint2 m, Matrix3& mat)
{	
    if ( ! vpt || ! vpt->IsAlive() )
		{
			// why are we here?
			DbgAssert(!"Doing proc() on invalid view port!");
			return FALSE;
		}
		
		Point3 p1,center;

    switch ( msg ) {
    case MOUSE_POINT:
    case MOUSE_MOVE:
        switch ( point ) {
        case 0:  // only happens with MOUSE_POINT msg
            sp0 = m;
            p0 = vpt->SnapPoint(m,m,NULL,SNAP_IN_PLANE);
            mat.SetTrans(p0);
            break;
        case 1:
            mat.IdentityMatrix();
            p1 = vpt->SnapPoint(m,m,NULL,SNAP_IN_PLANE);
            mat.SetTrans(p0);
            float radius = Length(p1-p0);
            fogObject->pblock->SetValue(PB_FOG_SIZE,
                                               fogObject->
                                               iObjParams->GetTime(), radius);
            fogObject->pmapParam->Invalidate();										
            if (flags&MOUSE_CTRL) {
                float ang = (float)atan2(p1.y-p0.y,p1.x-p0.x);
                mat.PreRotateZ(fogObject->iObjParams->SnapAngle(ang));
            }

            if (msg==MOUSE_POINT) {
                return (Length(m-sp0)<3)?CREATE_ABORT:CREATE_STOP;
            }
            break;					   
        }			
        break;
    case MOUSE_ABORT:
        return CREATE_ABORT;
    }
	
    return TRUE;
}
Beispiel #18
0
int
APITestUtil::MakeTestMirrorSurface(NURBSSet &nset, int p)
{
	NURBSMirrorSurface *s = new NURBSMirrorSurface();
	s->SetName(GetString(IDS_MIRROR_SURFACE));
	s->SetNSet(&nset);

	s->SetParent(p);
	Matrix3 mat;
	mat.IdentityMatrix();
	s->SetXForm(0, mat);
	s->SetAxis(kMirrorZ);
	s->SetDistance(0, 100.0);
	s->FlipNormals(TRUE);
	return nset.AppendObject(s);
}
Beispiel #19
0
void ProtHelpObject::BuildMesh()
{
   if(meshBuilt)
      return;
   int nverts = 7;
   int nfaces = 8;
   mesh.setNumVerts(nverts);
   mesh.setNumFaces(nfaces);

   float d = 5.0f;
   float ds = 0.866f * d;
   float h = 2.0f * 0.866f * 5.0f;

   mesh.setVert(0, Point3(0.0f, 0.0f, 0.0f ));
   mesh.setVert(1, Point3(  -d,  -ds, -h ));
   mesh.setVert(2, Point3(   d,  -ds, -h ));
   mesh.setVert(3, Point3(0.0f,   ds, -h ));
   mesh.setVert(4, Point3(  -d,  -ds,  h ));
   mesh.setVert(5, Point3(   d,  -ds,  h ));
   mesh.setVert(6, Point3(0.0f,   ds,  h ));
   mesh.faces[0].setVerts(0, 1, 2);
   mesh.faces[0].setEdgeVisFlags(1,1,1);
   mesh.faces[1].setVerts(0, 2, 3);
   mesh.faces[1].setEdgeVisFlags(1,1,1);
   mesh.faces[2].setVerts(0, 3, 1);
   mesh.faces[2].setEdgeVisFlags(1,1,1);
   mesh.faces[3].setVerts(3, 2, 1);
   mesh.faces[3].setEdgeVisFlags(1,1,1);
   mesh.faces[4].setVerts(0, 5, 4);
   mesh.faces[4].setEdgeVisFlags(1,1,1);
   mesh.faces[5].setVerts(0, 6, 5);
   mesh.faces[5].setEdgeVisFlags(1,1,1);
   mesh.faces[6].setVerts(0, 4, 6);
   mesh.faces[6].setEdgeVisFlags(1,1,1);
   mesh.faces[7].setVerts(4, 5, 6);
   mesh.faces[7].setEdgeVisFlags(1,1,1);
#if 1
   // whoops- rotate 90 about x to get it facing the right way
   Matrix3 mat;
   mat.IdentityMatrix();
   mat.RotateX(DegToRad(90.0));
   for (int i=0; i<nverts; i++)
      mesh.getVert(i) = mat*mesh.getVert(i);
#endif
// mesh.buildNormals();
   meshBuilt = 1;
}
Matrix3 SGP_MaxInterface::GetNodeTM(INode *pNode, float time)
{
	// initialize matrix with the identity
	Matrix3 tm;
	tm.IdentityMatrix();

	// only do this for valid nodes
	if(pNode != NULL)
	{
		// get the node transformation
		tm = pNode->GetNodeTM(SecToTicks(time));

		// make the transformation uniform
		tm.NoScale();
	}

	return tm;
}
Beispiel #21
0
void
APITestUtil::COSTests()
{
	// now let's build a test object
	NURBSSet nset;
	Matrix3 mat;
	mat.IdentityMatrix();

	// build a cv surface
	int cvSurf = MakeTestCVSurface(nset, mat);

	// Now an Iso Curve on the CV surface
	int isoCrv1 = MakeTestIsoCurveU(nset, cvSurf);

	// Now an Iso Curve on the CV surface
	int isoCrv2 = MakeTestIsoCurveV(nset, cvSurf);

	// build a CV Curve on Surface
	int cvCOS = MakeTestCurveOnSurface(nset, cvSurf);

	// build a Point Curve on Surface
	int pntCOS = MakeTestPointCurveOnSurface(nset, cvSurf);

	// build a Surface Normal Offset Curve
	int cnoCrf = MakeTestSurfaceNormalCurve(nset, cvCOS);

	// build a surface surface intersection curve
	int cvSurf1 = MakeTestCVSurface(nset, TransMatrix(Point3(0.0, 0.0, -30.0)) * RotateYMatrix(0.5));
	int intCrv = MakeTestSurfSurfIntersectionCurve(nset, cvSurf, cvSurf1);

	// Vector Projection Curve
	int cvCrv1 = MakeTestCVCurve(nset, TransMatrix(Point3(-100, -200, 40)));
	int vecCrv = MakeTestProjectVectorCurve(nset, cvSurf, cvCrv1);

	// Normal Normal Curve
	int cvCrv2 = MakeTestCVCurve(nset, TransMatrix(Point3(0, -250, 10)));
	int nrmCrv = MakeTestProjectNormalCurve(nset, cvSurf1, cvCrv2);


	Object *obj = CreateNURBSObject(mpIp, &nset, mat);
	INode *node = mpIp->CreateObjectNode(obj);
	node->SetName(GetString(IDS_COS_TEST_OBJECT));
	mpIp->RedrawViews(mpIp->GetTime());
}
Beispiel #22
0
int
SwitchCreateCallBack::proc(ViewExp *vpt, int msg, int point, int flags,
                           IPoint2 m, Matrix3 &mat)
{
    Point3 p1, center;

    switch (msg)
    {
    case MOUSE_POINT:
    case MOUSE_MOVE:
        switch (point)
        {
        case 0: // only happens with MOUSE_POINT msg
            sp0 = m;
            p0 = vpt->SnapPoint(m, m, NULL, SNAP_IN_PLANE);
            mat.SetTrans(p0);
            break;
        case 1:
            mat.IdentityMatrix();
            p1 = vpt->SnapPoint(m, m, NULL, SNAP_IN_PLANE);
            mat.SetTrans(p0);
            float radius = Length(p1 - p0);
            switchSensorObject->pblock->SetValue(PB_S_SIZE,
                                                 switchSensorObject->iObjParams->GetTime(), radius);
            switchSensorObject->pmapParam->Invalidate();
            if (flags & MOUSE_CTRL)
            {
                float ang = (float)atan2(p1.y - p0.y, p1.x - p0.x);
                mat.PreRotateZ(switchSensorObject->iObjParams->SnapAngle(ang));
            }

            if (msg == MOUSE_POINT)
            {
                return (Length(m - sp0) < 3) ? CREATE_ABORT : CREATE_STOP;
            }
            break;
        }
        break;
    case MOUSE_ABORT:
        return CREATE_ABORT;
    }

    return TRUE;
}
Beispiel #23
0
void XsiExp::ExportNodeTM( INode * node, int indentLevel)
{
	// dump the full matrix
	Matrix3 matrix = node->GetNodeTM(GetStaticFrame());
	TSTR indent = GetIndent(indentLevel);
	
	fprintf(pStream,"%s\t%s {\n\n", indent.data(), "FrameTransformMatrix");

	Object * obj = node->EvalWorldState(0).obj;
  BOOL isBone = obj && obj->ClassID() == Class_ID(BONE_CLASS_ID, 0) ? TRUE : FALSE;

  if (node->GetParentNode() && node->GetParentNode()->IsRootNode())
  {
    // bone chains get grafted into the hierarchy tree
    //
	  if (!isBone)
    {
      // root mesh
      oTopMatrix = matrix;
      AffineParts ap;
      decomp_affine( matrix, &ap);
      topMatrix.Set( Point3( ap.k.x,0.0f,0.0f), Point3( 0.0f,ap.k.z,0.0f), Point3(0.0f,0.0f,ap.k.y), Point3(0,0,0));

      // root transform is controlled by the engine
      matrix.IdentityMatrix();
    }
  }
  else
  {
    matrix = matrix * Inverse(node->GetParentTM(GetStaticFrame()));
    if (!isBone)
    {
      matrix.SetRow( 3, topMatrix * matrix.GetRow(3));
    }
  }

  // write the matrix values
  DumpMatrix3( &matrix, indentLevel+2);

  // transform close brace
	fprintf(pStream,"%s\t}\n", indent.data());
}
Beispiel #24
0
void TapeHelpObject::BuildMesh()
{
    if(meshBuilt)
        return;
    int nverts = 5;
    int nfaces = 6;
    mesh.setNumVerts(nverts);
    mesh.setNumFaces(nfaces);

    float d =  5.0f;
    float h = 10.0f;

    mesh.setVert(0, Point3(  -d, -d, 0.0f ));
    mesh.setVert(1, Point3(   d, -d, 0.0f ));
    mesh.setVert(2, Point3(   d,  d, 0.0f ));
    mesh.setVert(3, Point3(  -d,  d, 0.0f ));
    mesh.setVert(4, Point3(0.0f,0.0f, -h  ));
    mesh.faces[0].setVerts(0, 3, 1);
    mesh.faces[0].setEdgeVisFlags(1,1,0);
    mesh.faces[1].setVerts(3, 2, 1);
    mesh.faces[1].setEdgeVisFlags(1,1,0);
    mesh.faces[2].setVerts(0, 1, 4);
    mesh.faces[2].setEdgeVisFlags(1,1,1);
    mesh.faces[3].setVerts(1, 2, 4);
    mesh.faces[3].setEdgeVisFlags(1,1,1);
    mesh.faces[4].setVerts(2, 3, 4);
    mesh.faces[4].setEdgeVisFlags(1,1,1);
    mesh.faces[5].setVerts(3, 0, 4);
    mesh.faces[5].setEdgeVisFlags(1,1,1);
#if 0
    // whoops- rotate 180 about x to get it facing the right way
    Matrix3 mat;
    mat.IdentityMatrix();
    mat.RotateX(DegToRad(180.0));
    for (int i=0; i<nverts; i++)
        mesh.getVert(i) = mat*mesh.getVert(i);
#endif
    mesh.buildNormals();
    mesh.EnableEdgeList(1);
    meshBuilt = 1;
}
Beispiel #25
0
Matrix3 Jiggle::GetCurrentTM(TimeValue t)
{
	INode* baseNode = NULL;
	baseNode = selfNode;

	Matrix3 selfTM;
	Point3 pos = Point3(0.0f,0.0f,0.0f);
	Interval for_ever = FOREVER;
	posCtrl->GetValue(t, pos, for_ever, CTRL_ABSOLUTE);
	if (baseNode != NULL )
	{
		selfTM = baseNode->GetNodeTM(t);
		selfTM.SetTrans(selfTM * pos);
	}
	else 
	{	
		selfTM.IdentityMatrix();
		selfTM.SetTrans(pos);
	}
	return selfTM;
}
Beispiel #26
0
int
OBJImport::DoImport(const TCHAR *filename,ImpInterface *i,Interface *gi, BOOL suppressPrompts) {
	TriObject *object = CreateNewTriObject();
	if(!object)
		return 0;
	if(objFileRead(filename, &object->GetMesh())) {
		ImpNode *node = i->CreateNode();
		if(!node) {
			delete object;
			return 0;
			}
		Matrix3 tm;
		tm.IdentityMatrix();
		node->Reference(object);
		node->SetTransform(0,tm);
		i->AddNodeToScene(node);
		node->SetName(GetString(IDS_TH_WAVE_OBJ_NAME));
		i->RedrawViews();
		return 1;
		}
	return 0;
	}
Beispiel #27
0
int ConeAngleManipCreateCallBack::proc(ViewExp *pVpt, int msg, int point, int flags,
                                       IPoint2 m, Matrix3& mat ) {
    float r;
    Point3 p1, center;

    if (msg == MOUSE_FREEMOVE)
    {
        pVpt->SnapPreview(m, m, NULL, SNAP_IN_3D);
    }


    if (msg==MOUSE_POINT||msg==MOUSE_MOVE) {
        switch(point) {
        case 0:  // only happens with MOUSE_POINT msg
//            ob->suspendSnap = TRUE;             
            sp0 = m;
            p0 = pVpt->SnapPoint(m, m, NULL, SNAP_IN_3D);
            mat.SetTrans(p0);
            break;
        case 1:
            mat.IdentityMatrix();
            p1 = pVpt->SnapPoint(m, m, NULL, SNAP_IN_3D);
            r = Length(p1-p0);
            mat.SetTrans(p0);

            mpManip->GetPBlock()->SetValue(kConeAngleDistance, 0, r);
            ConeAngleManipBlock.InvalidateUI();

            if (msg==MOUSE_POINT) {
                return (Length(m-sp0)<3)?CREATE_ABORT:CREATE_STOP;
            }
            break;                     
        }
    } else {
        if (msg == MOUSE_ABORT) return CREATE_ABORT;
    }

    return TRUE;
}
//---------------------------------------------------------------------------
//
// This implementation of NfGetLocalTM removes all scales from the returned
// Matrix3, but also stores them in the parameter pScaleOut (if specified)
// so that they can be pushed down to the geometry level.
//
Matrix3 U2MaxSceneExport::GetLocalTM(INode* pMaxNode, TimeValue t)
{
	Matrix3 localScaleTM;
	INode* pParent = pMaxNode->GetParentNode();


	if(pParent)
	{
		Matrix3 parentTM = pParent->GetNodeTM(t);
		Matrix3 thisTM = pMaxNode->GetNodeTM(t);

		localScaleTM = thisTM * Inverse(parentTM);		
	}
	else 
		localScaleTM.IdentityMatrix();

	Matrix3 localNoScaleTM;
	localNoScaleTM = UniformMatrix(localScaleTM);

	return localNoScaleTM;

}
Beispiel #29
0
TwistDeformer::TwistDeformer(
      TimeValue t, ModContext &mc,
      float angle, int naxis, float bias,
      float from, float to, int doRegion,
      Matrix3& modmat, Matrix3& modinv) 
   {  
   this->doRegion = doRegion;
   this->from = from;
   this->to   = to;
   if (bias!=0.0f) {
      this->bias = 1.0f-(bias+100.0f)/200.0f;
      if (this->bias < 0.00001f) this->bias = 0.00001f;
      if (this->bias > 0.99999f) this->bias = 0.99999f;
      this->bias = float(log(this->bias)/log(0.5));
      doBias = TRUE;
   } else {
      this->bias = 1.0f;
      doBias = FALSE;
      }
   
   Matrix3 mat;
   Interval valid;   
   time   = t; 

   tm = modmat;
   invtm = modinv;
   mat.IdentityMatrix();
   
   switch ( naxis ) {
      case 0: mat.RotateY( -HALFPI );   break; //X
      case 1: mat.RotateX( HALFPI );  break; //Y
      case 2: break;  //Z
      }
   SetAxis( mat );   
   assert (mc.box);
   bbox = *mc.box;
   CalcHeight(naxis,DegToRad(angle));
   }
Beispiel #30
0
void
APITestUtil::CurveTests()
{
	// now let's build a test object
	NURBSSet nset;
	Matrix3 mat;
	mat.IdentityMatrix();

	// build a cv curve
	int cvCrv = MakeTestCVCurve(nset, mat);

	// now a point curve
	int ptCrv = MakeTestPointCurve(nset, mat);

	// Blend the two curves
	int blendCrv = MakeTestBlendCurve(nset, cvCrv, ptCrv);

	// make an offset of the CV curve
	int offCrv = MakeTestOffsetCurve(nset, cvCrv);

	// make a Transform curve of the point curve
	int xformCrv = MakeTestXFormCurve(nset, ptCrv);

	// make a mirror of the blend
	int mirCrv = MakeTestMirrorCurve(nset, blendCrv);

	// make a fillet curve (It makes it's own point curves to fillet)
	int fltCrv = MakeTestFilletCurve(nset);

	// make a chamfer curve (It makes it's own point curves to fillet)
	int chmCrv = MakeTestChamferCurve(nset);

	Object *obj = CreateNURBSObject(mpIp, &nset, mat);
	INode *node = mpIp->CreateObjectNode(obj);
	node->SetName(GetString(IDS_CRV_TEST_OBJECT));
	mpIp->RedrawViews(mpIp->GetTime());
}