dAnimIKController* CreateHuman(DemoEntity* const model, const dMatrix& origin)
	{
		DemoEntityManager* const scene = (DemoEntityManager*) NewtonWorldGetUserData(GetWorld());

		DemoEntity* const character = (DemoEntity*)model->CreateClone();
		character->SetNameID("dommyRoot");
		character->ResetMatrix(*scene, character->GetCurrentMatrix() * origin);
		scene->Append(character);

		dAnimIKController* const controller = CreateSkeletonRig(character);

//		dAnimCharacterUserData* const userData = new dAnimCharacterUserData(controller);
//		character->SetUserData(userData);
		
		// populate base pose
		PopulateBasePose(controller->GetBasePose(), character);
		//dAnimTakeData* const walkCycle = LoadAnimation(controller, "whiteman_walk.ngd");
		dAnimTakeData* const walkCycle = LoadAnimation(controller, "whiteman_idle.ngd");

		dAnimIKBlendNodeTake* const walk = new dAnimIKBlendNodeTake(controller, walkCycle);
		//dAnimIKBlendNodePose* const walk = new dAnimIKBlendNodePose(controller);
		//dAnimIKBlendNodePose* const pose = new dAnimIKBlendNodePose(controller);
		dAnimIKBlendNodeRoot* const animTree = new dAnimIKBlendNodeRoot(controller, walk);
		//dAnimIKBlendNodeRoot* const animTree = new dAnimIKBlendNodeRoot(controller, pose);

		controller->SetAnimationTree(animTree);
		return controller;
	}
	void PreUpdate(dFloat timestep)
	{
		NewtonWorld* const workd = GetWorld();
		DemoEntityManager* const scene = (DemoEntityManager*)NewtonWorldGetUserData(workd);

		bool mouseClick = scene->GetMouseKeyState(0);
		if (!m_mouseDown && mouseClick) {
			if (!m_body) {
				// pick a body form teh scene
				int mouseX;
				int mouseY;

				DemoCamera* const camera = scene->GetCamera();
				scene->GetMousePosition(mouseX, mouseY);

				dFloat x = dFloat(mouseX);
				dFloat y = dFloat(mouseY);
				dVector p0(camera->ScreenToWorld(dVector(x, y, 0.0f, 0.0f)));
				dVector p1(camera->ScreenToWorld(dVector(x, y, 1.0f, 0.0f)));
				RayCastCompoundsAllSubShapes(p0, p1);
			}
		} else if (m_mouseDown && !mouseClick) {
			// release the body
			m_body = NULL;
		}

		m_mouseDown = mouseClick;
	}
