• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Snippet ST-Animation a.k.a. UV-Animation (mojo2)

Holzchopf

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jul 31, 2017
Messages
500
This snippet demonstrates the basics of texture coordinate animation.

Cerberus:
Strict

' ST-Animation / UV-Animation
' (in Cerberus X, texture coordinates are called ST)

Import mojo2

Function Main:Int()
    New MyApp
    Return 0
End

Class MyApp Extends App
    Field canvas:Canvas
    ' material (texture and shader)
    Field mat:Material
    ' vertex model and texture data
    ' 4 vertices, 2 coordinates each
    Field verts:Float[4 * 2]
    Field texcs:Float[4 * 2]
    ' primitives (quads, in this case)
    ' 1 quad, 4 coordinates
    Field quads:Int[1 * 4]
    ' texture offset
    Field s0:Float

    Method OnCreate:Int()
        SetUpdateRate(60)
        canvas = New Canvas
        ' material must be loaded via Material.Load to disable texture clamping
        mat = Material.Load("flower.png", Texture.Filter, null)
        ' initialize model data
        ' starting top/left going clockwise, x and y coordinate each
        Local x:Float = 100.0
        Local y:Float = 50.0
        Local w:Float = 256.0
        Local h:Float = 256.0
        verts[00*2+0] = x
        verts[00*2+1] = y
        verts[01*2+0] = x + w
        verts[01*2+1] = y
        verts[02*2+0] = x + w
        verts[02*2+1] = y + h
        verts[03*2+0] = x
        verts[03*2+1] = y + h
        ' init quad
        ' keep in mind to have vertices clockwise arranged in quad
        quads[00*4+0] = 0
        quads[00*4+1] = 1
        quads[00*4+2] = 2
        quads[00*4+3] = 3
        Return 0
    End

    Method OnUpdate:Int()
        ' move texture (the '+1) Mod 1' helps keeping the value in 0..1)
        s0 = (s0 + 0.01 + 1) Mod 1
        Return 0
    End

    Method OnRender:Int()
        ' update tex coords
        ' starting top/left going clockwise, s and t coordinate each
        texcs[00*2+0] = 0.0 - s0
        texcs[00*2+1] = 0.0
        texcs[01*2+0] = 1.0 - s0
        texcs[01*2+1] = 0.0
        texcs[02*2+0] = 1.0 - s0
        texcs[02*2+1] = 1.0
        texcs[03*2+0] = 0.0 - s0
        texcs[03*2+1] = 1.0
        ' draw quad
        canvas.DrawIndexedPrimitives(4, 1, verts, texcs, quads, mat)

        canvas.Flush()
        Return 0
    End
End
 

Attachments

  • flower.png
    flower.png
    78.2 KB · Views: 2,254
Back
Top Bottom