distance from a mesh

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

distance from a mesh

Postby blackbird_dream » Wed Oct 18, 2017 9:00 am

Hello,
How can I get the distance of a body (newton body) from a mesh (not convex) ?
I'd like to display the value in a unity app. The script appreciated.
Thks very much in advance
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: distance from a mesh

Postby Julio Jerez » Wed Oct 18, 2017 2:56 pm

I believe this does it.
Code: Select all
   int NewtonCollisionClosestPoint (const NewtonWorld* const newtonWorld,
      const NewtonCollision* const collisionA, const dFloat* const matrixA,
      const NewtonCollision* const collisionB, const dFloat* const matrixB,
      dFloat* const contactA, dFloat* const contactB, dFloat* const normalAB, int threadIndex);
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: distance from a mesh

Postby blackbird_dream » Thu Oct 19, 2017 3:37 am

thks a lot .
I'll give it a try
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: distance from a mesh

Postby blackbird_dream » Fri Oct 20, 2017 7:33 am

I'm stuck with it. I don't know where to find help to write this script. The 20 demos seem not to be of any support.

Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class tire : NewtonBodyScript
{
    private float dist;

    void Start()
    {
        body = GetComponent<NewtonBody>();
        floor = GameObject.Find("Floor").GetComponent<NewtonBody>();
    }

    override public void OnApplyForceAndTorque(float timestep)
    {
 
        dist = ?

retrieve the closest point between floor and body (NewtonCollisionClosestPoint();)
it seems the function is not implemented in the plugin and raycast neither. Julio you wrote somewhere in this forum you planned to do it, am I wrong ?
Code: Select all
         Debug.Log("distance is " + dist);
    }
    NewtonBody body = null;
    NewtonBody floor = null;
}
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: distance from a mesh

Postby blackbird_dream » Tue Oct 24, 2017 2:12 am

or maybe I can use the raycast function of the physic engine of unity instead, there might be one?
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: distance from a mesh

Postby Julio Jerez » Tue Oct 24, 2017 11:15 am

I see If I can add a new demo that use ray and convex cast.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: distance from a mesh

Postby blackbird_dream » Tue Oct 24, 2017 11:25 am

thks . That means the function already exists in the plugin ?
I know how to handle it in a C++ app but I did not find the function in Unity.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: distance from a mesh

Postby Julio Jerez » Tue Oct 24, 2017 1:50 pm

no I do not think that familly of functions is converted,
I said I will make a demo because the picking object functionality needs a ray cast implemented.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: distance from a mesh

Postby blackbird_dream » Thu Oct 26, 2017 10:07 am

I understand you will implement it for use in your demo.
Can't wait to get the demo and the new facilities.
Thks
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: distance from a mesh

Postby blackbird_dream » Fri Oct 27, 2017 9:08 am

I managed to get a working raycast from the genuine Unity Raycast :
Code: Select all
     
Vector3 n;
float d;
if (Physics.Raycast(center,direction, out hit))
{
  d=hit.distance;
  n=hit.normal;
}
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 15 guests

cron