static void OnReconstructMainMeshCallBack (NewtonBody* const body, NewtonFracturedCompoundMeshPart* const mainMesh, const NewtonCollision* const fracturedCompoundCollision)
{
	DemoEntity* const entity = (DemoEntity*)NewtonBodyGetUserData(body);
	DemoMesh* const visualMesh = (DemoMesh*)entity->GetMesh();
	dAssert (visualMesh->IsType(DemoMesh::GetRttiType()));
	
	dAssert (NewtonCollisionGetType(fracturedCompoundCollision) == SERIALIZE_ID_FRACTURED_COMPOUND);

	DemoEntityManager* const scene = (DemoEntityManager*)NewtonWorldGetUserData(NewtonBodyGetWorld(body));
	dAssert (scene);

	visualMesh->RemoveAll();
	for (void* segment = NewtonFracturedCompoundMeshPartGetFirstSegment(mainMesh); segment; segment = NewtonFracturedCompoundMeshPartGetNextSegment (segment)) {
		DemoSubMesh* const subMesh = visualMesh->AddSubMesh();

		int material = NewtonFracturedCompoundMeshPartGetMaterial (segment); 
		int indexCount = NewtonFracturedCompoundMeshPartGetIndexCount (segment); 

		subMesh->m_textureHandle = AddTextureRef ((GLuint)material);
		subMesh->m_shader = scene->GetShaderCache().m_diffuseEffect;

		subMesh->AllocIndexData (indexCount);
		subMesh->m_indexCount = NewtonFracturedCompoundMeshPartGetIndexStream (fracturedCompoundCollision, mainMesh, segment, (int*)subMesh->m_indexes); 
	}

	visualMesh->OptimizeForRender();
}
Esempio n. 4
0
VALUE MSNewton::Servo::set_power(VALUE self, VALUE v_joint, VALUE v_power) {
	JointData* joint_data = Util::value_to_joint2(v_joint, JT_SERVO);
	ServoData* cj_data = (ServoData*)joint_data->cj_data;
	WorldData* world_data = (WorldData*)NewtonWorldGetUserData(joint_data->world);
	cj_data->power = Util::clamp_min(Util::value_to_dFloat(v_power), 0.0f) * world_data->scale5;
	return Util::to_value(cj_data->power * world_data->inverse_scale5);
}
	void SpawnRandomProp(const dMatrix& location) const
	{
		NewtonWorld* const world = GetWorld();
		DemoEntityManager* const scene = (DemoEntityManager*) NewtonWorldGetUserData(world);
		//scene->SetCurrent();

		static PrimitiveType proSelection[] = {_SPHERE_PRIMITIVE, _BOX_PRIMITIVE, _CAPSULE_PRIMITIVE, _CYLINDER_PRIMITIVE, _CONE_PRIMITIVE, 
											   _CHAMFER_CYLINDER_PRIMITIVE, _RANDOM_CONVEX_HULL_PRIMITIVE, _REGULAR_CONVEX_HULL_PRIMITIVE};

		PrimitiveType type = PrimitiveType (dRand() % (sizeof (proSelection) / sizeof (proSelection[0])));

		dVector size (0.35f, 0.25f, 0.25f, 0.0f);
		NewtonCollision* const collision = CreateConvexCollision (world, dGetIdentityMatrix(), size, type, 0);
		DemoMesh* const geometry = new DemoMesh("prop", collision, "smilli.tga", "smilli.tga", "smilli.tga");

		dMatrix matrix (location);
		matrix.m_posit.m_y += 0.5f;

		NewtonBody* const prop = CreateSimpleSolid (scene, geometry, 30.0f, matrix, collision, 0);
		NewtonDestroyCollision(collision);
		geometry->Release();

		dFloat initialSpeed = 20.0f; 
		dVector veloc (matrix.m_front.Scale (initialSpeed));
		NewtonBodySetVelocity(prop, &veloc[0]);
		NewtonBodySetLinearDamping(prop, 0);
	}
