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 / How to Align 3D Plane object to camera view pixel perfect?

Author
Message
LittlePIC
13
Years of Service
User Offline
Joined: 19th Oct 2011
Location:
Posted: 21st Jan 2014 07:09
Hi guys,

Have the need for shaders on some 2D images in T1. With AppGameKit v2 having an unknown release date ( to compile on devices) I need to think out side of the box. Solution would be to use a 3D plane object which is effectively the same. At least in my apps case

My problem is sizing and positioning the 3D plane to fit pixel perfectly in the camera view( ie device window). For simulating on a iOS iPhone with resolution of 640 by 960,the object needs to be rotated x approx -10 deg and sized around 11,16.

To make this more accurate I'll need sin,cos and tan.

Can someone assist or provide some direction to this problem?

Many thanks in advance

Regards

LittlePIC
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 21st Jan 2014 09:56 Edited at: 21st Jan 2014 13:30
i would use set rotation of plane same camera,
then move the plane local axis forward, then rotate local

Get3DVectorXFromScreen
Get3DVectorYFromScreen
Get3DVectorZFromScreen

RotateObjectGlobalX
RotateObjectGlobalY
RotateObjectGlobalZ

RotateObjectLocalX
RotateObjectLocalY
RotateObjectLocalZ

MoveObjectLocalX
MoveObjectLocalY
MoveObjectLocalZ

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 21st Jan 2014 10:04
How about using SetObjectLookAt set to the camera coords?

My hovercraft is full of eels
Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 21st Jan 2014 13:08 Edited at: 24th Jan 2014 18:43
I've been trying to do this a while ago, using the commands Markus and lilpissywilly suggested. Alas, I ran into trouble with the 'depth' of the plane I was trying to display. Basically I wanted it set to 0, so other objects wouldn't pass through it. If I find time this evening, I'll post my code. Though I didn't get it working, it might help a bit.

EDIT: here it is.

Jimmanator
14
Years of Service
User Offline
Joined: 12th Nov 2010
Location:
Posted: 21st Jan 2014 18:13
You have to change the agk_ViewProj to agk_Ortho in your vertex shader I have attached an example.

Attachments

Login to view attachments
LittlePIC
13
Years of Service
User Offline
Joined: 19th Oct 2011
Location:
Posted: 22nd Jan 2014 07:09
Thank you everyone for your responses. I'll work through the solution over the next few days.

Have plenty of 'ammo' now to put this puppy to bed

Cheers

LittlePIC
Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 22nd Jan 2014 20:27 Edited at: 22nd Jan 2014 20:39
Good luck! Look forward to any progress you can report! I edited my code slightly, because there was some unneeded stuff in it and it contained spelling errors.
Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 24th Jan 2014 14:00 Edited at: 24th Jan 2014 18:45
I've been experimenting with my original code myself. Here's an update that approaches the needed end-result more. The objects are not influenced by movement of the camera any longer, but hold their relative positions to the screen.

Zwarteziel
13
Years of Service
User Offline
Joined: 22nd Jan 2011
Location: Netherlands
Posted: 26th Jan 2014 11:34 Edited at: 26th Jan 2014 11:51
Third version The code now works as it should (yay) and allows one to place a textured panel at the desired X and Y-coordinates. The panel stays on this position when moving through a 3D-world.

I've read on the forums that the ZDepth of an object cannot be disabled currently, but that it is planned for AGKV2. I haven't had time to check Jimmanator's shader code, but it might be combined with mine to get the desired effect regardless. Also, please note that I'm using the actual width and height of the screen (not the virtual resolution) to set the coordinates. So when you compile this with setup.agc set to 1024x786 but use a different virtual resolution, the points need to be specified with the former in mind. Haven't had time to adjust this.

Login to post a reply

Server time is: 2024-11-25 02:47:08
Your offset time is: 2024-11-25 02:47:08