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 / 3D GUI... why does this code not work???

Author
Message
Suicidal Sledder
20
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 7th Dec 2014 17:37
Hi all,
I am using the function below in an attempt to draw a 3d plane to the 2D coordinates passed to it. Right, Top, Left, and Bottom.





I orginally was trying to calculate the width and height by subtracting the pick vectors but that was producing erratic results.

I started using these "marker" spheres and they are being rendered almost prefectly to the 2d coordinates i passed to the function.


however the plane is not. it is consistantly smaller than required. I am thinking it has something to do with the FOV since if I set the camera FOV to 1 then it renders to the appropriate location and size. but I tried multiplying the width by the reciprocal of the FOV angle thinking maybe it would make up the appropriate difference but it did not.


been toying with this chunk of code for several hours now. anyone with a fresh pair of eyes that may be able to offer some insight would be appreciated

Thanks

Sadly, programming is only a hobby for me right now. As it turns out, driving a 70 ton, 7 million dollar Abrams tank requires less qualification than pecking away at a keyboard. Who'da thunk it?

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Dec 2014 00:58
This snippet might illustrate what your problem is - if I've understood what you're trying to do.

Study it carefully and you should see where you've gone wrong. [Hint: ask yourself what does the help file mean by "The additional Distance parameter indicates how far into the screen the 3D coordinate is to be calculated"?]





Powered by Free Banners
Suicidal Sledder
20
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 8th Dec 2014 04:00
GG,
thanks for your reply.

From the snippet you provided it seems as if you know exactly what I am trying to achieve and how I am trying to achieve it.

After studying the code snippet, I see that although both spheres are the same distance from the camera, they have different z vectors. I am thinking this is caused by the fact that the further from the center of the screen the 2D coordinate is, the lower the z vector.

In other words, the additional distance parameter is "cast" angularly. That is the closer to the edges of the screen, the more the difference is.

if the distance parameter were to be cast straight into the screen without taking the FOV into account then this problem would be non-existent.

Anywhere close to on the right track?

If this is the case then can I account for the difference in z vector based on the 2D distance from the center of the screen?

Thanks a ton

Sadly, programming is only a hobby for me right now. As it turns out, driving a 70 ton, 7 million dollar Abrams tank requires less qualification than pecking away at a keyboard. Who'da thunk it?

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Dec 2014 02:30 Edited at: 9th Dec 2014 02:30
I'm fairly sure the distance is the standard Euclidean distance of the marker objects from the camera - see diagram which hopefully explains what I think is going on.



The best way of doing what you want is to use an orthographic camera which can be approximated by using a standard camera with a small FOV - which is why your experiments worked when you reduced the FOV to 1.

You might be able to use Dmitry's code posted several years ago which produces a perfect orthographic camera in DBPro. I haven't tested it with pick screen but it's definitely worth a try. I've been using it a lot recently for shadow mapping. Works very well. Here's the link to Dmitry's code:

http://forum.thegamecreators.com/?m=forum_view&t=42592&b=6



Powered by Free Banners

Attachments

Login to view attachments
Suicidal Sledder
20
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 15th Dec 2014 01:49 Edited at: 15th Dec 2014 01:50
GG,
thanks a ton for your help, you definitely got me pointed in the right direction...

here's what I have discovered: exactly as you had demonstrated above, the pick screen command used the distance to be a straight line from the camera. I had assumed it was creating a plane perpendicular to the camera. so in other words, I had been under the impression that as the pick screen command used coordinates closer to the edge of the screen, the depth was measured using the center of the screen.

however since the depth uses a straight line distance, it creates a "radius" around the camera the closer to the screen edge the coordinates become.

after several, several, SEVERAL hours of my weekend (and i rather annoyed wife ) I devised a function to make up for the difference using geometry.

In other words, my problem is ALMOST completely solved. the planes are scaled, positioned, and rotated properly, however they appear to jitter a bit in their positions. I am thinking it has something to do with float rounding or casting. But after hours of going over this code, I cant seem to pin it down. Have a look:

(No media)


Please excuse my terrible coding and commenting, im always on short time over the weekends.

Anyone that can eliminate the jitter will be my best friend forever.

P.S. After hitting 1000 gui objects I am still pulling a solid 46-48 FPS on my laptop. It seems that this function is fast enough for complete GUI handling despite the extensive use of SQRT and pick screen. Also, it is easily modified to texture the objects and add other effects like alpha masking. Once i can work out the bugs I will post some final code for everyone

Sadly, programming is only a hobby for me right now. As it turns out, driving a 70 ton, 7 million dollar Abrams tank requires less qualification than pecking away at a keyboard. Who'da thunk it?

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Dec 2014 11:48
I'll take a look as soon as I can - probably tomorrow if no one else fixes it before then.

