Adam's Lair Forum

game development and casual madness
It is currently 2018/12/14, 06:06

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: 2018/08/30, 20:29 
Novice Member
Novice Member
User avatar

Joined: 2018/08/28, 17:12
Posts: 12
Role: Hobbyist
Hi.

In all game engines and frameworks I've been using in the past, the top left corner of the game window/screen is considered 0,0 in local screen coordinates but in Duality the Transform component consider the middle of the screen to be 0,0 at least when I try position an object at 0,0 it is positioned at the middle of the screen.

I was thinking first, maybe the origin point of the sprite is off or something but then I saw in the samples comes with Duality, the position of the objects is off also in the samples, so it is not my objects, it must be down to the Transform component.

Is this normal for Duality? If it is normal, what would be the best way to compensate?
For example, if I want to set the position of something to be in the top left corner which is normally 0,0 in most engines, in Duality I need to consider that I may allow the user to choose from multiple screen sizes and resolutions so I need to get the width and height of the current screen, divide it by 2 and then make it a negative value. It is obviously too much trouble. Is there a more practical way to do this?

I would appreciate any help.

Thanks.

SOLUTION://
Solved the problem by converting the values 0,0 to "World Space Coordinates" using a method available from the Camera class.

Code:
Camera mainCamera = this.GameObj.ParentScene.FindComponent<Camera>();
this.GameObj.Transform.Pos = mainCamera.GetSpaceCoord(new Vector3(0, 0, 0));


It puts the object right in the top left corner where it belongs :1+:
Wondering why is this not default in the Transform component, I mean in ALL game engines and frameworks I'v been using, 0,0 is ALWAYS the top left corner of the game window/screen.


Top
 Profile  
 
PostPosted: 2018/08/31, 07:26 
Forum Addict
Forum Addict
User avatar

Joined: 2013/09/19, 14:31
Posts: 880
Location: Italy
Role: Hobbyist
That's because you are just not thinking fourth-dimensionally!

Jokes aside, having the origin in the top-left corner makes sense when you are dealing in a strictly-2d engine, and it's a heritage on when there were no graphical modes on a PC and text-based interfaces counted rows and columns at the top-left.
But Duality, like many other engines, it's actually a 3d engine - or 2.5d in our case, since you can actually position your Transforms anywhere in a 3d space, but it only deals with 2d sprites - and this includes the Camera, that can be moved and rotated around. Being this the case, it's actually just a "coincidence" that the origin is in the middle of the screen; it was just decided to have the starting position of the original camera staring down along the Z axis on the origin.

On the other hand, if you don't need the (pseudo)3d features of the engine, you could always set all your Sprites to be rendered in the ScreenOverlay DrawingGroup, and this would make them behave as a standard 2d engine (origin in the top-left corner, and no matter where the Camera is, they are always visible on screen).

Hope it helps :D (oh, and welcome :mrgreen: )

_________________
Come on Duality's Discord channel. We have cookies! :mrgreen:


Top
 Profile  
 
PostPosted: 2018/08/31, 13:20 
Novice Member
Novice Member
User avatar

Joined: 2018/08/28, 17:12
Posts: 12
Role: Hobbyist
Thank you for the explanation. I didn't realized we are dealing with actual 3d space and camera. It makes more sense now. However I do like the natural sense of depth and distance the 3rd dimension provide in my project. I didn't looked in to the rendering groups yet, thanks for mentioning the ScreenOverlay group it is going to be very useful :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group