Can TCastleScene be set with the top left corner as the origin coordinate?

Can TCastleScene be set with the top left corner as the origin coordinate? I used to use the 2D engine with the top left corner as 0,0 for all logic, but now TCastleScene sets Vector3 (0,0,0) in the middle of the screen. Is there any way to set it to the top left corner of the screen

A relation between TCastleScene and end-coordinates on screen is not straightforward. Between screen and scene there is a Camera, which tells how to convert three dimensional coordinates (Vector3) into two-dimensional coordinates on screen. Depending on Camera orientation it may be center of the screen, bottom-left corner of the screen or even completely invisible because located behind the camera.

In the simplest case (e.g. you use 2D camera setup, or 2D game template) you can simply move the camera as much as you like, to correspondingly make Vector3(0,0,0) be converted into a different place on the screen than center. E.g. 2D game template does it this way.

However, note that it’s not so simple. As “what exactly is the lower-left bottom of the screen” depends on screen resolution. So if you really want to have that “perfectly”, you need to adjust it through code in overridden TCastleView.Resize.

I’m almost sure you can rely that 2D set up camera works in “unscaled pixels” in your regular design. I.e. setting something like (I didn’t test it, expect some tweaks necessary):

procedure TMyView.Resize;
begin
  inherited;
  MyCamera.Translation := Vector3(Container.UnscaledWidth / 2, Container.UnscaledHeight / 2, 0);
end;

Thank you, I will study it carefully

Let me offer a different advise:

Reading your question, I think you just want to change MyViewport.Camera.Orthographic.Origin to 0 1.

  • By default this origin is 0.5 0.5, which means that stuff you place at (0,0) lands in the middle of the screen.
  • If you set Origin to 0 1 then stuff you place at (0,0) lands in the left-top corner of the screen.
  • You could also set set Origin to 0 0, then stuff you place at (0,0) lands in the left-bottom corner of the screen.
  • See API docs for details, Castle Game Engine: CastleTransform: Class TCastleOrthographic .

This is unrelated to TCastleScene, that doesn’t really dictate what is placed in what screen corner. Each TCastleScene has its own coordinate system, and the stuff it loads is sometimes loaded “around local 0 0” (depends on what format you load). If you want to change this, it is easiest to set TCastleScene.Translation after loading, to “counter” it, but it seems not what you seek :slight_smile: