Frustums, bounding boxes and can one object see another

Started by
12 comments, last by Zakwayda 4 years, 6 months ago

I think OP just needs some direction as to how to go about the math itself.

There are a few ways to go about it. Any 3d library that has "cameras" and all that is just using matrices, vertices, points, etc. If you are doing everything in 2d, it's entirely possible to do all of this using Euler X and Y coordinates and trig. It would better to learn some vector math, and use that. The exact same vector math will translate to 3d easily if you go that route.

If nothing else, if Three.js works, look at its source code for the underlying math and logic. Look up 3blue1brown vector math videos. Good search terms would include ray/circle intersection algorithms, 2d vector math tutorials, etc.

No idea if that helps, but my 2c. :)

Advertisement
3 hours ago, Zakwayda said:

Just to be completely clear, is the issue you're facing that you want to perform operations on the server side that Three.js could handle for you, but you don't have Three.js available in that setting and you're not sure how to implement equivalent functionality yourself?

Yeah pretty much this - i went down the route a few weeks ago at looking how i may run three.js server side and realised that was just wrong on so many levels

2 hours ago, Scienthsine said:


There are a few ways to go about it. Any 3d library that has "cameras" and all that is just using matrices, vertices, points, etc. If you are doing everything in 2d, it's entirely possible to do all of this using Euler X and Y coordinates and trig. It would better to learn some vector math, and use that. The exact same vector math will translate to 3d easily if you go that route.

Thanks @Scienthsine really good point - i supposed i assumed there to be some 'magic' in threejs' camera system - i will lookup the videos you mention and also dig about in the threejs source - it is open source so i suppose i can pull the functions for 'insersectObject' (et al) and write them into a different language for server side

 

15 minutes ago, Paul Drage said:

... i supposed i assumed there to be some 'magic' in threejs' camera system - i will lookup the videos you mention and also dig about in the threejs source - it is open source so i suppose i can pull the functions for 'insersectObject' (et al) and write them into a different language for server side

No magic - it's just math, which can be replicated in pretty much any environment as needed. (Not to say it's trivial necessarily - just that is can be done.)

Although I've read the whole thread, I don't remember everything that's been discussed, so I may be repeating some things. But, what you'll need to do obviously depends on some variables, like how the environment is represented and so on.

I gather from your initial post that this is 3-d and that therefore purely 2-d solutions won't suffice. It also sounds like there are two problems you want to solve: being visible or not based on position and orientation (ignoring obstacles), and whether there's an unobstructed line of sight between two entities.

For the first problem, you could do what a typical camera system does, which usually involves a frustum built out of planes. There are other options though, such as a visibility cone or some other ad hoc solution. That's probably the easier of the two problems to solve (determining line of sight can be more demanding). In any case, if you run into problems you can always post back here.

This topic is closed to new replies.

Advertisement