Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / There is the Object In Screen command, but what about Object In Camera View?

Author
Message
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 15th Jun 2013 23:44
The Object In Camera View command is a fantasy it seems; but it would be cool to check if an object is in the frustum of a camera. Does anyone know the mathematical term I need to search for to calculate whether something can see something with a field of view in mind?

My impulse tells me to get the angle vector of the object in question; then get 4 maximum angles for each edge of a squared frustum and see if the angle fits; but you might know a better way; who knows, perhaps a cone could be used as a collision trigger.

James H
19
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 16th Jun 2013 00:57 Edited at: 16th Jun 2013 01:52
Whats the difference? Surely if the object or any part of it is in the screen then its in the view frustum, I always thought the frustum was much like a pyramid on its side where the "cut off top" is situated right at the point of the camera and the "base" of the pyramid furthest from screen at the clipping plane to match the cameras rotation. Lost in thought did produce some code for frustum checking, I`m sure you will find it if you search his profile

edit
I see now, silly of me - it doesn`t check against the clipping plane distance, or is there more to it than this? would distance checking combined with inscreen command not be sufficient or fast enough then?
Burning Feet Man
18
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 16th Jun 2013 01:12
O-er, subscribed to this one! Pyramid & frustum zones sound cool!

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 16th Jun 2013 01:50
The most accurate solution I can think of is projecting the object into screen space, and then testing whether the object is "inside" the screen (same as testing a cube). This code is self explanatory.



TheComet


Yesterday is History, Tomorrow is a Mystery, but Today is a Gift. That is why it is called "present".
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 16th Jun 2013 03:08 Edited at: 16th Jun 2013 03:12
Quote: "I see now, silly of me - it doesn`t check against the clipping plane distance, or is there more to it than this? would distance checking combined with inscreen command not be sufficient or fast enough then? "


What I want to achieve has absolutely nothing to do with the screen; I want to find out if a particular camera can see something without syncing the scene; most cameras in my simulation do not affect the screen.

For example if a camera is used as a CCTV camera to texture a monitor object, I need to check if the CCTV camera can see something. Obviously collision and raycasting could be used, but

Well.. it looks like TheComet has a solution.

For that matter I also need to check if entities can see entities. The first part of the query is to check if the item in question is within the field of view; after this the use of my own portal system and ray casting will come into play.


Quote: "Lost in thought did produce some code for frustum checking, I`m sure you will find it if you search his profile"


Will do

Quote: "The most accurate solution I can think of is projecting the object into screen space, and then testing whether the object is "inside" the screen (same as testing a cube). This code is self explanatory."


Thanks a million Comet; I could use Matrix1 utilities and supply that view matrix call with a camera ID parameter. There is also a Matrix1 command for creating matrices out of vectors, objects and limbs which could come in handy for entities and portals.

I wonder what I should use in place of the screen size functions?

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 16th Jun 2013 12:10 Edited at: 16th Jun 2013 12:10
Quote: "I wonder what I should use in place of the screen size functions?"


In what language are you trying to write this? Or are you looking for a purely mathematical solution? If that's the case, I can run you through the underlying mathematics involved, which will let you do the calculation without knowing the screen size. It will probably let you simplify other things too, because the code above isn't cheap.

TheComet


Yesterday is History, Tomorrow is a Mystery, but Today is a Gift. That is why it is called "present".
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Jun 2013 13:19
I'm sure Lost In Thought posted a snippet a few years ago which does exactly this - with the intention of culling those outside the frustum. If I recall correctly it handles most situations accurately but might need a bit of tweaking.

TheComet's suggestion sounds simpler though - I'll need to look at that.
Silverman
19
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 16th Jun 2013 16:29
hi Chris Tate,

you can calculate the 3D angle between the monitor and each object. Then, if the angle is greater than the angle of the field of vision, the object is not visible.
In the download, there a code made ​​with DBClassic, but I think it should work with DBPro.(But unlike DBPro, in DBC there is not need to set the number of camera)

DirectX 9.0c (February 2010)/ DBClassic v1.20
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 16th Jun 2013 18:03 Edited at: 16th Jun 2013 19:02
Quote: "In what language are you trying to write this? Or are you looking for a purely mathematical solution?"


I am trying to get a number of mechnisms to tell me if an 'eye' can see something. From CCTVs, occlusion culling algorithms to range-of-effect collisions. These will usually be done in DBP, but sometimes my editor will need to do these things in VB.NET.

Quote: "I'm sure Lost In Thought posted a snippet a few years ago which does exactly this"


Yeah, James also stated this, I will look into that, but Silverman's logic sounds like that would be the speediest solution.

Quote: "Then, if the angle is greater than the angle of the field of vision, the object is not visible."


