Page 1 of 1

Mouse Input & Relative Pitch/Yaw

Posted: Tue Jul 09, 2024 9:07 pm
by [object Object]
This is a set of macros and hexes that demonstrate a technique for implementing 2D mouse input in Hex Casting. It works by getting the relative pitch/yaw between the player's current look direction and a known reference direction. Mouse movement in Minecraft directly affects the pitch (y) and yaw (x) of the player's head, so we can effectively reverse-engineer the mouse input based on the angle of the player's head.

This technique was sort of possible before, but it would break if the player looked straight up or down, since it's not possible in that case to find the player's yaw based only on Alidade's Purification. However, the introduction of Theodolite Purification in Hexical 1.3.0 makes this fully possible, as that pattern gives the up vector of the player's head; with that, we have enough information to construct a coordinate space that rotates with the player's head. (This would also be useful for creating HUDs that stay at a constant position in the player's view.)

One interesting use case could be to use this macro along with Mediaworks' Macula and Hexical's Telepathy to implement a working GUI in Hex Casting.

The code for these macros/hexes (and many others) are available on GitHub.

Required mods: MoreIotas, Hexical 1.3.0 (currently unreleased)

Mouse Input
reference look, reference up, current look, current up(x, y) | (null, null)
Given reference and current look/up directions, returns an x/y mouse position relative to the reference position.
The position (0, 0) is at the reference, x increases when yawing right, and y increases when pitching up. The coordinates range from -1 to 1, at -90 and 90 degrees from the reference respectively. If the mouse goes out of bounds in either axis, null is returned for both values.
Required macros: Get Relative Angles
awddeeeeeqaqqwq
Patterns
qqqNumerical Reflection: 4waadadaaBookkeeper's Gambit: Drop 1, Keep 1, Drop 1, Keep 4dwaaqqqqqedeeweNumerical Reflection: -1waqaweawaeNumerical Reflection: 4wdedwddqaawdedwddqddwdedwNumerical Reflection: 22qaawddewaqawNumerical Reflection: 0qddaaeaaqqqBookkeeper's Gambit: Drop 2, Keep 2Bookkeeper's Gambit: Drop 2eeeqwaeawqawdddeaqqeee

Code: Select all

#define Mouse Input (NORTH_WEST awddeeeeeqaqqwq) = vec, vec, vec, vec -> (num, num) | (null, null)
// reference look, reference up, current look, current up -> x, y
// Given reference and current look/up directions, returns an x/y mouse position relative to the reference position.
// The position (0, 0) is at the reference, x increases when yawing right, and y increases when pitching up.
// The coordinates range from -1 to 1, at -90 and 90 degrees from the reference respectively.
// If the mouse goes out of bounds in either axis, null is returned for both values.
{
    // duplicate look vectors to use for bounds check later
    Numerical Reflection: 4
    Dioscuri Gambit II
    Bookkeeper's Gambit: v-v----

    // get scaled coordinates
    Get Relative Angles

    Numerical Reflection: -1  // invert pitch
    Multiplicative Distillation
    
    Circle's Reflection  // tau / 4 = 90 degrees
    Numerical Reflection: 4
    Division Distillation

    Undertaker's Gambit
    Division Distillation
    Rotation Gambit II
    Division Distillation

    // bounds check
    // since we're restricting each axis to +/- 90 degrees, we can just do a dot product test
    Numerical Reflection: 22  // dcba -> abdc
    Swindler's Gambit
    
    Multiplicative Distillation
    Numerical Reflection: 0
    Minimus Distillation
    
    // return null if out of bounds
    Nullary Reflection
    Nullary Reflection
    Rotation Gambit
    {
        Bookkeeper's Gambit: vv--
        Bookkeeper's Gambit: vv
    }
    Flock's Disintegration
    Augur's Exaltation
    Hermes' Gambit
}
Get Relative Angles
reference look, reference up, current look, current upyaw, pitch
Given reference and current look/up directions, returns the current yaw and pitch relative to the reference.
All inputs should be unit vectors, and the returned values are in radians. Yaw increases right, and pitch increases down.
To get the pitch/yaw from the F3 screen, use (0, 0, 1) and (0, 1, 0) as the reference look and up vectors respectively.
Required macros: Theta Exaltation
dwaaqqqqqedeewe
Patterns
qqqNumerical Reflection: 4waadadaaBookkeeper's Gambit: Drop 1, Keep 1, Drop 1, Keep 4wdedwddqddwdedwaadaaaaeaaeeeeeqwdwaaqqqqqedaaeaaaaeddqqqqqewaawddawwaeawwawawddwaawddwaqawawwaeawwaaeaaNumerical Reflection: 4ddadaawdddwaaqqqqqedeee

