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.

Dark GDK / Convert 3D coordinates to screen coordinates

Author
Message
tobi453
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 18th May 2008 21:45
A few minutes ago I wrote a small function that converts 3d coordinates to screen coordinates and returns false if the 3d point is outside the screen:


If the 3d-point is visible, the screen coordinates are saved in ScreenX and ScreenY.

I hope you find it useful.

FINAL VERSION RELEASED!!!!
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 18th May 2008 22:36
Kewl stuff. I'm not into the 3D stuff just yet but maybe someday.

AAR, something like this probably needs to be posted in Code Snippets for the benefit of humanity.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
bobba
16
Years of Service
User Offline
Joined: 10th Apr 2008
Location:
Posted: 19th May 2008 05:36
There is an easy bodge way to convert 3d to 2d coordinates. It’s actually fairly efficient too. If you create an object at the given 3d coordinates you can then use:

dbObjectScreenX : int dbObjectScreenX ( int iObject )
dbObjectScreenY : int dbObjectScreenY ( int iObject )

to get the 2d coordinates, then just delete the object you made. Because the object is deleted before the call to dbsync it is never rendered to screen so will not appear.
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 19th May 2008 09:11
thanks guys this will be really useful.
tobi453
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 19th May 2008 10:41
hi bobba,

you're right. You can do it with dbObjectScreenX and dbObjectScreenY but I don't want to use a object for this.

FINAL VERSION RELEASED!!!!
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 19th May 2008 16:23 Edited at: 19th May 2008 16:24
I rewrote it so you can actually return the values using std::pair. Just access them by using the .first and .second fields.

Untested btw:


Don't you just hate that Zotoaster guy?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 19th May 2008 18:53
Thanx Zotoaster - thats a good sample of templates.. something I honestly have veered away from EVEN THOUGH I KNOW what they do and how useful they are - I NEED to implement those into my Array and Double Linked Classes so they are more flexible without needing type casts.

Now... I added Tobi's code to my library already and have a mental note to examine the dbGetViewMatrix and dbGetProjectionMatrix closer because when I was doing the frustrum code I recall something about at least ONE of them only neededing to be executed if the CameraRange or FOV changes, and you don't want to call it over and over again. I THINK its the Projecttion Matrix.

The point is, I want to check if its more efficient to do this is a two stage process, where the Projection Matrix is begot at startup or when you change the cam stuff .. in the same routine that does this camera setting changing, and then leave the rest of this routine intact to get the "current" answer you're looking for without running something you don't need to each go around.

A cycle here or there is not a big deal - shoot - some of my pixelgrid class could be optimized to run 10 times faster maybe... and same for some of the string functions I have like left$ and Right$ or whatever... but I do recall reading something in Lost in thought's comments about the ... (I think dbProjectionMatrix) being a little heavy... but then again I may have read wrong.

I think this is a brilliant routine. I also think if its used in a loop - possibly a 100+ objects - then it might be worth seeing if the redundant call(s) can be moved.

Just me rambling - I think this is GREAT work - Like I said - the moment I saw that code from you Tobi, I snagged it! LOL IT's GREAT Stuff!

Sephnroth
22
Years of Service
User Offline
Joined: 10th Oct 2002
Location: United Kingdom
Posted: 20th May 2008 00:02
It's the projection matrix. Iro2 does alot of world->screen transformations for bounding boxes, scanners, etc and it really is a sensiable and much faster idea to define some global definitions for those matrix ideas (#define DB_PROECTION_MATRIX 1 for example) and have a function in your main loop called something like UpdateCommonMatrices();

That way all matrices get updated only once a frame and all the functions that use them and would usually update them once /each/ now just refrence the #define. Notciably saves fps.

Again, the projection matrix doesnt even need updating once a frame - just at the start and when you change something like the FoV.

Dragon Tiger Wolf Bald Eagle
16
Years of Service
User Offline
Joined: 5th Feb 2008
Location:
Posted: 26th Jun 2008 02:32
Hey tobi453 can You please E-mail me I have a question and it doesn't relate to this its about your Star Wars game Please Hurry Thanks

The quality of what a man gives without seeking anything in return shows his integrity.
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 26th Jun 2008 04:30
I smell an easy RTS coming up.

Dragon Tiger Wolf Bald Eagle
16
Years of Service
User Offline
Joined: 5th Feb 2008
Location:
Posted: 1st Jul 2008 20:10
Is this


written for Dark GDK or Dark Basic? I need it for Dark GDK To use so A person can click on a small object I am using as a button and have it pressed.

The quality of what a man gives without seeking anything in return shows his integrity.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 1st Jul 2008 20:12
DarkGDK. If you see lots of { and }, it's a C-style language.
Dragon Tiger Wolf Bald Eagle
16
Years of Service
User Offline
Joined: 5th Feb 2008
Location:
Posted: 1st Jul 2008 20:17
K good I have used C++ for a long time but never really used basic. Don't know how similar they are. Any way shouldn't I be able to take that and ajust it to work with a cursor and a 3D object.

The quality of what a man gives without seeking anything in return shows his integrity.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 1st Jul 2008 20:44
converting from darkgdk to dbpro and back isn't to to hard - you just need to know a little about both languages

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 1st Jul 2008 20:50
Yeah. It's usually pretty simple. Though, I do hate all the # and $'s in DBPro.
Dragon Tiger Wolf Bald Eagle
16
Years of Service
User Offline
Joined: 5th Feb 2008
Location:
Posted: 1st Jul 2008 22:36
Hey Does Any one Know Tobia453 I have some questions I wan't to ask that I would rather ask directly to him instead of posting I am sure he would rather that as well. Can some one who is friends with him ask him to E-mail me I am not asking for his E-mail address just ask that he E-mails mine withinmeisthetigerheart@gmail.com Thanks

The quality of what a man gives without seeking anything in return shows his integrity.
Dragon Tiger Wolf Bald Eagle
16
Years of Service
User Offline
Joined: 5th Feb 2008
Location:
Posted: 1st Jul 2008 22:37
Sorry I meant tobi453

The quality of what a man gives without seeking anything in return shows his integrity.
tobi453
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 1st Jul 2008 22:46
hi,

I've sent you an email. sorry I didn't react earlier, but I'm very busy at the moment.

FINAL VERSION RELEASED!!!!

Login to post a reply

Server time is: 2024-11-20 15:24:32
Your offset time is: 2024-11-20 15:24:32