当前位置: 首页>>代码示例>>C++>>正文


C++ NxMat33::diagonal方法代码示例

本文整理汇总了C++中NxMat33::diagonal方法的典型用法代码示例。如果您正苦于以下问题:C++ NxMat33::diagonal方法的具体用法?C++ NxMat33::diagonal怎么用?C++ NxMat33::diagonal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NxMat33的用法示例。


在下文中一共展示了NxMat33::diagonal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

NxPhysicsForceField::NxPhysicsForceField( NxPhysicsActor * Actor )//   NxPhysicsShape * Shape )
{

	//NxShape * mShape = Shape->GetNxShape();

	NxForceFieldLinearKernelDesc lKernelDesc;
	//constant force of 10 forward, which is then animated in the update() method
	lKernelDesc.constant = NxVec3(0, 0, 0);

	//lKernelDesc.constant = NxVec3(20, 0, 0);

	//The forces do not depend on where the objects are positioned
	NxMat33 m; m.zero();

	m(0,0) = -100; //radial force 
	m(0,1) = -100; //radial force 
	m(0,2) = -100; //radial force 

	lKernelDesc.positionMultiplier = m;
	lKernelDesc.noise = NxVec3(0.0,0.5,0.0); //adds a random noise on the forces to make the objects a little more chaotic

	//Set target velocity along the main axis to 20
	lKernelDesc.velocityTarget = NxVec3(10,10,10);  //20

	//Acts with a force relative to the current velocity to reach the target velocities. 0 means that those components won't be affected
	m.diagonal(NxVec3(0,0,0)); 
	lKernelDesc.velocityMultiplier = m;

	NxForceFieldLinearKernel * linearKernel = Actor->GetNxActor()->getScene().createForceFieldLinearKernel(lKernelDesc);

	//Create the forcefield with the Custom kernel
	NxForceFieldDesc fieldDesc1;
	fieldDesc1.kernel = linearKernel;
	fieldDesc1.coordinates = NX_FFC_SPHERICAL;//  NX_FFC_CARTESIAN;
	fieldDesc1.fluidType = NX_FF_TYPE_OTHER;//NX_FF_TYPE_GRAVITATIONAL;
	fieldDesc1.clothType = NX_FF_TYPE_OTHER;//NX_FF_TYPE_GRAVITATIONAL;
	fieldDesc1.softBodyType = NX_FF_TYPE_OTHER;//NX_FF_TYPE_GRAVITATIONAL;
	fieldDesc1.rigidBodyType = NX_FF_TYPE_OTHER;//NX_FF_TYPE_GRAVITATIONAL;

	// The field's pose is relative to the actor's pose and relative to the world frame if field is null.
	fieldDesc1.actor = Actor->GetNxActor();

	fieldDesc1.flags = NX_FFF_VOLUMETRIC_SCALING_FLUID | NX_FFF_VOLUMETRIC_SCALING_CLOTH | NX_FFF_VOLUMETRIC_SCALING_SOFTBODY | NX_FFF_VOLUMETRIC_SCALING_RIGIDBODY;

	mForceField = Actor->GetNxActor()->getScene().createForceField(fieldDesc1);

}
开发者ID:nxgraphics,项目名称:NxGraphics,代码行数:47,代码来源:NxPhysicsMagnet.cpp

示例2: createVortexForceField

//This method creates the vortex force field and include/exclude shapes.
//
//This is the most interesting function in this demo, below are other methods for controlling
//the movement of the vortex and turning on/off the exclude shape
//
void SampleVortex::createVortexForceField(const NxVec3& pos, NxActor* actor, NxScene* scene)
{
	assert(scene);

	NxForceFieldDesc ffDesc;
	NxForceFieldLinearKernelDesc	lKernelDesc;
	NxForceFieldLinearKernel*		linearKernel;

	ffDesc.coordinates = NX_FFC_CYLINDRICAL;
	//Attach the vortex in an actor (which we use for moving the field around in the world)
	ffDesc.actor = actor;
	//attach the force field at the center of the actor
	m_forceFieldTransform.id(); 
	ffDesc.pose = m_forceFieldTransform;

	//constant force of 30 towards the center (which is then counter-acted by radial forces specified below)
	//constant force of 4 upwards (creating a constant lift on the objects)
	lKernelDesc.constant = NxVec3(-30, 4.0f, 0);

	//The target where we want the objects to end up is at radius 3 from the center. We use
	//Y=0 as the target in along the y-axis together with the m(0,1)=-5 to create a force
	//directed outwards from the center of the vortex when objects are floating towards the
	//top of the vortex.
	lKernelDesc.positionTarget = NxVec3(3,0,0);

	//Setup radial forces, depending on where the objects are positioned
	NxMat33 m;
	m.zero();
	m(0,0) = 10; //radial error -> radial force. If outside of target radius, act with a force of 10*distance inwards
	m(0,1) = -5; //axial error -> radial force. If the y component of the object position is above the target y position (0), 
				 //then act with a force of 5*distance outwards. This reduces the force of 30 inwards that we setup earlier,
				 //making the vortex broaden out in the top
	m(0,2) = 0;  //there is no tangential error in cylindrical coordinates, so we just set this to 0
	lKernelDesc.positionMultiplier = m;
	lKernelDesc.noise = NxVec3(5,5,5); //adds a random noise on the forces to make the objects a little more chaotic

	//Set target velocity along the tangent of the vortex to 30 (the other directions to 0)
	lKernelDesc.velocityTarget = NxVec3(0,0,30);
	m.diagonal(NxVec3(1,1,1)); //Acts with a force relative to the current velocity to reach the
							   //target velocities. If the velocity is above 0 in radial direction, then
							   //the radial velocity is decreased. If the velocity is below 30 in tangential
							   //direction, then the velocity is increased until it reaches that velocity.
	lKernelDesc.velocityMultiplier = m;

	//You can try some fall-off forces if you e.g. want the vortex to lose power 
	//along the radial direction when the distance from its center increases:
	lKernelDesc.falloffLinear = NxVec3(5.0f, 0, 0);
	lKernelDesc.falloffQuadratic = NxVec3(5.0f, 0, 0);
	linearKernel = scene->createForceFieldLinearKernel(lKernelDesc);
	ffDesc.kernel = linearKernel;
	ffDesc.flags = 0;

	m_forceField = scene->createForceField(ffDesc);
	assert(m_forceField);

	//Attach an include shape, we position this so that it covers the vortex specified above
	NxForceFieldShape* s = NULL;
	NxBoxForceFieldShapeDesc b;
	b.dimensions = NxVec3(5, 7, 5);
	b.pose.t	 = NxVec3(0, 3.5f, 0);
	s = m_forceField->getIncludeShapeGroup().createShape(b);

	//Create an exclude shape, positioned around the shed
	NxForceFieldShapeGroupDesc sgDesc;
	sgDesc.flags	= NX_FFSG_EXCLUDE_GROUP;
	m_excludeGroup	= scene->createForceFieldShapeGroup(sgDesc);
	
	NxBoxForceFieldShapeDesc exclude;
	exclude.dimensions	= NxVec3(2.25f, 1.5f, 1.75f);
	exclude.pose.t		= NxVec3(8.85f, 1.5f, -10.3f);
	m_excludeShape		= m_excludeGroup->createShape(exclude);

	m_forceField->addShapeGroup(*m_excludeGroup);
}
开发者ID:binly,项目名称:TestPhysx,代码行数:79,代码来源:VortexSample.cpp


注:本文中的NxMat33::diagonal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。