Code: Select all

#define Get Relative Angles (NORTH_EAST dwaaqqqqqedeewe) = vec, vec, vec, vec -> num, num
// reference look, reference up, current look, current up -> yaw, pitch
// Given reference and current look/up directions, returns the current yaw and pitch relative to the reference.
// All inputs should be unit vectors, and the returned values are in radians.
// Yaw increases right, and pitch increases down.
{
    // right vectors
    Numerical Reflection: 4
    Dioscuri Gambit II
    Bookkeeper's Gambit: v-v----
    Division Distillation
    Rotation Gambit II
    Division Distillation
    
    // yaw (angle between current right and reference right)
    Gemini Decomposition
    Rotation Gambit
    Vector Reflection -Y
    Theta Exaltation
    
    // rotate current look about y axis to cancel out yaw
    // note: yaw is positive clockwise, but rotations are positive counterclockwise
    // so we don't need to negate the pitch for this
    Rotation Gambit
    Prospector's Gambit
    Vector Reflection +Y
    Jester's Gambit
    Rotation Distillation
    Jester's Gambit
    Multiplication Distillation: Matrix

    // pitch (angle between rotated current look and reference look)
    Rotation Gambit
    Numerical Reflection: 4
    Fisherman's Gambit
    Jester's Gambit
    Theta Exaltation
}
Genie Lamp Demo: Absolute Input
Demo video
Patterns
qqqqaqwaqaqwqaaqwddedqwaqqqqqaadaaawqqqqwaeawqBookkeeper's Gambit: Drop 1aadadaawaadadaawNumerical Reflection: 2ewdqdweqwddedqedeeeeeeeeaaqwqaaaawddawdddeaqqaaeddNumerical Reflection: 2waqawqaqaawaaweqqqqaNumerical Reflection: 16qaawddeawddeeeeeqaqqwqaadadaawNumerical Reflection: 2ewdqdweqqqqwaqaaadaadadqqqaqdeeBookkeeper's Gambit: Keep 1eeeqwaeawqawdddeaqqqwddedqwaqqqqqqwaeawqaadadaawwdedwNumerical Reflection: 56qaawddewaqawddqddwaqawwaawwaawNumerical Reflection: 2waqawqaqaawaaweqqqqaeee

Code: Select all

