g3n / engine

Go 3D Game Engine (http://g3n.rocks)
https://discord.gg/NfaeVr8zDg
BSD 2-Clause "Simplified" License
2.74k stars 292 forks source link

Collision detection angle calculation #261

Closed Semj0n closed 2 years ago

Semj0n commented 2 years ago

Hi,

i'd like to calc an angle of an vector relative to a box. is there a way to split a box into faces (or planes) to check for intersection and by calc the norm vector of the plane beeing able to calc the angle of inclination?

Any documentation available on this?

danaugrs commented 2 years ago

You'd need to do all the intersection calculations manually. Once you instantiate a Box, then you know exactly the sizes and positions of the face planes (they are arguments for the box creation function). What are you trying to accomplish?

Semj0n commented 2 years ago

Hi,

i'd like to use the engine for optical raytracing. For that i need to get the faces of the object and test the triangulated mesh for intersection ...

i tried: box := geometry.NewSegmentedCube(1, 2) box.ReadFaces(func(vA, vB, vC math32.Vector3) bool { for _,r := range new_rays{ var loc *math32.Vector3 found := r.IntersectTriangle(&vA,&vB,&vC,true,loc) if found{ log.Println(vA,vB,vC,loc ) } } return true })

but it just run one... i was expecting to get all vertices?

How to accomplish that ? Best Regards, Semjon

danaugrs commented 2 years ago

You need to return false to continue looping over the faces. Returning true halts the loop.