[3.6] distance between Camera and Object

Software: Away3D 3.x

Tempy111, Sr. Member
Posted: 07 March 2016 10:22 PM   Total Posts: 133

I’m trying to find a way to detect the distance of an object from the Camera so it can be compared with the player to see if the object is blocking the view of the player and should become transparent or not.

Using the cookbook’s section on Detecting whether an object is in front of behind the Camera, I can work out the angle to see if it’s infront of the camera or not BUT I noticed it does not seam to take into account the angle the camera is facing.

As the camera pans around the player, so the player is always in front of it, it’s dotProduct shifts into negative numbers as if it was behind the camera (which is a Hover Camera and is moving via setting the panAngle). I though the getForward line (which is:

_distVect=Matrix3DUtils.getForward(_cam.transform); 

) was dealing with that but it seams it does not. maybe because of the use of the transform property..

so really.. two questions I guess.
1) being that the camera can rotate, Can I detect the distance between the camera and an object

2) Should I replace the transform command with something else in order to take into account a panAngle of a rotating camera to get the correct values when checking an objects angle from the camera?

   

Tempy111, Sr. Member
Posted: 08 March 2016 11:12 AM   Total Posts: 133   [ # 1 ]

Okay.. about the distance, i’m an idiot.. forgot the Vector3d.distance function ^_^ still not sure on the checking in front when camera angle changed

   

Tempy111, Sr. Member
Posted: 10 March 2016 10:12 PM   Total Posts: 133   [ # 2 ]

okay.. work this one out..

right now all the tiles are cubes. each tile is a different cube. this means lot can be on screen at once.. too many objects means slow down.
so the answer is to merge.

BUT that would mean all the world is one mesh, so I can’t the code which detects if a wall tile is in the way of the camera and to make it invisible because I don’t know how (or if it’s even possible) to check just the faces of a mesh more then the other thing. So a bit screwed I think.

   

Avatar
Fabrice Closier, Administrator
Posted: 11 March 2016 11:03 AM   Total Posts: 1265   [ # 3 ]

yes you can, but you need to build some kind of partitioning, where you know within your 3d grid, which voxel is 0 or 1, (1 is a voxel/cube). Search on sparse arrays, bresenham like algos to traverse your grid etc…

   

Tempy111, Sr. Member
Posted: 11 March 2016 11:42 AM   Total Posts: 133   [ # 4 ]

mmm.. since it’s a basic uniform grid (each cube is 150x150x150, keeping track of where in the mesh/object each block is shouldn’t be too hard. Surely a standard 3D array would do the job for keeping track.

Which would leave the question about targeting the faces themselves..

   

Avatar
Fabrice Closier, Administrator
Posted: 11 March 2016 11:53 AM   Total Posts: 1265   [ # 5 ]

you simply need to transform the mesh vertices to world transform. loop over and define a voxel at this location. each voxel declared will hold at least one indice, the indice of the x of a face. so you can on traverse know that a voxel face starts at the x, rest is ++ 8 times to get the full face. You can of course store more face per voxel.

on traverse, you simply check if a voxel exists, and retreive the indices to retreive the face that you could for instance, edit or use for hittests.


note that if your faces are big, they will spread over a series of voxels. You will need some routine to make sure the in between voxels that should hold the same face are not forgotten.

   

Tempy111, Sr. Member
Posted: 11 March 2016 12:44 PM   Total Posts: 133   [ # 6 ]

I didn’t think Voxel’s had a set size so really, since, like I said, the world is 150x150x150 cubes, there shouldn’t really be a problem with larger faces.

Been looking through the API again, the Mesh.faces property would give a list of faces in the mesh, which I think would be as the vectors, so checking which faces are in which area should be easy but I don’t sem to be able to find the way to do anything with that face..

   

Tempy111, Sr. Member
Posted: 11 March 2016 08:11 PM   Total Posts: 133   [ # 7 ]

damn.. now i’m having a problem with the Merger..
I create the cubes on a ObjectContainer3D called ‘CubeMesh’. I have the floor which is a large plane mesh, called ‘ground’.

now using a Merge object:

var Merger:Merge = new Marge(true,false,true);
Merger.apply(ground,CubeMesh);
view.scene.addChild(ground); 

and they aren’t merged.. the ground appears without the CubeMesh layer..
If I add the CubeMesh layer without Merging, it’s fine. but of course, leads to a lot of objects on the scene and lag issues.

   

Tempy111, Sr. Member
Posted: 12 March 2016 10:31 PM   Total Posts: 133   [ # 8 ]

turns out the merge problem is cause I gave the tiles there ownSession and own canvas.. one of them two things was wrong when it comes to merging..

   
   
‹‹ entity number max?

X

Away3D Forum

Member Login

Username

Password

Remember_me



X