Horde3D

Next-Generation Graphics Engine
It is currently 23.11.2024, 04:35

All times are UTC + 1 hour




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: 29.10.2011, 08:53 
Offline

Joined: 29.10.2011, 08:43
Posts: 3
I have a problem using Horde3D for my project:

The distance between a wall and a person in Horde3D scene is needed in my project. So, when I import a 3D model from 3D MAX, can I get this kind of information automatically from the scene node? Namely, can I get the environment information like the positions of walls, obstacles, etc from H3DNode or anything else, so that I can determine the distance between a person and the surrounding environment?
If there is a way, how?

Thank you!


Top
 Profile  
Reply with quote  
PostPosted: 29.10.2011, 22:06 
Offline

Joined: 29.10.2011, 08:43
Posts: 3
To make the question more specific, how to know the minimum distance between two specific scene nodes?


Top
 Profile  
Reply with quote  
PostPosted: 30.10.2011, 09:34 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
The transformation of each of your model nodes is based on the pivot point of the model in your max file. So if you take the transformation of both of your H3D nodes you can calculate the distance easily by calculating the euclidian distance between the translation vectors. If the pivot point is not what you are interested in, you first have to find out what's the distance between your POI and the pivot point. Not sure what you're really trying to do.


Top
 Profile  
Reply with quote  
PostPosted: 30.10.2011, 19:13 
Offline

Joined: 29.10.2011, 08:43
Posts: 3
Volker wrote:
The transformation of each of your model nodes is based on the pivot point of the model in your max file. So if you take the transformation of both of your H3D nodes you can calculate the distance easily by calculating the euclidian distance between the translation vectors. If the pivot point is not what you are interested in, you first have to find out what's the distance between your POI and the pivot point. Not sure what you're really trying to do.


Thank you for replying!

Perhaps I didn't make my problem clear. In the whole program, the basic idea is prevent the crowd of people have collision with the obstacle, as well as with each other. My problem is preventing collision with the obstacle. I need to determine the distance between a specific person and the obstacle like a wall so that I can add a force to the person to make the direction of the person change. But the wall can't just be seen as a point; the leaf node of scene graph, I think, is a single object in my max model. So the wall can be the leaf node, but I can't get more information except for the bounding box of a h3dNode.

Perhaps I can use h3dCastRay to determine whether there is some obstacle in a specific direction and know the distance of it. But I need to know all the environment around the person so that it can be more accurate.


Top
 Profile  
Reply with quote  
PostPosted: 30.10.2011, 23:17 
Offline

Joined: 09.09.2009, 18:58
Posts: 107
You might want to use your physics engine for that sort of thing then. Physics engines are typically more optimized for what you are talking about.


Top
 Profile  
Reply with quote  
PostPosted: 02.11.2011, 00:43 
Offline

Joined: 01.11.2011, 02:23
Posts: 5
Hi sysande,

In this kind of situation it is important to have a system in your program for getting useful information in a simple fashion. While you can run brute-force calculations to find the absolute coordinates of an obstacle compared with your crowd of people, it seems that you'll want them all added to the same parent node (if not the root). I would imagine this as a world node that represents the bounds of your scene (floor and perhaps walls and ceiling), and then you add your crowd entities and obstacles to this node. At this point, your scene becomes far more simple to read data from; all distances and collisions can be checked with the relative translations held in the H3DNode. An added benefit of this is that you can position/rotate/scale the whole world without having to rearrange your crowd environment. If you do need them to have different environments (perhaps checking from a hierarchy of obstacles) then you need to calculate the object's absolute matrix and the absolute matrix of the obstacle you're checking against, so that your values are in the same dimensions.

You can use the h3dGetNodeTransform function to get the transformation data of a H3DNode. With this, you have the Cartesian coordinates of each object you wish to check for collisions. There is also the node's axis-aligned bounding box information via h3dGetNodeAABB if you need, although this is not required for simple distance-checking (you would just need a radius value instead).

Once you have the x/y/z of the entity and the obstacle, you can find the distance with a little help from Pythagoras:
Code:
float px, py, pz;      //entity's x/y/z position
float ox, oy, oz;      //obstacle's x/y/z position
h3dGetNodeTransform(_entityNode, &px, &py, &pz, 0, 0, 0, 0, 0, 0);      //we only need translation data
h3dGetNodeTransform(_obstacleNode, &ox, &oy, &oz, 0, 0, 0, 0, 0, 0);
float dx = px - ox;   //find the difference between the two points
float dy = py - oy;
float dz = pz - oz;
float distSq = (dx*dx + dy*dy + dz*dz);      //gives the squared distance between the two points

This is a verbose way of getting the raw data you need, finding the difference between the two points and then finding that value as a straight line. Of course if the entities are walking on a flat floor then you won't need to include the y values in the calculations. You can of course find the square root of the distSq value, but this is relatively intensive and not required if you just want to check for collisions.

