Skip to main content
gamedev.net
🔒 Locked

visiblity?

Started by avianRR 2 replies 300+ views
Original Post
avianRR
avianRR
Ok, I posted this question a while ago and didn''t get any answers so I''ll try again. I have a map that contains object data in regions. The region locations and sizes vary with the objects in them. I''m trying to find a way to determine if the viewer is close enough to the region for it to be visible. I know the view location and the 4 corners defining the region. I''ve tried a variety of messages to no avail. If anyone can help me with this I''d be grateful. I''ve illustrated the problem below. Thanks, Rob http://tannara.2y.net/
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Scarab0
Scarab0
Am I correct to say that you're looking for an algorithm to find the distance between a rectangle and a point in 2D?

I'm not sure how to tackle a problem like that. If you'd check the distance between the view location and the 4 corner points and then check the closest distance then it might get flagged as too far away while it isn't because the distance to one edge is smaller than the distance to one corner.

And if you'd calculate the distances to each edge you'd still have to figure out which edge-distance to take.

My guess is that you should determine the distance to an edge and then check if this point is actually on the edge. I hope this picture explains it:


So the distance you're looking for is the smallest distance to an edge that is actually on an edge. These distances can be found with a dotproduct I guess and to check if it's on the edge itself you could use the found distance and the edge's normal.

I hope this made any sense.

Greets, Dirk


Edited by - Scarab0 on January 22, 2001 3:26:58 AM
Dirk =[Scarab]= Gerrits
avianRR
avianRR
After two weeks working on the problem and not being able to figure it out I finally ralized something I did wrong! I had an error in my dot product code! one wrong letter and the results were wrong! I''ve been retrying what I was doing before and I''m getting closer!
This is the idea that I''m working on...
compute the angles between the four vectors from the view location and the points of the region. Then compare the largest of those agenst the angle for one pixel.
So far it seams to be working now that I found that error in the dot product code! I should remember to never assume existing code is flawless!
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
zedzeek
zedzeek
pixelsonscreen = bs.radius / zDistance;
pixelsonscreen = pixelsonscreen.squared
pixelsonscreen *= (screenHeight* screenWidth)

this is approx how many pixels on screen the object will take remeber theres a VERY FINE LINE between 0 and 1 pixels yet mathmatically there is a IMPOSSIBLE FINE LINE between the 2

http://members.xoom.com/myBollux

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.