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.

AppGameKit Classic Chat / 3d to 2d math - I'm stuc

Author
Message
Psycho Psam
16
Years of Service
User Offline
Joined: 3rd Apr 2008
Location: Western Australia
Posted: 28th Dec 2011 05:53
I'm doing a simple 3d shooter and I'm going to render the bad guys to a circle (radar) top left of the screen. As you turn left and right they will turn around the centre.

Their initial position plus player rotation will update their position correctly on the the radar.



The thing I can't figure out is how to take that point and project it into 2d space in front or behind the player as they player rotates. Any idea how to do this? I assume it's probably a 2d to 3d to 2d projection but I'm just wonder if that's too complicated?
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 28th Dec 2011 12:52
Is this in DBP or AppGameKit as you mention this project is in 3D, and AppGameKit doesn't support 3D yet?

My signature is NOT a moderator plaything! Stop changing it!
Psycho Psam
16
Years of Service
User Offline
Joined: 3rd Apr 2008
Location: Western Australia
Posted: 28th Dec 2011 13:44
It's in AGK. So I want to convert 3D coordinates to 2D and scale sprites to look 3D, but their are just 2D.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Dec 2011 16:04 Edited at: 28th Dec 2011 16:17
You already have 2d coordinates if you have it in 3d surely? Just take you x and z and use them as x and y?

Edit: didn't read your post... Try something like this:

... on my iPod so can't test it right now but it shouldn't be far off!

Psycho Psam
16
Years of Service
User Offline
Joined: 3rd Apr 2008
Location: Western Australia
Posted: 28th Dec 2011 16:35
cool that will place them on the radar - not what I'm asking but I needed a solution for that anyway - so thanks for that. I'm assuming it takes the distance vector from the player to the enemy, normalises the vector (sqrt bit) then gets the angle to the player using atan. After that it looks like it's rotating the position of the enemy's blip around the player based on that angle.

What I need is a way to tell if they are in front of the player, and if so where on the screen they will be.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Dec 2011 18:41
Oh I see... You're making something that looks 3d but is really 2d...

Well you can scale the sprite based on distance (D# in my code) but I am guessing you'll need to use a calculation based on your field of view. For example you can check the enemy is within say 30 degrees of you player angle and if so scale his sprite according to d and then position him on screen based on the difference between the angle to the enemy and the angle of the player...

I started a remake of my zombie shooter using a far simpler method but my PC is in bits at the moment otherwise I would send you the code.

MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 29th Dec 2011 02:46 Edited at: 29th Dec 2011 02:50
Why not use pointers around the screen instead of a radar?


Baxslash... your pc dead?... I can set you up with a virtual pc for now if it helps and you can use something like splashtop to connect to it on your mobile device if you do not have a desktop to utilise for now... more than welcome. else if your ok for now no worries

EDIT

Just saying so you can use your mobile device to connect to it and utilise DBP or AppGameKit and test out any code as you need of course you will have to use your own licences and all but I will just delete the VR machine once your done with it I only have a Vista licence lying around to utilise. full disks and ultimate upgrade

Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 29th Dec 2011 08:16
Check out Cliff's wolfenstein code in the announcements board. It's a full 3d raycaster engine like doom/wolfenstein and is fully open source. It could help you as it already does exactly what you want and is almost complete!

My signature is NOT a moderator plaything! Stop changing it!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 29th Dec 2011 09:18
I didn't realise that was open source but yes that might do exactly what you're after.

Thanks for the offer but my PC is not dead just I'm tiling through my office area over next few days...

MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 29th Dec 2011 09:31
no worries... wooo tiles?

Psycho Psam
16
Years of Service
User Offline
Joined: 3rd Apr 2008
Location: Western Australia
Posted: 29th Dec 2011 17:29 Edited at: 29th Dec 2011 17:30
@baxslash - your code is working wonders. The space ships look a bit weird when getting up close but if the player hasn't blasted them by then, they would have blasted the player.

Here's a screenie...

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 29th Dec 2011 18:59
Great! Glad to help

Login to post a reply

Server time is: 2024-11-22 20:27:48
Your offset time is: 2024-11-22 20:27:48