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 / Centering an object to the screen

Author
Message
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 10th Apr 2003 13:22
Seeing as the X & Y position of an object has no relation to the screen X & Y position - how do you center an object to the screen ? At the moment I position all objects to 0,0, and the camera to the left of that - it works well for most objects. However for some they appear too far up the screen, in which the only way around would be to manually change the camera, so they appear more centered.
Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Neophyte
23
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 10th Apr 2003 23:46
I suppose you could get the x and y pos of the camera and set the objects x y to those or vice versa. I'm not sure if the z depth will be a problem for you but if it is you could always fetch the z of the camera as well. Oh and after you set the coords point the camera to the object with the point camera command. I think that should do it but i'm not sure if it will work. Let me know if it goes well. [b])

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 11th Apr 2003 17:47
I'll try that sometime, see what it does...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Dmitry K
23
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Russia
Posted: 11th Apr 2003 18:28
Try it.



Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 11th Apr 2003 18:42
Toady, use Object Screen X and Object Screen Y to determine the screen coords of an object, then you can use that to position the object accordingly.

@DMiTROS

Can you explain the maths behind the source that you posted? I would find it very useful.

Current Project: Retro Compo. Entry.
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 11th Apr 2003 19:20
Thanks - I'll see if I can try that later.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Dmitry K
23
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Russia
Posted: 12th Apr 2003 08:57
@Rob K
It's simple.
The vector 1 is the coordinates of an object in Camera Space.
Set Vector3 1, 0.0, 0.0, 50.0

By transforming these coordinates on the inverted view matrix, you will get coordinates of an object in World Space(World Coordinates).
View Matrix4 3
r=Inverse Matrix4(3, 3)
Transform Coords Vector3 2, 1, 3

solo
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Israel
Posted: 12th Apr 2003 16:43
MrTAToad,
Here is a snippet i made today for "center an object on screen",
i hope that you find it useful.



[solo]

solo
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Israel
Posted: 12th Apr 2003 22:52
a few things i didn't mention:

The snippet is acting like LOCK OBJECT ON with a different
behaviour when you decide to "UNLOCK" the object:

In the origin UNLOCK OBJECT, the relative-to-camera coordinates become the absolute cooridnates when unlocking.
Here, where you decide in the program to quit the loop, the object remains at the absolute position he was "dropped".

The same math calculations i use to create a "Camera follows an object", if someone needs the code then i post it.

[solo]

If you only need to init an object coordinates to the screen center,
you need no loop, only a single cycle...

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 13th Apr 2003 01:18
Yes, it certainly works well - I'll have to try and put it in my code. Thanks!

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!

Login to post a reply

Server time is: 2026-07-11 12:01:06
Your offset time is: 2026-07-11 12:01:06