{
    // get current vectors
    Mind's Reflection
    Alidade's Purification
    Mind's Reflection
    Theodolite Purification

    // get reference vectors, and save them if necessary
    Genie Reflection: Memory
    Gemini Decomposition
    Augur's Purification
    {
        // if truthy
        Flock's Disintegration
        
        // if falsy
        Bookkeeper's Gambit: v
        Dioscuri Gambit
        Dioscuri Gambit
        Numerical Reflection: 2
        Flock's Gambit
        Genie Gambit
    }
    Speaker's Decomposition
    Jester's Gambit
    Augur's Exaltation
    Hermes' Gambit

    // draw particle at reference point
    Prospector's Gambit
    Numerical Reflection: 2
    Multiplicative Distillation
    Mind's Reflection
    Compass' Purification
    Additive Distillation
    Particles
    
    // get mouse pos
    Numerical Reflection: 16
    Swindler's Gambit
    Mouse Input
    
    // print mouse pos
    Dioscuri Gambit
    Numerical Reflection: 2
    Flock's Gambit
    Send Thought

    // continue if out of bounds
    Gemini Decomposition
    Nullary Reflection
    Equality Distillation
    {
        Charon's Gambit
        Bookkeeper's Gambit: -
    }
    Flock's Disintegration
    Augur's Exaltation
    Hermes' Gambit
    
    // draw particle at mouse pos
    Genie Reflection: Memory
    Flock's Disintegration
    Dioscuri Gambit
    Division Distillation
    
    Numerical Reflection: 56  // edcba -> cdbea
    Swindler's Gambit
    
    Multiplicative Distillation
    Rotation Gambit II
    Multiplicative Distillation
    Additive Distillation
    Additive Distillation

    Numerical Reflection: 2
    Multiplicative Distillation

    Mind's Reflection
    Compass' Purification
    Additive Distillation
    Particles
}
Genie Lamp Demo: Relative Input
Demo video
Patterns
qqqqwddedqwaqqqqqaadaaawqqqqwaeawqBookkeeper's Gambit: Drop 1Numerical Reflection: 0Numerical Reflection: 0qaqwaqaqwqaaNumerical Reflection: 4waadadaaNumerical Reflection: 4ewdqdweqwddedqedeeeeeeeeaaqwqaaaawddawdddeaqqaaeddNumerical Reflection: 2waqawqaqaawaaweqqqqaqaqwaqaqwqaaawddeeeeeqaqqwqaadaadadqqqaqdeeBookkeeper's Gambit: Keep 1eeeqwaeawqawdddeaqqNumerical Reflection: 0eqqqqqNumerical Reflection: 0.5waqawaadaawqaqwNumerical Reflection: 1Numerical Reflection: 90wdedweaawddqqqqqawddqeeeeeBookkeeper's Gambit: Drop 1aaeaawaawddqddwaawaawddaadadaawNumerical Reflection: 2ewdqdweqqqqwaqaqwddedqwaqqqqqqwaeawqBookkeeper's Gambit: Drop 2, Keep 2Numerical Reflection: 4waadadaaNumerical Reflection: 4ewdqdweqwddedqedeeeeeaadadaawwdedwNumerical Reflection: 56qaawddewaqawddqddwaqawwaawaawddNumerical Reflection: 2waqawwaawqaqaawaaweqqqqaeee

Code: Select all

{
    // get (and set, if necessary) accumulators and reference vectors
    Genie Reflection: Memory
    Gemini Decomposition
    Augur's Purification
    {
        // if truthy
        Flock's Disintegration
        
        // if falsy
        Bookkeeper's Gambit: v

        Numerical Reflection: 0
        Numerical Reflection: 0

        Mind's Reflection
        Alidade's Purification
        Mind's Reflection
        Theodolite Purification

        Numerical Reflection: 4
        Dioscuri Gambit II
        Numerical Reflection: 4
        Flock's Gambit
        Genie Gambit
    }
    Speaker's Decomposition
    Jester's Gambit
    Augur's Exaltation
    Hermes' Gambit

    // draw particle at reference point
    Prospector's Gambit
    Numerical Reflection: 2
    Multiplicative Distillation
    Mind's Reflection
    Compass' Purification
    Additive Distillation
    Particles

    // get mouse offset
    Mind's Reflection
    Alidade's Purification
    Mind's Reflection
    Theodolite Purification
    Mouse Input

    // continue if out of bounds
    Gemini Decomposition
    Nullary Reflection
    Equality Distillation
    {
        Charon's Gambit
        Bookkeeper's Gambit: -
    }
    Flock's Disintegration
    Augur's Exaltation
    Hermes' Gambit

    // apply sensitivity
    Numerical Reflection: 0
    Vector Exaltation
    Numerical Reflection: 0.5  // sensitivity
    Multiplicative Distillation
    
    // check for dead zone
    Gemini Decomposition
    Length Purification

    Numerical Reflection: 1  // 1 degree from reference
    Numerical Reflection: 90
    Division Distillation
    Maximus Distillation

    Jester's Gambit
    Vector Reflection Zero
    Augur's Exaltation
    Vector Disintegration
    Bookkeeper's Gambit: v

    // add offset to mouse pos
    Rotation Gambit
    Additive Distillation
    Rotation Gambit II
    Additive Distillation
    Jester's Gambit

    // print mouse pos
    Dioscuri Gambit
    Numerical Reflection: 2
    Flock's Gambit
    Send Thought

    // update saved mouse pos
    Genie Reflection: Memory
    Flock's Disintegration
    Bookkeeper's Gambit: vv--
    Numerical Reflection: 4
    Dioscuri Gambit II
    Numerical Reflection: 4
    Flock's Gambit
    Genie Gambit

    // draw particle at mouse pos
    Dioscuri Gambit
    Division Distillation
    
    Numerical Reflection: 56  // edcba -> cdbea
    Swindler's Gambit
    
    Multiplicative Distillation
    Rotation Gambit II
    Multiplicative Distillation
    Additive Distillation

    Jester's Gambit
    Numerical Reflection: 2
    Multiplicative Distillation
    Additive Distillation

    Mind's Reflection
    Compass' Purification
    Additive Distillation
    Particles
}

