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 / [SOLVED] How to know which object is in the dead center of the screen?

Author
Message
Devil Master
20
Years of Service
User Offline
Joined: 16th Jul 2003
Location:
Posted: 8th Apr 2020 22:50
I've recently resumed my work on an old DarkBasic project of mine, for which I need to know, moment by moment, which object in the game world, or which point in the matrix terrain, I'm centering my gaze (meaning the camera) on.
I have thought of a possible procedure to do so, but I'd like to know if there is a better way:


As you can see, with this method I have to slowly move a "probe" object, and for every step in the loop, I have to check the distance between it and every other existing object. I feel it's clunky, so I need to ask: is there a more optimized way to achieve the same result?

The author of this post has marked a post as an answer.

Go to answer

Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 9th Apr 2020 05:52
Perform Checklist for OnScreen Objects 0
^ This is your new Best Friend of a Function ^
It's not amazingly "Fast" per se, but it'll be quicker than performing the same in DBP itself (and if you want to know by how much, I have an on-going thread in the AppGameKit Studio Forum showcasing the performance gulf between AGK-S, DBP and C++)

This will dramatically reduce the overall Object List... the Results of which are output to the Checklist Functions.
You can actually dramatically increase this by Decreasing the Size of the Camera View (Set Camera View Left, Top, Right, Bottom) to being as small as you feel comfortable with.
So if for example you set it to say:

ScreenWidth = Int( Screen Width( ) * 0.5 )
ScreenHeight = Int( Screen Height( ) * 0.5 )
Set Camera View OffscreenCamID, ScreenWidth - 4, ScreenHeight - 4, ScreenWidth + 4, ScreenHeight + 4
Set Current Camera OffscreenCamID

Then perform the Checklist ... you'll have far fewer Objects to Compare.
Now you will typically have more than 1 Object that will be "Dead Centre" ... so you'll still need compare their World Positions against where the Camera is looking at in the World., but doing this on say half a dozen Objects as opposed to thousands or tens of thousands; is going to be much quicker.

Remember performance optimisation typically will stem from Culling needless Calculations from occurring.
Devil Master
20
Years of Service
User Offline
Joined: 16th Jul 2003
Location:
Posted: 9th Apr 2020 13:09 Edited at: 9th Apr 2020 13:10
Wow, I didn't know about that command, so I googled it and found this thread: https://forum.thegamecreators.com/thread/137250
Now I realize I didn't know about the existence of the .dbo format either, so how do I convert my models from .x to .dbo?
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 11th Apr 2020 23:05
This post has been marked by the post author as the answer.
I am wondering if there is a more practical way to handle this issue, with some organization.

OBJECT SCREEN X
OBJECT SCREEN Y

These commands claim to provide screen coordinates of objects on screen. No doubt they get weird if the object is not on screen.
However if you only have a handful of target objects, where is the sense of checking every object loaded? Why not just run checks on potential targets.

So eliminate the objects outside your field of view. Easiest way is to store all of your player objects angles, use the POINT OBJECT command to point it at the target, then compare those angles with original to determine if they are larger than FOV, then put the player object back.
Then you maybe have a few on screen possible targets, so compare each on screen coordinates to see which has the closest to center coordinates, then if the closest object is within a minimum distance, voila that object is the one targeted.

Mage's Modular Code - Get awesome UI controls and powerful Bitmap Fonts!
Screen Device Recovery - Stop your apps from crashing when minimized/tabbed/screen locked.
CPU Friendly Frame Limiter - Make your app generate less computer heat + noise, and use less battery life!
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 12th Apr 2020 06:36
Quote: "Now I realize I didn't know about the existence of the .dbo format either, so how do I convert my models from .x to .dbo?"


Use the Save Object command... it supports .3ds, .obj, .x and .dbo
But as a word of warning., ONLY Dark Basic Pro supports the DarkBasic Object (.dbo) Format.

Quote: "These commands claim to provide screen coordinates of objects on screen. No doubt they get weird if the object is not on screen."


I've never known them to "get weird"... either the Object is between 0, 0 to Screen Width( ), Screen Height( ) or it returns -1 (i.e. Not in Screen Frustum)
This is in-fact quite lightweight functions; as this is calculated as an object is being World-View-Projection Transformed., as DBP automatically occludes any objects not within the Camera View Frustum.
So those objects simply populate -1., those that are; will return their WVP Transposed Coordinates.
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 13th Apr 2020 02:44 Edited at: 13th Apr 2020 02:47
I am remembering back several years now, but if I recall correctly if you use OBJECT SCREEN X or OBJECT SCREEN Y and the object in question is outside of the camera view they will give you erroneous values. I remember thinking at the time the values were valid for a camera looking directly backward, but I cannot be that certain. In any case, eliminating objects not in view might be a good step before using these.

There's a few ways to solve this issue as we've both mentioned two. I am not sure which is best in any particular situation. However my sense tells me that good organization skills, checking one or two "action" objects instead of every asset loaded might be the best approach most of the time. Even if the speed of checking per object were a bit slower, and there's no indication it is.

Built-IN commands can be useful, getting a solution is better than no solution, but some are very generalized and not that efficient. I want to advocate being efficient, squeezing a higher frame rate, etc.

Mage's Modular Code - Get awesome UI controls and powerful Bitmap Fonts!
Screen Device Recovery - Stop your apps from crashing when minimized/tabbed/screen locked.
CPU Friendly Frame Limiter - Make your app generate less computer heat + noise, and use less battery life!
Devil Master
20
Years of Service
User Offline
Joined: 16th Jul 2003
Location:
Posted: 15th Apr 2020 13:39
Quote: "So eliminate the objects outside your field of view. Easiest way is to store all of your player objects angles, use the POINT OBJECT command to point it at the target, then compare those angles with original to determine if they are larger than FOV, then put the player object back.
Then you maybe have a few on screen possible targets, so compare each on screen coordinates to see which has the closest to center coordinates, then if the closest object is within a minimum distance, voila that object is the one targeted."

That's great, I will definitely do that.

Login to post a reply

Server time is: 2024-03-28 19:18:20
Your offset time is: 2024-03-28 19:18:20