How Are Ship Images Positioned?

Discuss and distribute tools and methods for modding. Moderator - Grognak
Post Reply
Vhati
Posts: 792
Joined: Thu Oct 25, 2012 12:01 pm

How Are Ship Images Positioned?

Post by Vhati »

Could someone explain how a ship's base, cloak, floor, and shield images are laid out?


kestral.xml

Code: Select all

<img x="-71" y="-116" w="677" h="444"/>

kestral.txt

Code: Select all

X_OFFSET
0
Y_OFFSET
2
VERTICAL
0
ELLIPSE
350
220
-30
0

The wiki isn't clear on what each of the x/y offsets are relative to and how the images' bounds affect one another.

The cloak image is always scaled 20 pixels wider and taller than the base image, so presumably it's positioned at baseX-10, baseY-10 to keep their centers lined up?

The floor's position/scale wasn't mentioned at all (Given the 35px sprites, there shouldn't be any floor scaling).

These are described as offsetting the 'entire' ship.
X_OFFSET*35 + HORIZONTAL
Y_OFFSET*35 + VERTICAL

The Kestral's base seems to be centered vertically on the shield image, so what's that y="-116" doing where the wiki says it "Slides the base image"?
User avatar
kartoFlane
Posts: 1488
Joined: Mon Jan 14, 2013 10:20 pm

Re: How Are Ship Images Positioned?

Post by kartoFlane »

From what I worked out while developing Superluminal...

FTL uses positioning system with X axis increasing rightwards, and Y axis increasing downwards:
  • X axis: positive - right, negative - left
  • Y axis: positive - down, negative - up
As a consequence, objects are anchored in their top left corner, ie. object placed at point (0, 0) with size (width, height) will have the other three corners at points (width, 0), (0, height), (width, height).

Ship's origin point - Po
  • FTL has a predetermined, hardcoded common point (separate for player/enemy ships) that serves as origin for further translations.
  • X_OFFSET translates the point by #*35 pixels in X axis
  • Y_OFFSET translates the point by #*35 pixels in Y axis
  • HORIZONTAL translates the point by # pixels, X axis
  • VERTICAL translates the point by # pixels, Y axis
Let's call the resulting point Po
Rooms and doors are then placed relative to Po.


Images' origin point - Pi
  • Ship images use Po as origin for further translations
  • <img>'s x= attribute translates the point by # pixels, X axis
  • <img>'s y= attribute translates the point by # pixels, Y axis
Let's call the resulting point Pi.

Ship image properties:
  • Base, floor, cloak, gibs are all placed at Pi
    [cloak having x - 10, y - 10]
  • <img>'s w= and h= attributes determine the size of base, floor and cloak
    [cloak having width + 20, height + 20]
  • Gibs are further translated from Pi on an individual basis via <gib#> tags' <x> and <y> tags

Shield image origin point - Ps
I explained that not so long ago here, but I guess it's pretty confusing, maybe this image will clear it up:
Image
Red rectangles - rooms
Blue rectangle - bounding rectangle - smallest rect containing all rooms

Ps is placed at the intersection of the bounding rectangle's diagonals. It doesn't have to line up with the room grid (could be in the middle of a room, for example)

Ellipse - shield image and collision perimeter

Code: Select all

ELLIPSE
350   = semi-major axis in elliptical equation - a
220   = semi-minor axis in elliptical equation - b
-30   = x offset
0     = y offset
The ellipse is then calculated using the following equation
Image
Ps,x is the x component of Ps
Ps,y is the y component of Ps

What this basically means, is an ellipse with width = 2*a and height = 2*b, centered at Ps offset by the x and y offset values.

The resulting ellipse is the projectile collision perimiter, defense drone orbit, and shield.
For whatever reason, player ships' shield image is not affected by the ellipse's width and height, only the offset values.
However, enemy ships' shield image is resized to match the ellipse exactly.


...soo yeah, that about covers it, I guess :lol:
Superluminal2 - a ship editor for FTL
Vhati
Posts: 792
Joined: Thu Oct 25, 2012 12:01 pm

Re: How Are Ship Images Positioned?

Post by Vhati »

kartoFlane wrote:Ps is placed at the intersection of the bounding rectangle's diagonals.
The bounding rectangle of the ellipse being double the axes' lengths.

So for the Kestral, centering a 700x440 shield image at (Pi+350-30, Pi+220+0).

And the the y="-116" is shifting Pi - and all the images - upward while leaving the rooms in place?


I'd forgotten about that gap between the room grid and the top edge of the hull. :|
User avatar
kartoFlane
Posts: 1488
Joined: Mon Jan 14, 2013 10:20 pm

Re: How Are Ship Images Positioned?

Post by kartoFlane »

Vhati wrote:So for the Kestral, centering a 700x440 shield image at (Pi+350-30, Pi+220+0).

And the the y="-116" is shifting Pi - and all the images - upward while leaving the rooms in place?
Precisely
Superluminal2 - a ship editor for FTL
Post Reply