Macula Mouse Cursor

Posted: Tue Jul 09, 2024 10:26 pm
by [object Object]
This hex is a proof-of-concept for using Mouse Input to draw a mouse cursor on Mediaworks' Macula.

Required macros: Mouse Input, Minimization Distillation

Video demo
Patterns
qqqawawaaaddaddadqqqaqdeedeeeqwaeawqawdddeaqqBookkeeper's Gambit: Drop 1qaqwaqaqwqaaqwddedqwaqqqqqaadaaawqqqqwaeawqBookkeeper's Gambit: Drop 1aadadaawaadadaawNumerical Reflection: 2ewdqdweqwddedqedeeeeeeeeaaqwqaaaawddawdddeaqqNumerical Reflection: 16qaawddeawddeeeeeqaqqwqaadaadadqqqaqdeeBookkeeper's Gambit: Keep 1eeeqwaeawqawdddeaqqNumerical Reflection: -1waqawNumerical Reflection: 0eqqqqqaawawaaqaaNumerical Reflection: 2wdedwwaqawaawawaaNumerical Reflection: 2eqqqqqNumerical Reflection: 2wdedwwaawaadaaNumerical Reflection: -3Numerical Reflection: -5Numerical Reflection: 0eqqqqqwaawqqqBookkeeper's Gambit: Keep 2eeeqwaeawqaaqdwdwdwddaaddweee

Code: Select all

{
    Macula Erasure

    // if the lamp is stopping, don't write anything new to the macula
    Finale Reflection
    {
        Charon's Gambit
        Nullary Reflection
    }
    Flock's Disintegration
    Augur's Exaltation
    Hermes' Gambit
    Bookkeeper's Gambit: v

    // get current look/up vectors
    Mind's Reflection
    Alidade's Purification
    Mind's Reflection
    Theodolite Purification

    // get reference look/up vectors, and save them if necessary
    Genie Reflection: Memory
    Gemini Decomposition
    Augur's Purification
    {
        // if truthy
        Flock's Disintegration
        
        // if falsy
        Bookkeeper's Gambit: v
        Dioscuri Gambit
        Dioscuri Gambit
        Numerical Reflection: 2
        Flock's Gambit
        Genie Gambit
    }
    Speaker's Decomposition
    Jester's Gambit
    Augur's Exaltation
    Hermes' Gambit

    // get mouse pos
    Numerical Reflection: 16
    Swindler's Gambit
    Mouse Input

    // continue if out of bounds
    Gemini Decomposition
    Nullary Reflection
    Equality Distillation
    {
        Charon's Gambit
        Bookkeeper's Gambit: -
    }
    Flock's Disintegration
    Augur's Exaltation
    Hermes' Gambit

    // translate mouse pos to screen space
    Numerical Reflection: -1
    Multiplicative Distillation

    Numerical Reflection: 0
    Vector Exaltation
    
    Macula Gambit
    Minimization Distillation
    Numerical Reflection: 2
    Division Distillation
    Multiplicative Distillation
    
    Macula Gambit
    Numerical Reflection: 2  // ensure cursor is drawn in front of buttons
    Vector Exaltation
    Numerical Reflection: 2
    Division Distillation
    Additive Distillation

    // offset cursor so the center of the x is over the mouse pos
    Gemini Decomposition
    Numerical Reflection: -3
    Numerical Reflection: -5
    Numerical Reflection: 0
    Vector Exaltation
    Additive Distillation

    // draw cursor
    {
        Bookkeeper's Gambit: -- <"x">
    }
    Flock's Disintegration
    Calligrapher's Purification
    Etch Visage
}