void* dNewtonBody::GetInterpolatedRotation()
{
	const dNewtonWorld* const world = (dNewtonWorld*) NewtonWorldGetUserData(NewtonBodyGetWorld(m_body));
	ScopeLock scopelock(&m_lock);
	m_interpolatedRotation = m_rotation0.Slerp(m_rotation1, world->m_interpotationParam);
	return &m_interpolatedRotation.m_q0;
}
Esempio n. 7
0
VALUE MSNewton::Bodies::get_force_in_between(VALUE self, VALUE v_body1, VALUE v_body2) {
	const NewtonBody* body1 = Util::value_to_body(v_body1);
	const NewtonBody* body2 = Util::value_to_body(v_body2);
	Util::validate_two_bodies(body1, body2);
	dVector net_force(0.0f, 0.0f, 0.0f);
	for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint(body1); joint; joint = NewtonBodyGetNextContactJoint(body1, joint)) {
		if (NewtonJointGetBody0(joint) == body2 || NewtonJointGetBody1(joint) == body2) {
			for (void* contact = NewtonContactJointGetFirstContact(joint); contact; contact = NewtonContactJointGetNextContact(joint, contact)) {
				NewtonMaterial* material = NewtonContactGetMaterial(contact);
				dVector force;
				NewtonMaterialGetContactForce(material, body1, &force[0]);
				net_force += force;
			}
		}
	}
	const NewtonWorld* world = NewtonBodyGetWorld(body1);
	WorldData* world_data = (WorldData*)NewtonWorldGetUserData(world);
	//BodyData* body1_data = (BodyData*)NewtonBodyGetUserData(body1);
	//BodyData* body2_data = (BodyData*)NewtonBodyGetUserData(body2);
	/*if (world_data->gravity_enabled && (body1_data->gravity_enabled || body2_data->gravity_enabled)) {
		for (int i = 0; i < 3; ++i)
			net_force[i] *= world_data->inverse_scale;
	}*/
	return Util::vector_to_value(net_force, world_data->inverse_scale4);
}
static void OnEmitFracturedChunk (NewtonBody* const chunkBody, NewtonFracturedCompoundMeshPart* const fractureChunkMesh, const NewtonCollision* const fracturedCompoundCollision)
{
	NewtonWorld* const world = NewtonBodyGetWorld(chunkBody);
	DemoEntityManager* const scene = (DemoEntityManager*)NewtonWorldGetUserData(world);

	// set the force an torque call back
	NewtonBodySetForceAndTorqueCallback (chunkBody, PhysicsApplyGravityForce);

	// set the transform callback 
	NewtonBodySetTransformCallback (chunkBody, DemoEntity::TransformCallback);

	// create the visual entity and mesh, and set the use data
	dMatrix matrix;
	NewtonBodyGetMatrix (chunkBody, &matrix[0][0]);

	DemoEntity* const visualChunkEntity = new DemoEntity(matrix, NULL);
	scene->Append(visualChunkEntity);

	NewtonBodySetUserData (chunkBody, visualChunkEntity);

	// create the mesh geometry and attach it to the entity
	DemoMesh* const visualChunkMesh = new DemoMesh ("fracturedChuckMesh");
	visualChunkEntity->SetMesh (visualChunkMesh, dGetIdentityMatrix());
	visualChunkMesh->Release();

	// add the vertex data
	AddMeshVertexwData (visualChunkMesh, fractureChunkMesh, fracturedCompoundCollision);

	// add the mesh indices
	OnReconstructMainMeshCallBack (chunkBody, fractureChunkMesh, fracturedCompoundCollision);
}
	void CreatCasterBody(dFloat location_x, dFloat location_z, PrimitiveType shapeType, int materialID)
	{
		NewtonWorld* const world = ((CustomControllerManager<dClosestDistanceRecord>*)GetManager())->GetWorld();
		DemoEntityManager* const scene = (DemoEntityManager*)NewtonWorldGetUserData(world);

		//dMatrix matrix (GetIdentityMatrix());
		dMatrix matrix (dRollMatrix(3.141592f/2.0f));

		matrix.m_posit.m_x = location_x;
		matrix.m_posit.m_y = 2.0f;
		matrix.m_posit.m_z = location_z;

		// create the shape and visual mesh as a common data to be re used
		dVector size(0.5f, 0.5f, 0.75f, 0.0f);
		NewtonCollision* const collision = CreateConvexCollision (world, dGetIdentityMatrix(), size, shapeType, materialID);

		//	DemoMesh____* const geometry = new DemoMesh____("cylinder_1", collision, "wood_0.tga", "wood_0.tga", "wood_1.tga");
		DemoMesh* const geometry = new DemoMesh("convexShape", collision, "smilli.tga", "smilli.tga", "smilli.tga");
		m_body = CreateSimpleSolid (scene, geometry, 1.0f, matrix, collision, materialID);

		// disable gravity and apply a force that only spin the body 
		//NewtonBodySetForceAndTorqueCallback(m_myBody, PhysicsSpinBody);
		//NewtonBodySetAutoSleep (m_myBody, 0);

		geometry->Release(); 
		NewtonDestroyCollision (collision);
	}
Esempio n. 10
0
		virtual const void InitRigiBody(const NewtonBody* const body, const char* const bodyName) const
		{
			dMatrix matrix;
			DemoEntityManager* const scene = (DemoEntityManager*)NewtonWorldGetUserData(NewtonBodyGetWorld(body));

			NewtonCollision* const collision = NewtonBodyGetCollision(body);
			DemoMesh* const mesh = new DemoMesh("ragdoll", collision, "smilli.tga", "smilli.tga", "smilli.tga");

			NewtonBodyGetMatrix(body, &matrix[0][0]);
			DemoEntity* const entity = new DemoEntity(matrix, NULL);
			entity->SetNameID (bodyName);
			entity->SetMesh(mesh, dGetIdentityMatrix());
			scene->Append(entity);
			mesh->Release();

			// save the pointer to the graphic object with the body.
			NewtonBodySetUserData(body, entity);

			// assign the wood id
			NewtonBodySetMaterialGroupID(body, m_material);

			//set continuous collision mode
			//NewtonBodySetContinuousCollisionMode (rigidBody, continueCollisionMode);

			// set a destructor for this rigid body
			NewtonBodySetDestructorCallback(body, PhysicsBodyDestructor);

			// set the transform call back function
			NewtonBodySetTransformCallback(body, DemoEntity::TransformCallback);

			// set the force and torque call back function
			NewtonBodySetForceAndTorqueCallback(body, PhysicsApplyGravityForce);
		}
Esempio n. 11
0
void* dNewtonBody::GetInterpolatedPosition()
{
	const dNewtonWorld* const world = (dNewtonWorld*)NewtonWorldGetUserData(NewtonBodyGetWorld(m_body));
	ScopeLock scopelock(&m_lock);
	m_interpolatedPosit = m_posit0 + (m_posit1 - m_posit0).Scale(world->m_interpotationParam);
	return &m_interpolatedPosit.m_x;
}
Esempio n. 12
0
VALUE MSNewton::Slider::set_max(VALUE self, VALUE v_joint, VALUE v_max) {
	JointData* joint_data = Util::value_to_joint2(v_joint, JT_SLIDER);
	SliderData* cj_data = (SliderData*)joint_data->cj_data;
	WorldData* world_data = (WorldData*)NewtonWorldGetUserData(joint_data->world);
	cj_data->max = Util::value_to_dFloat(v_max) * world_data->scale;
	return Util::to_value(cj_data->max * world_data->inverse_scale);
}
	void PostUpdate(dFloat timestep, int threadIndex)
	{
		int count = 1;
		void* nodes[32];
		dMatrix parentMatrix[32];
		nodes[0] = NewtonInverseDynamicsGetRoot(m_kinematicSolver);

		parentMatrix[0] = dGetIdentityMatrix();

		NewtonWorld* const world = GetManager()->GetWorld();
		DemoEntityManager* const scene = (DemoEntityManager*)NewtonWorldGetUserData(world);

		while (count) {
			dMatrix matrix;

			count --;
			void* const rootNode = nodes[count];
			NewtonBody* const body = NewtonInverseDynamicsGetBody(m_kinematicSolver, rootNode);
			NewtonBodyGetMatrix (body, &matrix[0][0]);
			dMatrix localMatrix (matrix * parentMatrix[count]);

			DemoEntity* const ent = (DemoEntity*)NewtonBodyGetUserData(body);

			dQuaternion rot(localMatrix);
			ent->SetMatrix(*scene, rot, localMatrix.m_posit);

			matrix = matrix.Inverse();
			for (void* node = NewtonInverseDynamicsGetFirstChildNode(m_kinematicSolver, rootNode); node; node = NewtonInverseDynamicsGetNextChildNode(m_kinematicSolver, node)) {
				nodes[count] = node;
				parentMatrix[count] = matrix;
				count ++;
			}
		}
	}
Esempio n. 14
0
VALUE MSNewton::Slider::set_friction(VALUE self, VALUE v_joint, VALUE v_friction) {
	JointData* joint_data = Util::value_to_joint2(v_joint, JT_SLIDER);
	SliderData* cj_data = (SliderData*)joint_data->cj_data;
	WorldData* world_data = (WorldData*)NewtonWorldGetUserData(joint_data->world);
	cj_data->friction = Util::clamp_min<dFloat>(Util::value_to_dFloat(v_friction), 0.0f) * world_data->scale4;
	return Util::to_value(cj_data->friction * world_data->inverse_scale4);
}
VALUE MSNewton::CurvySlider::set_angular_friction(VALUE self, VALUE v_joint, VALUE v_friction) {
	JointData* joint_data = Util::value_to_joint2(v_joint, JT_CURVY_SLIDER);
	CurvySliderData* cj_data = (CurvySliderData*)joint_data->cj_data;
	WorldData* world_data = (WorldData*)NewtonWorldGetUserData(joint_data->world);
	cj_data->angular_friction = Util::clamp_min(Util::value_to_dFloat(v_friction), 0.0f) * world_data->scale5;
	return Util::to_value(cj_data->angular_friction * world_data->inverse_scale5);
}
	void OnUpdateTransform (const dAnimationRigJoint* const bone, const dMatrix& localMatrix) const
	{
		DemoEntityManager* const scene = (DemoEntityManager*) NewtonWorldGetUserData(GetWorld());
		NewtonBody* const newtonBody = bone->GetNewtonBody();
		DemoEntity* const meshEntity = (DemoEntity*)NewtonBodyGetUserData(newtonBody);
		
		dQuaternion rot(localMatrix);
		meshEntity->SetMatrix(*scene, rot, localMatrix.m_posit);
	}
Esempio n. 17
0
int dNewton::OnBodiesAABBOverlap (const NewtonMaterial* const material, const NewtonBody* const body0, const NewtonBody* const body1, int threadIndex)
{
	dAssert (NewtonBodyGetWorld (body0) == NewtonBodyGetWorld (body1));
	dNewton* const world = (dNewton*) NewtonWorldGetUserData(NewtonBodyGetWorld (body0));
	dNewtonBody* const dBody0 = (dNewtonBody*) NewtonBodyGetUserData (body0);
	dNewtonBody* const dBody1 = (dNewtonBody*) NewtonBodyGetUserData (body1);

	return world->OnBodiesAABBOverlap(dBody0, dBody1, threadIndex);
}
VALUE MSNewton::CurvySlider::get_cur_point(VALUE self, VALUE v_joint) {
	JointData* joint_data = Util::value_to_joint2(v_joint, JT_CURVY_SLIDER);
	CurvySliderData* cj_data = (CurvySliderData*)joint_data->cj_data;
	WorldData* world_data = (WorldData*)NewtonWorldGetUserData(joint_data->world);
	if (cj_data->cur_data_set)
		return Util::point_to_value(cj_data->cur_point, world_data->inverse_scale);
	else
		return Qnil;
}
Esempio n. 19
0
	BasicCarControllerManager (NewtonWorld* const world)
		:CustomVehicleControllerManager (world)
		,m_externalView(true)
		,m_player (NULL) 
	{
		// hook a callback for 2d help display
		DemoEntityManager* const scene = (DemoEntityManager*) NewtonWorldGetUserData(world);
		scene->Set2DDisplayRenderFunction (RenderVehicleHud, this);
	}
Esempio n. 20
0
	virtual void OnUpdateTransform(const dAnimationJoint* const bone, const dMatrix& localMatrix) const
	{
		// calculate the local transform for this player body
		NewtonBody* const body = bone->GetBody();
		DemoEntity* const ent = (DemoEntity*)NewtonBodyGetUserData(body);
		DemoEntityManager* const scene = (DemoEntityManager*)NewtonWorldGetUserData(NewtonBodyGetWorld(body));

		dQuaternion rot(localMatrix);
		ent->SetMatrix(*scene, rot, localMatrix.m_posit);
	}
Esempio n. 21
0
	virtual void OnUpdateTransform (const dCustomActiveCharacterController::dSkeletonBone* const bone, const dMatrix& localMatrix) const
	{
		DemoEntity* const ent = (DemoEntity*) NewtonBodyGetUserData(bone->m_body);
		DemoEntityManager* const scene = (DemoEntityManager*) NewtonWorldGetUserData(NewtonBodyGetWorld(bone->m_body));
		
		dQuaternion rot (localMatrix);
		ent->SetMatrix (*scene, rot, localMatrix.m_posit);

		dCustomActiveCharacterControllerManager::OnUpdateTransform (bone, localMatrix);
	}
