angered-ghandi / OpenAOE

An open source reimplementation of Age of Empires (1997)
Other
66 stars 6 forks source link

Use a unit's rotation during rendering #27

Closed angered-ghandi closed 8 years ago

angered-ghandi commented 8 years ago

The TransformComponent has a rotation field that is currently populated by the rotation from the loaded scenario file, and presumably this rotation is around the z-axis in radians (that's a guess; I haven't confirmed).

Currently there's a TODO comment to actually use this rotation value when rendering the unit: https://github.com/angered-ghandi/OpenAOE/blob/master/src/ecs/render_system/unit_render_system.rs#L65

Now, examining the graphic data for a simple idle villager:

    GraphicId(285): Graphic {
        id: GraphicId(285),
        name: "Fidget Basic",
        short_name: "f_basic",
        slp_id: SlpFileId(418),
        layer: 20,
        player_color_id: PlayerColorId(-1),
        second_player_color_id: PlayerColorId(-1),
        replay: true,
        coordinates: [
            0,
            0,
            0,
            0
        ],
        sound_group_id: SoundGroupId(-1),
        frame_count: 6,
        angle_count: 8,
        new_speed: 0,
        frame_rate: 1,
        replay_delay: 3,
        sequence_type: 7,
        mirror_mode: 6,
        deltas: [],
        attack_sounds: []
    },

I'm guessing that the mirror_mode, frame_count, and angle_count play a huge role in figuring out which frame has the correct angle.

If you look at SLP 418 in the slp_viewer tool, you can see that the first angle lasts for 6 frames, and then the second angle for another 6, and so on.

The directions appear to be:

0-6:   South
6-12:  South West
12-18: West
18-24: North West
24-30: North

And that's it--the rest of the directions must be mirrored from the others. I'm guessing there are different ways of mirroring, so the mirror_mode probably plays a role here. We'll probably have to visually examine graphics with different mirror modes to figure out how that works.