Hello Guest

Author Topic: 2.1 perspective camera and anchors issue  (Read 6063 times)

juruhn

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
2.1 perspective camera and anchors issue
« on: July 30, 2013, 04:47:14 pm »
Hi,

Got a setup for a 1080*1920 projector build, using 2dtoolkit 2.1 latest release.
Using the ortho camera with anchors works perfectly, I can easily place spites on pixel values relatively of the screen resolution (handy for hotween animation).
When rebuilding the setup for using a tk2dcamera in perspective settings, I am lost. Anchors have strange x,y,z values and therefor the relative positioning is not working.
I would really want to use a perspective camera to get some nice 3D animations in the project.

Any tips would be welcome.

Cheers,
Juruhn

juruhn

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: 2.1 perspective camera and anchors issue
« Reply #1 on: August 01, 2013, 11:55:33 am »
For anyone who wants to set up something with a perspective cam, this is my solution sofar for having screenwise pixel alignment.

Position a sprite in 3D space, do the 1:1 trick to make it pixelperfect on that depth. Thru script position it at the X,Y screen values using:

var mainCam : Camera;

function ScreenPos2WorldPos ( xP : float, yP : float, zP : float) : Vector3 { // converts the given 2d x,y layout to 3d vector in space on zP
// xP = x position that we want our object to be at in 2D layout
// yP = y position that we want our object to be at in 2D layout
// zP = the desired depth layer / distance from camera
   xP = (xP / PlayerSettings.defaultScreenWidth);
   yP = (yP / PlayerSettings.defaultScreenHeight);
   return mainCam.ViewportToWorldPoint (Vector3 (xP, yP, zP));
}


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: 2.1 perspective camera and anchors issue
« Reply #2 on: August 01, 2013, 03:03:50 pm »
Thats more or less what the tk2dCameraAnchor does - but you obviously can't rely on moving things using "position" - you should rather move using the "Offset" parameter in the anchor. That is in pixels.

I'm considering another workflow, where the anchor will rescale "1:1" automatically for you, depending on depth. Might work better here - any thoughts?

juruhn

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: 2.1 perspective camera and anchors issue
« Reply #3 on: August 08, 2013, 10:35:14 am »
Hi Unikron,

Sounds like a logical solution, scale every child within the cameraAnchor parent 1:1 automaticly when changing the Zdepth of the anchor. You could 'see it' as a Z-layer I suppose.
The real issue is that I seem to have no way to offset a sprite in pixels values from that anchor.

I tried this:

tk2Camera
    Anchor (upper left)
          Sprite (with pivot centered)

The Anchor stays in the upper left when I move it in Zspace. That is good.
The sprite I want to position an N amount of pixels from the 0,0 upper left point. The transform values of the sprite do indeed not correspond with pixels values, but, even when I offset the anchor to lets say the centre (which seems to be 1/4 of the actual width value), then strange repositioning happens when resizing the game view window. So that's no solution either.

For now, recalculation it in script will do for my project, as it is a fixed resolution.
I understand that it is way easier in orthographic mode but it would be nice to have pixel positioning in perspective too. Maybe something for on the wishlist, or I am missing / minunderstanding the toolkit a bit, still figuring it out.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: 2.1 perspective camera and anchors issue
« Reply #4 on: August 08, 2013, 08:58:43 pm »
If you look on the anchor, there should be an offset parameter? That should be in pixels. You will need multiple anchors with different offsets to position things "side by side" but that should still work?