If you want to find when a collision occurs, you can define the radius of each object; then the check is quite simply
Code:
//pRadius = entity's radius
//oRadius = obstacle's radius
if (distSq < pRadius*pRadius + oRadius*oRadius)
{
   //collision occurred
}

Again, you don't need to square the radii if you square-rooted the distance.

The above information assumes perfectly spherical collisions, and accurate collision checking for different kinds of shapes is a very deep topic. For example, you may want to use radial checking as above for your characters but instead have a bounding-box check for collisions with a wall. In this case, it is not the distance that matters but the x/z position in relation to the obstacle. This again assumes a perfectly flat pair of edges, and any differently shaped objects will not collide properly (an axis-aligned bounding box won't behave in the expected manner if the node is rotated). Perhaps the simplest way of checking this would be by finding the point-to-plane distance, which is relatively complicated but is explained nicely here http://mathinsight.org/distance_point_plane.


Top
 Profile  
Reply with quote  
PostPosted: 28.01.2012, 09:47 
Offline

Joined: 09.02.2011, 17:02
Posts: 83
Helloo Sorry to interrupt in your thread but i have a related question,

As you mentioned that we can get the transformation of two entities compare the distances and if it is smaller then specific number we can say
Collision occured but this is the case when you are considering only one obstacle, and its fine and simple. but what will you do when you have to avoid walls
doors and so on.

I personally made a list of obstacles (all walls, doors, tables ad everything) and then I compare the distance of my one entity (e.g Key board controlled) with all that
list and then I avoid collision if i have a obstacle infront. But as it takes long time for all computations for every object so i think it is not feasable, what can be possible
solution to it.
Is there any function in which camera returns us an entity_id, in a specific direction or infront of it because after that we can start to compare the distance to that entity? atleast it will save my computation that i am doing by computing all the object's distances compared to one entity
Thanks
Regards Imran


Last edited by Volker on 28.01.2012, 12:40, edited 1 time in total.
Removed unnecessary full quote


Top
 Profile  
Reply with quote  
PostPosted: 28.01.2012, 12:43 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
h3dCastRay is doing exactly what you requested


Top
 Profile  
Reply with quote  
PostPosted: 28.01.2012, 17:51 
Offline

Joined: 09.02.2011, 17:02
Posts: 83
Volker wrote:
h3dCastRay is doing exactly what you requested



Hello Volker Thank You so much

After reading about h3dcastRay i came to conclusion that this function

DLL int h3dCastRay(H3DNode node, float ox, float oy, float oz, float dx, float dy, float dz, int numNearest )

1. Takes origin points that in my case would be position of Keyboard controlled character, Yes?
1. H3DNode node :: what will be the node in this case. my character ID or what ?
2. Will i have to define direction of ray? if yes ? how can i define direction points ? for pointing it to a head of keyboard controlled agent.
3. numNearest will it return something in it or will i have to fix something?
4. While reading about h3dcastRay I came accross h3dcastrayresults it says that for getting the results of h3dcastray we use h3dcastrayresult function
if yes will it return me the handle to the node which is right infront of me.

can you give a small example how this function will work.
what i understand from it is that i will first call h3dcastray function in which i have to give origin of ray and direction and it will return me nodes that come infront
of it, and for getting nodes i will have to use h3draycastresult funciton.

am i right ?
i shall be thankful to you for this favor


Top
 Profile  
Reply with quote  
PostPosted: 29.01.2012, 20:26 
Offline

Joined: 14.07.2011, 02:18
Posts: 20
http://horde3d.org/docs/html/_api.html#h3dCastRay

The H3DNode is the node whose children you want to cast the ray against (i.g., if you wanted to check every node in the scene you would use the root node). Ray direction and length is defined by dx, dy, and dz and numNearest is how many intersection points you want to be stored.

I'm not sure about this one, but I believe that h3dGetCastRayResult(0, H3DNode* node, float* distance, float* intersection) will return the nearest object.


Top
 Profile  
Reply with quote  
PostPosted: 30.01.2012, 01:19 
Offline

Joined: 09.02.2011, 17:02
Posts: 83
Elnof wrote:
http://horde3d.org/docs/html/_api.html#h3dCastRay

The H3DNode is the node whose children you want to cast the ray against (i.g., if you wanted to check every node in the scene you would use the root node). Ray direction and length is defined by dx, dy, and dz and numNearest is how many intersection points you want to be stored.

I'm not sure about this one, but I believe that h3dGetCastRayResult(0, H3DNode* node, float* distance, float* intersection) will return the nearest object.


Code:
1.  h3dCastRay(H3DRootNode,t1.x,t1.y,t1.z,0,0,0,1);
2.  float distance,intersection;
3.  H3DNode Intersection_Node ;
4.  bool a = h3dGetCastRayResult(0,&Intersection_Node,&distance,&intersection   );


Line 1.
I wrote H3DRootNode // I think it starts from camera because the Id that it returned me in HH3DRootNode was the same as of the camera, do you think it will include every object in the scene starting from camera,

I used t1.x , t1.y , t1.z as transformation of Keyboard Agent as origin of the ray because i want to cast ray from Keyboard agent and calculate if there comes another entity infront of it. is it right ? if yes do you think i must add some value in t1.y so that it considers casting of ray straight from eyes to the object.
I used 0,0,0 for direction dx,dy,dz because i didn't know what value to use for giving the straight direction from Keyboard controlled agent. what value should i use for casting the ray straight from eyes of keyboard controlled agent. ?
In simple words I want find nodes with respect to keyboard controlled agent. and take decisions based on returned distance to it. That is provided to me in h3dgetcastrayresult
In Line 4 : I get value in Intersection_Node as -858993460 I don't know which node's id it is.
In distance variable i get -1.07374e+008
And distance variable has the same value -1.07374e+008

I don't know why it gives me such values ?
Any suggestions about what if i have more then one entity how to view them. is that index in the function h3dgetcastrayresult
which can give me access to other entities also ?


Top
 Profile  
Reply with quote  
PostPosted: 30.01.2012, 01:58 
Offline

Joined: 14.07.2011, 02:18
Posts: 20
The reason you're getting those results is because you cast the ray in no direction and for no distance. You need to do something like this:
Code:
// v1 is a vector that is the same direction as your keyboard agent's eye vector
// and has a magnitude of however far you want to cast the ray.
// Example: <0, 10, 0> will cast the ray 10 units along the Y-Axis
unsigned int num_wanted_results = 10;
h3dCastRay(H3DRootNode, t1.x, t1.y, t1.z, v1.x, v1.y, num_wanted_results);
float distance;
float intersection[3];
for(int i = 0; i < num_wanted_results; i++) {
    if(h3dGetCastRayResult(i, &Intersection_Node, &distance, &intersection)) {
        // Do things with the information;
    }
    else
        break; // No more results
}


Top
 Profile  
Reply with quote  
PostPosted: 03.02.2012, 17:10 
Offline

Joined: 09.02.2011, 17:02
Posts: 83
Thanks Elnof !
This is working perfectly. I am creating a list of obstacles that are in specific range or that are coming into range of keyboard controlled agent.
But there is a problem in it,

Code:
h3dGetCastRayResult(i, &Intersection_Node, &distance, &intersection))


The function returns me an ID of the object in Intersection_Node for example crate or a wall, and when i try to find out the position
of that obstacle from the list of obstacles then it gives me an error and it doesn't return me the position

When I use this function to get ID of the obstacle it works perfectly it returns perfect position.

Code:
GameEngine::entitySceneGraphID(GameEngine::entityWorldID("crate1"));


But when i send my same function for position an id obtained from the function h3dGetCastRayResult(i, &Intersection_Node, &distance, &intersection))
then it gives me exceptions and errors. which means there is a problem in the handle to an ID obtained from the two different functions.
Do you think there is some way or should i convert this id to horde3did or etc etc.
Following is the function from game engine that i use to get position.
Code:
GameEngine::getEntityTransformation(Id);


Based on the distance i will later delete obstacles from my list or if distance is decreasing then i will try taking other decisions


Top
 Profile  
Reply with quote  
PostPosted: 09.02.2012, 01:42 
Offline

Joined: 14.07.2011, 02:18
Posts: 20
imranhabib wrote:
But when i send my same function for position an id obtained from the function h3dGetCastRayResult(i, &Intersection_Node, &distance, &intersection))
then it gives me exceptions and errors. which means there is a problem in the handle to an ID obtained from the two different functions.
Do you think there is some way or should i convert this id to horde3did or etc etc.
Following is the function from game engine that i use to get position.
Code:
GameEngine::getEntityTransformation(Id);


I'm not entirely sure what you're asking here. If your GameEngine id isn't equivalent to the Horde id, then you need to convert them.


Top
 Profile  
Reply with quote  
PostPosted: 09.02.2012, 04:14 
Offline

Joined: 09.02.2011, 17:02
Posts: 83
I just meant that Horde ID and Game Engine ID are different as according to Roland's reply to my post you can find here in second comment by Roland

http://www.horde3d.org/forums/viewtopic.php?f=2&t=1630

Anyways an Id is returned to me in the following function in the parameter Intersection_Node
Code:
h3dGetCastRayResult(i, &Intersection_Node, &distance, &intersection)

but when i am trying to find the transformation against the obtained Id (Intersection_Node which is a handle to an object) i am not returned with transformation
of the object while it gives me an excepetion and doesn't let my program to continue. I don't know why it doesn't allow me to calculate the transformation against
this ID although if i obtain the Id of the same object with the following function

Code:
GameEngine::entitySceneGraphID(GameEngine::entityWorldID("crate1"));


then I am able to obtain the transformation. so i was thinking that there is some problem in the Id that is returned in Intersection_Node in the function
h3dGetCastRayResult() Can you kindly give a solution that i can get the transformation also against the obtained handle in parameter Intersection_Node.
2. is there any way i can get the name also (in this function) to the object whose handle i will obtain in the Intersection_Node


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: Bing [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group