Esempio n. 22
0
void _CDECL World::newtonLeaveWorld( const NewtonBody* body, int threadIndex )
{
    OgreNewt::World* me = (OgreNewt::World*)NewtonWorldGetUserData( NewtonBodyGetWorld( body ) );

    if (me->m_leaveCallback)
    {
        OgreNewt::Body* b = (OgreNewt::Body*)NewtonBodyGetUserData( body );
        me->m_leaveCallback( b, threadIndex );
    }
}
VALUE MSNewton::CurvySlider::add_point(VALUE self, VALUE v_joint, VALUE v_position) {
	JointData* joint_data = Util::value_to_joint2(v_joint, JT_CURVY_SLIDER);
	CurvySliderData* cj_data = (CurvySliderData*)joint_data->cj_data;
	WorldData* world_data = (WorldData*)NewtonWorldGetUserData(joint_data->world);
	dVector point = Util::value_to_point(v_position, world_data->scale);
	dMatrix pin_matrix;
	MSNewton::Joint::c_get_pin_matrix(joint_data, pin_matrix);
	cj_data->points.push_back(pin_matrix.UntransformVector(point));
	cj_data->curve_len = c_calc_curve_length(cj_data->points, cj_data->loop);
	return Util::to_value(cj_data->points.size() - 1);
}
Esempio n. 24
0
void dNewton::OnContactProcess (const NewtonJoint* const contactJoint, dFloat timestep, int threadIndex)
{
	NewtonBody* const body = NewtonJointGetBody0 (contactJoint);
	dNewton* const world = (dNewton*) NewtonWorldGetUserData(NewtonBodyGetWorld (body));
//	for (void* contact = NewtonContactJointGetFirstContact (contactJoint); contact; contact = NewtonContactJointGetNextContact (contactJoint, contact)) {
//		NewtonMaterial* const material = NewtonContactGetMaterial (contact);
//		NewtonMaterialSetContactFrictionCoef (material, 1.0f, 1.0f, 0);
//		NewtonMaterialSetContactFrictionCoef (material, 1.0f, 1.0f, 1);
//	}
	dNewtonContactMaterial contactMaterial ((void*)contactJoint);
	world->OnContactProcess (&contactMaterial, timestep, threadIndex);
}
Esempio n. 25
0
	AnimatedPlayerControllerManager(NewtonWorld* const world)
		:dCustomPlayerControllerManager(world)
		, m_player(NULL)
	{
		DemoEntityManager* const scene = (DemoEntityManager*)NewtonWorldGetUserData(GetWorld());

		scene->SetUpdateCameraFunction(UpdateCameraCallback, this);
		scene->Set2DDisplayRenderFunction(RenderPlayerHelp, NULL, this);

		// load the animation sequences.
		GetAnimationSequence("whiteman_idle.ngd");
		GetAnimationSequence("whiteman_walk.ngd");
	}