I will try that out after looking at your example; I'd just subtract the camera angle and compare the difference. I imagine that this uses a cone field of vision instead of a frustum; I also need to cancel objects to high or too low to be seen. TheComet's solution sounds more suitable for quad shaped checks.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Jun 2013 21:50
Quote: "Yeah, James also stated this,"


So he did, sorry (missed your comment too - I should have double checked before posting ).

One problem is how to deal with objects whose vertices are all outside the frustum but parts of some polys are inside. Tends to happen with large simple objects like plains and boxes when you get close up. I vaguely recall that kind of situation produced difficulties for LiTs method. Covering all possibilities accurately can be awkward. I guess it's more important to mistakenly think something is visible than the converse.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 16th Jun 2013 22:04
Yeah I have that in mind. The vertices & face will checked for visibility until the first one appears in sight in design-time and run-time checks; at least this is the case for some calculations I have planned.

For others, vertex and face positions will not be easy enough to track in a short space of time when doing runtime checks. Decimation, division or a delegated low poly models could substitute a detailed raw vertex array.

In view of what you mentioned, situations could arise where all vertices and edges are out of sight, but a single face could covering the whole view; its edges are simply out of range.

A raycast check would need to be the next part of the query I think.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 16th Jun 2013 23:00 Edited at: 16th Jun 2013 23:01
Quote: "Then, if the angle is greater than the angle of the field of vision, the object is not visible."


That alone isn't enough. You also have to check near and far clipping. Calculating the distance to the camera is only part of the solution for that, because near and far clipping distances aren't linear.

@ Chris - How many objects and/or vertices in total do you plan on checking?

TheComet


Yesterday is History, Tomorrow is a Mystery, but Today is a Gift. That is why it is called "present".
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 17th Jun 2013 04:00 Edited at: 17th Jun 2013 04:14


Wow, never assume!

Turns out the command is more an object in camera view command than it is object in screen; the name of the function is misleading.

They made the object in screen command subject to the current camera; therefore it is actually a function that checks if a camera can see an object; even if the camera rendering is off.

I just had a quite check to see if this code works, and it does. At least DBP has a simple solution for this.



Quote: "How many objects and/or vertices in total do you plan on checking?"

When making frustum event triggers ; I'll settle for object positions; no verts.

When creating portals; thousands of vertices will be checked during design time.

During the runtime I'd only be checking occlusion boxes in visible portals which will include or exclude models and entities when not seen.

Now that the object in screen command has an additional use, I can use a fake camera along with raycasts to check if dynamic things can see other things.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Jun 2013 13:53
Good news. That's worth knowing.
James H
19
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 17th Jun 2013 19:09
Somewhat narrow minded/ignorant of me to not think of possible purposes for your needs, my apologies

However I feel its worth noting a couple of bugs with inscreen command, the first can be found in following link and appears to be present in latest update still although I never did write a bug report on it, will do so later this week when I have more time;
http://forum.thegamecreators.com/?m=forum_view&t=199063&b=1

The second appears to be fixed in latest update, but in case your using an older one for whatever reason(maybe because other bugs exist elsewhere in dbp that you cant live with for example), so I thought I would highlight it(cannot remember which update I was using - I emailed lee at the time so never bothered with a bug report as he said he would look into it)
The issue could be seen when holding spacekey down and looking left/right 90 degrees; some of the cubes would still be visible in a line that the original camera angle was perpendicular to before the spacekey was pressed, here is code I was using(obviously not worth looking into unless your using 1 of older updates);
Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 18th Jun 2013 12:21 Edited at: 18th Jun 2013 12:30
I have a feature where when the player is walking through the level he can see wall mounted displays showing a camera feed tracking him from cameras placed in the level.

The most important culling I use is portal culling. Then anything remaining is checked by the fustrum culling code.

I just checked and found that I'm having this same problem the other cameras have culling errors. I was moving camera 0 to their position then using the object in screen command. The new camera position isn't being used so it doesn't work.

Unless I see something better i will fix this problem as follows. I'll just do the angle math to find out if the objects are inside the camera view. I'll probably use point camera and compare the horizontal and vertical angles. I'll probably use a point behind the camera and with a slightly increased field of view. This will reduce edge related culling errors. I'll protect anything in a small box radius of the camera from being culled to reduce errors.

Level architecture like walls is unaffected since it is tied to the portal culling. This is why I didn't even notice. Also it's just a graphical effect on a wall fixture so being accurate isn't as important as being fast and cheap.

Edit: I'll use Chris Tate's suggestion involving Set Current Camera if it pans out. Not sure if sync needs to be called to update the camera positions. That would ruin it.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Jun 2013 12:36
Quote: "I'll use Chris Tate's suggestion involving Set Current Camera if it pans out."


That's probably essential if you're trying to read any data related to a specific camera (unless the command in question specifies the camera - and to be safe I'd probably recommend doing it even then).

Login to post a reply

Server time is: 2026-07-11 11:40:25
Your offset time is: 2026-07-11 11:40:25