Circular sprite mask with CLEO+
Enviado: 07 Nov 2020, 19:04
Português: f16-utilidades/t5397-mascara-de-sprite- ... r-com-cleo
Unlimited, independent, support for aspect ratio correction, can be drawn at different moments of the game rendering etc.
But something that stands out is the use of masks: You can use tristrip (triangle strip) to create a sprite mask.
Here, you have an example of how to draw circles using a sprite mask (in this example, we don't include textures, but can be included).

Use in Myths Maker:

The function allocates a tristrip array in the form of a circle. You can also choose the number of elements, to create more perfect circles, or hexagons etc.
Note that in the example I allocate and deallocate each frame, for better demonstration and to always update the number of elements/segments. You can allocate only once and reuse as needed.
Note that it is expected that you will not understand all of the code below, as it is relatively advanced, what matters is that you understand the basics of how to use it.
gta3script
Function:
Complete example (version for predefined quantity):
Complete example (version for modular quantity):
DRAW_TEXTURE_PLUS
from CLEO+ is very interesting:Unlimited, independent, support for aspect ratio correction, can be drawn at different moments of the game rendering etc.
But something that stands out is the use of masks: You can use tristrip (triangle strip) to create a sprite mask.
Here, you have an example of how to draw circles using a sprite mask (in this example, we don't include textures, but can be included).

Use in Myths Maker:

The function allocates a tristrip array in the form of a circle. You can also choose the number of elements, to create more perfect circles, or hexagons etc.
Note that in the example I allocate and deallocate each frame, for better demonstration and to always update the number of elements/segments. You can allocate only once and reuse as needed.
Note that it is expected that you will not understand all of the code below, as it is relatively advanced, what matters is that you understand the basics of how to use it.
gta3script
Function:
Código: Selecionar tudo
{
LVAR_FLOAT x y radius // In
LVAR_INT verts outer // In
LVAR_FLOAT angle angleStep f offsetX offsetY lastOffsetX lastOffsetY
LVAR_INT i j currentVert allocSize array arrayOffset
AllocCircularMask:
allocSize = verts * 8
ALLOCATE_MEMORY allocSize array
radius /= 2.0
f =# verts
f /= 2.0
angleStep = 360.0 / f
WHILE i < verts
IF j = 2
j = 0
IF outer = TRUE
offsetX = 0.0
offsetY = 0.0
ELSE
IF lastOffsetX < 0.0
offsetX = radius * -1.0
ELSE
offsetX = radius
ENDIF
IF lastOffsetY < 0.0
offsetY = radius * -1.0
ELSE
offsetY = radius
ENDIF
ENDIF
ELSE
//easiest way to create a circle, you can dot it by COS and SIN but just let C++ do this for you
GET_COORD_FROM_ANGLED_DISTANCE 0.0 0.0 angle radius (offsetX offsetY)
angle += angleStep
currentVert++
GET_FIXED_XY_ASPECT_RATIO offsetX offsetY (offsetX offsetY)
lastOffsetX = offsetX
lastOffsetY = offsetY
ENDIF
offsetX += x
offsetY += y
WRITE_STRUCT_OFFSET_MULTI array arrayOffset 2 4 offsetX offsetY
arrayOffset += 8
i++
j++
ENDWHILE
CLEO_RETURN 0 (verts array)
}
Complete example (version for predefined quantity):
Código: Selecionar tudo
SCRIPT_START
{
LVAR_INT j iElements pMaskTriArrayArray[2] iCount
LVAR_FLOAT x y z fRadius fDepth
iElements = 24
WHILE TRUE
WAIT 0
IF IS_KEY_JUST_PRESSED VK_KEY_Y
iElements += 2
CLAMP_INT iElements 10 128 (iElements)
ENDIF
IF IS_KEY_JUST_PRESSED VK_KEY_N
iElements -= 2
CLAMP_INT iElements 10 128 (iElements)
ENDIF
PRINT_FORMATTED_NOW "Elements: %i (Y/N)" 1000 iElements
// Free old allocated memory for masks
IF iCount > 0
j = 0
WHILE j < iCount
FREE_MEMORY pMaskTriArrayArray[j]
++j
ENDWHILE
ENDIF
iCount = 0
// Alloc, create a circular mask and draw it
x = 320.0
y = 244.0
fRadius = 30.0
CLEO_CALL AllocCircularMask 0 (x y fRadius iElements 0)(iCount pMaskTriArrayArray[iCount])
DRAW_TEXTURE_PLUS 0 DRAW_EVENT_AFTER_HUD x y fRadius fRadius 0.0 0.0 TRUE iCount pMaskTriArrayArray[iCount] 255 255 0 180
++iCount
// ANOTHER: Alloc, create a circular mask and draw it
x = 400.0
y = 280.0
fRadius = 30.0
CLEO_CALL AllocCircularMask 0 (x y fRadius iElements 0)(iCount pMaskTriArrayArray[iCount])
DRAW_TEXTURE_PLUS 0 DRAW_EVENT_AFTER_HUD x y fRadius fRadius 0.0 0.1 TRUE iCount pMaskTriArrayArray[iCount] 255 0 0 180
++iCount
// we need to free allocated memory (pMaskTriArrayArray) on next frame
ENDWHILE
}
SCRIPT_END
... AllocCircularMask function here ...[/i]
Complete example (version for modular quantity):
Código: Selecionar tudo
SCRIPT_START
{
LVAR_INT i j k iElements lMasks pMaskTriArray iCount iDepthRandomSeed
LVAR_FLOAT x y z fRadius fDepth
CREATE_LIST DATATYPE_INT lMasks
iElements = 24
WHILE TRUE
WAIT 0
IF IS_KEY_JUST_PRESSED VK_KEY_Y
iElements += 2
CLAMP_INT iElements 10 128 (iElements)
ENDIF
IF IS_KEY_JUST_PRESSED VK_KEY_N
iElements -= 2
CLAMP_INT iElements 10 128 (iElements)
ENDIF
PRINT_FORMATTED_NOW "Elements: %i (Y/N)" 1000 iElements
// Free old allocated memory for masks
GET_LIST_SIZE lMasks (iCount)
IF iCount > 0
i = 0
WHILE i < iCount
GET_LIST_VALUE_BY_INDEX lMasks i (pMaskTriArray)
FREE_MEMORY pMaskTriArray
i++
ENDWHILE
ENDIF
RESET_LIST lMasks
// To avoid intersecting masks. You may don't need this.
iDepthRandomSeed = 654321
// Alloc, create a circular mask and draw it
x = 320.0
y = 244.0
fRadius = 30.0
CLEO_CALL AllocCircularMask 0 (x y fRadius iElements 0)(iCount pMaskTriArray)
GENERATE_RANDOM_FLOAT_IN_RANGE_WITH_SEED iDepthRandomSeed 0.0 0.9 (fDepth)
DRAW_TEXTURE_PLUS 0 DRAW_EVENT_AFTER_HUD x y fRadius fRadius 0.0 fDepth TRUE iCount pMaskTriArray 255 255 0 180
iDepthRandomSeed += 123456
// You can't free memory now because the game will draw the circles yet, so, store the circle in a list and next frame you free it using FREE_MEMORY
LIST_ADD lMasks i
// ANOTHER: Alloc, create a circular mask and draw it
x = 400.0
y = 280.0
fRadius = 30.0
CLEO_CALL AllocCircularMask 0 (x y fRadius iElements 0)(iCount pMaskTriArray)
GENERATE_RANDOM_FLOAT_IN_RANGE_WITH_SEED iDepthRandomSeed 0.0 0.9 (fDepth)
DRAW_TEXTURE_PLUS 0 DRAW_EVENT_AFTER_HUD x y fRadius fRadius 0.0 fDepth TRUE iCount pMaskTriArray 255 0 0 180
iDepthRandomSeed += 123456
LIST_ADD lMasks i
ENDWHILE
}
SCRIPT_END
... AllocCircularMask function here ...