VALUE MSNewton::CurvySlider::get_points(VALUE self, VALUE v_joint) {
	JointData* joint_data = Util::value_to_joint2(v_joint, JT_CURVY_SLIDER);
	CurvySliderData* cj_data = (CurvySliderData*)joint_data->cj_data;
	WorldData* world_data = (WorldData*)NewtonWorldGetUserData(joint_data->world);
	dMatrix pin_matrix;
	MSNewton::Joint::c_get_pin_matrix(joint_data, pin_matrix);
	VALUE v_points = rb_ary_new();
	for(std::vector<dVector>::iterator it = cj_data->points.begin(); it != cj_data->points.end(); ++it) {
		dVector point = pin_matrix.TransformVector(*it);
		rb_ary_push(v_points, Util::point_to_value(point, world_data->inverse_scale));
	}
	return v_points;
}
void DemoSoundListener::PostUpdate (const NewtonWorld* const world, dFloat timestep)
{
	DemoEntityManager* const scene = (DemoEntityManager*) NewtonWorldGetUserData(world);

	DemoCamera* const camera = scene->GetCamera();
	dMatrix matrix0 (camera->GetCurrentMatrix ());
	dMatrix matrix1 (camera->GetNextMatrix ());
	dVector veloc ((matrix1.m_posit - matrix0.m_posit).Scale (1.0f / timestep));
	//printf ("%f %f %f %f\n", veloc.m_x, veloc.m_y, veloc.m_z, timestepInSecunds);

	UpdateListener (matrix1.m_posit, veloc, matrix0.m_front, matrix0.m_up);
	dSoundManager::Update();
}
Esempio n. 28
0
void dNewtonDynamicBody::InitForceAccumulators()
{
	dFloat mass;
	dFloat Ixx;
	dFloat Iyy;
	dFloat Izz;

	NewtonBodyGetMass(m_body, &mass, &Ixx, &Iyy, &Izz);
	const dNewtonWorld* const world = (dNewtonWorld*)NewtonWorldGetUserData(NewtonBodyGetWorld(m_body));

	m_externalForce = world->GetGravity().Scale(mass);
	m_externalTorque = dVector(0.0f);
}
VALUE MSNewton::CurvySlider::get_point_position(VALUE self, VALUE v_joint, VALUE v_point_index) {
	JointData* joint_data = Util::value_to_joint2(v_joint, JT_CURVY_SLIDER);
	CurvySliderData* cj_data = (CurvySliderData*)joint_data->cj_data;
	WorldData* world_data = (WorldData*)NewtonWorldGetUserData(joint_data->world);
	unsigned int point_index = Util::value_to_uint(v_point_index);
	if (point_index < cj_data->points.size()) {
		dMatrix pin_matrix;
		MSNewton::Joint::c_get_pin_matrix(joint_data, pin_matrix);
		dVector point = pin_matrix.TransformVector(cj_data->points[point_index]);
		return Util::point_to_value(point, world_data->inverse_scale);
	}
	else
		return Qnil;
}
Esempio n. 30
0
    virtual void PreUpdate (dFloat timestep)
    {
        (void)timestep;

        NewtonWorld* const world = GetWorld();
        DemoEntityManager* const scene = (DemoEntityManager*) NewtonWorldGetUserData(world);
        NewtonDemos* const mainWindow = scene->GetRootWindow();
        DemoCamera* const camera = scene->GetCamera();

        m_helpKey.UpdatePushButton (mainWindow, 'H');
        if (m_selectShape.UpdateTriggerButton (mainWindow, ' ')) {
            m_stupidLevel->ChangeCastingShape();
        }

        bool buttonState = mainWindow->GetMouseKeyState(1);
        if (buttonState) {
            int mouseX;
            int mouseY;

            buttonState = false;
            mainWindow->GetMousePosition (mouseX, mouseY);

            float x = dFloat (mouseX);
            float y = dFloat (mouseY);
            dVector p0 (camera->ScreenToWorld(dVector (x, y, 0.0f, 0.0f)));
            dVector p1 (camera->ScreenToWorld(dVector (x, y, 1.0f, 0.0f)));

            //p0 = dVector (-11.531384, 6.897866, -2.453451, 1.0f);
            //p1 = dVector (1720.189697, -1245.047241, 58.625248, 1.0f);

            // do the convex cast here
            dMatrix matrix (dGetIdentityMatrix());
            matrix.m_posit = p0;


            dFloat param = 1.2f;
            NewtonCollision* const shape = m_stupidLevel->GetCurrentShape();
            //int count = NewtonWorldConvexCast (world, &matrix[0][0], &p1[0], shape, ConvexCastCallBack::Filter, &filter, ConvexCastCallBack::Prefilter, &filter.m_contacts[0], 4, 0);
            NewtonWorldConvexCast (world, &matrix[0][0], &p1[0], shape, &param, NULL, Prefilter, NULL, 0, 0);

            //dTrace(("%f, %f, %f\n", p0[0], p0[1], p0[2]));
            //dTrace(("%f, %f, %f\n", p1[0], p1[1], p1[2]));

            if (param < 1.0f) {
                matrix.m_posit += (p1 - matrix.m_posit).Scale (param);
                m_stupidLevel->SetCastEntityMatrix (scene, matrix);
            }
            m_stupidLevel->SetCastingLine (p0, p1);
        }
    }