Just a thought (without looking at any code), if you're positioning things using the mouse then are you sure it's not caused by the mouse itself? I find I get an annoying jitter sometimes because of mouse sensitivity to small vibrations.



Powered by Free Banners
Suicidal Sledder
20
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 16th Dec 2014 05:32
GG,
Thx for your advice, but the problem is not caused by the mouse. Although in the demo above I am using the mouse to position The UI elements above, the jitter seems to only occur when when the camera is being moved or rotated. Not sure of the correlation there. Its a bit confusing.

Sadly, programming is only a hobby for me right now. As it turns out, driving a 70 ton, 7 million dollar Abrams tank requires less qualification than pecking away at a keyboard. Who'da thunk it?

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Dec 2014 12:56 Edited at: 16th Dec 2014 12:56
Just ran your code to check it runs OK and, yes, the jitter is quite clear as you say. Will check the code as soon as I can but must do something else first.



Powered by Free Banners
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Dec 2014 19:23
I've had a look at this and I suspect there's a simpler solution using lock object on. You'll need to experiment with the position values a bit (or, better, do some more maths) but something like this might work. Obviously you'll need to adapt it to your application but I don't see any jitter with this demo.





Powered by Free Banners
Silverman
18
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
Posted: 18th Dec 2014 15:55 Edited at: 18th Dec 2014 15:57
hi,

no jitter in my example, but i don't use pick screen command.


DirectX 9.0c (February 2010)/ DBClassic v1.20
Suicidal Sledder
20
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 19th Dec 2014 05:47
Silverman,
Looking forward to trying out your demo over the weekend. On my way to work now so will check it out tomorrow.

GG,
I strongly considered using the LOCK OBJECT command, but I wanted the gui to be very dynamic so i feel constantly locking and unlocking would be clumsy.

As a side note, does anyone know a good matrix4 tut? I read they were equivalent to DX D3D matrices but couldnt find any good tuts for those either.

Thanks all

Sadly, programming is only a hobby for me right now. As it turns out, driving a 70 ton, 7 million dollar Abrams tank requires less qualification than pecking away at a keyboard. Who'da thunk it?

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 19th Dec 2014 10:48
Quote: "I strongly considered using the LOCK OBJECT command, but I wanted the gui to be very dynamic so i feel constantly locking and unlocking would be clumsy."


It would indeed.

Are your plains always going to be square (as in your demo)? If so, then would a sprite solution be what you want?



Powered by Free Banners
Suicidal Sledder
20
Years of Service
User Offline
Joined: 17th Aug 2004
Location: Tikrit, Iraq
Posted: 23rd Dec 2014 16:29
Hey sorry for the late response...

Silverman, tour cose worked exactly as needed although a bit slower than with the PICK SCREEN command. It is still exactly what I was needing so tyvm. I tweaked the values a bit to fit my needs.

GG, I have been doing sprite based UIs since I started and for 1 wanted to change it up a bit. Also, now that I am beginning to understand the power of shaders, alpha mapping, texture stages, etc I am wanting to keep my graphics as pure 3D as possible. Of course thats not to say there isnt a place for 2D, but it seems as if theres a lot more "polish" that can be added to 3D that cannot be done with 2D.

Thanks all for your help. Ive learned a lot!!

Sadly, programming is only a hobby for me right now. As it turns out, driving a 70 ton, 7 million dollar Abrams tank requires less qualification than pecking away at a keyboard. Who'da thunk it?

Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 23rd Dec 2014 17:59 Edited at: 23rd Dec 2014 19:20
Couldn't you just draw all 3D UI elements to a Othographic camera (doesn't even have to be orthogonal) somewhere and just combine the output with the main camera? This way, you don't have to keep updating the positions of all the UI elements, you have control over how there drawn, they will sit on top of everything and theres so many advantages to do this *WHY THE HELL DIDN'T I THINK OF THIS! I WILL BE BACK!

Edit: I see the Green beat me to it again!

Though I believe this is enough for a orhographic camera:


"Get in the Van!" - Van B
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 24th Dec 2014 15:59 Edited at: 24th Dec 2014 16:02
Well, this was easier than I thought...

Orthographic Camera Method:


Dem Codes:


This is a simple example but it shows how it works well

"Get in the Van!" - Van B

Attachments

Login to view attachments
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 31st Dec 2014 12:26
Quote: "Though I believe this is enough for a orhographic camera:"


Thanks. I missed that. It needs IanM's wonderful Matrix1 plugins of course.



Powered by Free Banners

Login to post a reply

Server time is: 2025-05-11 14:14:51
Your offset time is: 2025-05-11 14:14:51