A New Render Object - Shape

▶︎
all
running...

Introduction

What is a Shape

This is what the name implies. It is a freely definable shape. It resembles a sprite in a way. A sprite is usually rendered only as a quad. A quad usually consists of four vertieces and corresponding UV coordinates, which are usually also squared on an image.
This is where the shape differs from the sprite.

These are the main differences. Most of the commands are similar to Sprite. You also have the possibility to create prefabricated shapes. When you create a prefabricated shape, the corresponding UV coordinates are automatically created.
Here you can see an example of creating a shape.

Agk.CreateShapeTriangle(2, 128, 128);
Agk.SetShapePosition(2, Agk.GetShapeRadius(2), 384);
Agk.SetShapeImage(2, 1);

The result looks like this.
Alt text


Function Reference

Shape Creation

uint CreateShape( )
void CreateShape(uint iShapeIndex)

Creates an empty new shape.This can be used later to fill the shape with vertieces using LoadShapeFromMemblock or LoadShapeFromMemory.

PARAMETER
iShapeIndex The shape ID in which the new shape.
RETURNS
The return value is a new ID for the Shape object.
    float[] custVert = { -112, -122, 130, -64, 105, 120, -100, 85 };
    float[] custColor = { 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0.5f, 0.5f, 0.5f, 1 };
    float[] custUV = { 0, 0, 1, 0, 1, 1, 0, 1 };
    ushort[] custIndicies = { 0, 1, 2, 0, 2, 3 };

    Agk.LoadImage(1, "media/background5.jpg");

    Agk.CreateShape(1);
    Agk.LoadShapeFromMemory(1, 4, custVert, custColor, custUV, 6, custIndicies);
    Agk.SetShapePosition(1, 512, 128);

Alt text


uint CreateShapeTriangle(float iX1, float iY1, float iX2, float iY2, float iX3, float iY3)
uint CreateShapeTriangle(float iWidth, float iHeight)
void CreateShapeTriangle(uint iShapeIndex, float iX1, float iY1, float iX2, float iY2, float iX3, float iY3)
void CreateShapeTriangle(uint iShapeIndex, float iWidth, float iHeight)

Creates a shape with three vertices.

PARAMETER
iShapeIndex The shape ID in which the new shape.
fX1 X coordinate of the first vertex.
fY1 Y coordinate of the first vertex.
fX2 X coordinate of the second vertex.
fY2 Y coordinate of the second vertex.
fX3 X coordinate of the third vertex.
fY3 Y coordinate of the third vertex.
fWidth Triangle width.
fHeight Triangle height.
RETURNS
The return value is a new ID for the Shape object.

uint CreateShapeRectangle(float fWidth, float fHeight)
void CreateShapeRectangle(uint iShapeIndex, float fWidth, float fHeight)

Creates a shape with four corner points.

PARAMETER
iShapeIndex The shape ID in which the new shape.
fWidth Triangle width.
fHeight Triangle height.
RETURNS
The return value is a new ID for the Shape object.
    Agk.CreateShapeRectangle(3, 128, 128);
    Agk.SetShapePosition(3, Agk.GetShapeX(2) + Agk.GetShapeRadius(3) * 2.0f, 384);
    Agk.SetShapeImage(3, 1);
    Agk.SetShapeUVAxis(3, 0.5f, 0.5f);

Alt text


uint CreateShapeStar(float fWidth, float fHeight, float fInner, uint iPikes)
void CreateShapeStar(uint iShapeIndex, float fWidth, float fHeight, float inner, uint pikes)

Creates a star with the total size of width and height. The parameter inner specifies how far the pikes may go inwards.

PARAMETER
iShapeIndex The shape ID in which the new shape.
fWidth Shape width.
fHeight Shape height.
fInner Inner radius of the generated star. It is a percentage value of the whole star. For an inner radius the value should be between 0.0 and 1.0. If the value is greater than one, it is more of an outer radius.
iSpikes Number of spikes to be generated.
RETURNS
The return value is a new ID for the Shape object.
    Agk.CreateShapeStar(5, 128, 128, 0.38f, 6);
    Agk.SetShapePosition(5, Agk.GetShapeX(4) + Agk.GetShapeRadius(5) * 2.0f, 384);

Alt text


uint CreateShapeSymbol(float fWidth, float fHeight, uint iSymbol)
void CreateShapeSymbol(uint iShapeIndex, float fWidth, float fHeight, uint iSymbol)

Creates a symbol as a shape. There are currently 4 different symbols.

PARAMETER
iShapeIndex The shape ID in which the new shape.
fWidth Shape width.
fHeight Shape height.
iSymbol Symbol number 0=Chefron arrow ; 1=Direction arrow ; 2=Notched arrow ; 3=Arrow
RETURNS
The return value is a new ID for the Shape object.
    Agk.CreateShapeSymbol(6, 128, 128, 2);
    Agk.SetShapePosition(6, Agk.GetShapeRadius(6), 484);
    Agk.InkShape(6, 0.5f, 0.7f, 0, 1);
    Agk.MoveShapeAxis(6, 64, 0);

Alt text


uint CreateShapePolygon(float fWidth, float fHeight, uint iEdges)
void CreateShapePolygon(uint iShapeIndex, float fWidth, float fHeight, uint iEdges)

Creates a polygon with the specified number of edges. The created points are generated in a circle around the center point.

PARAMETER
iShapeIndex The shape ID in which the new shape.
fWidth Shape width.
fHeight Shape height.
iEdges Symbol number 0=Chefron arrow ; 1=Direction arrow ; 2=Notched arrow ; 3=Arrow
RETURNS
The return value is a new ID for the Shape object.
    Agk.CreateShapePolygon(4, 128, 128, 10);
    Agk.SetShapePosition(4, Agk.GetShapeX(3) + Agk.GetShapeRadius(4) * 2.0f, 384);
    Agk.SetShapeImage(4, 1);
    Agk.SetShapeDepth(4, 0.5f);

Alt text


Properties to Get

IntPtr GetShapePtr(uint iShapeIndex)

Returns the pointer to the shape class.

PARAMETER
iShapeIndex The shape ID from which the pointer is to be fetched.
RETURNS
An IntPtr that represents the pointer of the class.

void LoadShapeFromMemblocks(uint iShapeIndex, uint numVertices, uint iVertMemblock, uint iColorMemblock, uint iUVMemblock, ushort iNumIndices, uint iIndicesMemblock)

Fills a shape object previously created with CreateShape() or CreateShape(id) with vertices.

PARAMETER
iShapeIndex The shape ID to be filled with the vertex data.
iNumVertices Number of vertices that will be loaded into it.
iVertMemblock This memblock contains the position data of the vertices. Values in the memblock must be of type float. The number of float values are the double of iNumVertices. So for each vertex two float values (X and Y)
iColorMemblock This memblock contains the color information for each vertex. For each vertex there must be 4 float values. The value range is between 0.0 and 1.0 representing the red, green, blue and alpha channels. Also in this order.
iUVMemblock This memblock contains the UV coordinates of each vertex. Again, the values are between 0.0 and 1.0. Two values for each vertex must be present.
iNumIndices Number of indices for the shape. The number of indices should be divisible by three.
iIndicesMemblock This memblock contains the indices. The values are short values. Three indices form a triangle.

void LoadShapeFromMemory(uint iShapeIndex, uint iNumVertices, float[] Vert, float[] Color, float[] UV, ushort iNumIndices, ushort[] Indices)

Fills a shape object previously created with CreateShape() or CreateShape(id) with vertices. The data is passed here as float and ushort arrays.

PARAMETER
iShapeIndex The shape ID to be filled with the vertex data.
iNumVertices Number of vertices that will be loaded into it.
Vert This array contains the position data of the vertices. Values in the array must be of type float. The number of float values are the double of iNumVertices. So for each vertex two float values (X and Y)
Color This array contains the color information for each vertex. For each vertex there must be 4 float values. The value range is between 0.0 and 1.0 representing the red, green, blue and alpha channels. Also in this order.
UV This array contains the UV coordinates of each vertex. Again, the values are between 0.0 and 1.0. Two values for each vertex must be present.
iNumIndices Number of indices for the shape. The number of indices should be divisible by three.
Indices This array contains the indices. The values are short values. Three indices form a triangle.

Shape Properties

int GetShapeInScreen(uint iShapeIndex)

Used to check if the shape is in the visible area of the screen.

PARAMETER
iShapeIndex The shape ID to be checked.
RETURNS
Returns 1 if the shape is in the visible area. Otherwise the function returns 0.

int GetShapeVisible(uint iShapeIndex)

Used to check if the shape set to visible.

PARAMETER
iShapeIndex The shape ID to be checked.
RETURNS
Returns 1 if the shape is set to visible. Otherwise the function returns 0.

float GetShapeX(uint iShapeIndex)

Gets the current X coordinate of the shape.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns the current X coordinate of the shape's axis.

float GetShapeY(uint iShapeIndex)

Gets the current Y coordinate of the shape.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns the current Y coordinate of the shape's axis.

float GetShapeScaleX(uint iShapeIndex)

Gets the current X scale factor.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns the current X scale factor shape.

float GetShapeScaleY(uint iShapeIndex)

Gets the current Y scale factor.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns the current Y scale factor shape.

float GetShapeAngle(uint iShapeIndex)

Gets the current angle of the shape.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns the current angle of the shape.

float GetShapeAngle(uint iShapeIndex)

UV coordinates can be rotated independently from the normal vertices. This is used to retrieve the angle of the UV rotation.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns the current angle of the UV rotation of the shape.

float GetShapeWidth(uint iShapeIndex)

Gets the current width of the shape.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns the current width of the shape.

float GetShapeHeight(uint iShapeIndex)

Gets the current height of the shape.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns the current height of the shape.

float GetShapeRadius(uint iShapeIndex)

Gets the furthest vertex from the axis of the shape.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns the furthest vertex from the axis of the shape.

float GetShapeDepth(uint iShapeIndex)

Gets the current drawing depth. The values are between 0.0001 and 0.9999. The lowest value is in the front of the screen and the higher values are in the back of the screen.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns the current drawing depth.

float GetShapeAxisX(uint iShapeIndex)

Gets the X center of the axis. This is the negative value of the smallest value of the X axis.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns the X center of the axis.

float GetShapeAxisY(uint iShapeIndex)

Gets the Y center of the axis. This is the negative value of the smallest value of the Y axis.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns the Y center of the axis.

float GetShapeVertexPositionX(ushort iShapeIndex, int iVertexIndex)

Gets the X position of a vertex from a shape.

PARAMETER
iShapeIndex The ID of the shape to retrieve
iVertexIndex The Vertex-ID from the shape to retrieve
RETURNS
Returns the X position of a vertex from a shape.

float GetShapeVertexPositionY(ushort iShapeIndex, int iVertexIndex)

Gets the Y position of a vertex from a shape.

PARAMETER
iShapeIndex The ID of the shape to retrieve
iVertexIndex The Vertex-ID from the shape to retrieve
RETURNS
Returns the Y position of a vertex from a shape.

float GetShapeVertexPositionY(ushort iShapeIndex, int iVertexIndex)

Gets the Y position of a vertex from a shape.

PARAMETER
iShapeIndex The ID of the shape to retrieve
iVertexIndex The Vertex-ID from the shape to retrieve
RETURNS
Returns the Y position of a vertex from a shape.

uint GetShapeVertexColor(ushort iShapeIndex, int iVertexIndex)

Gets the color of a vertex from a shape.

PARAMETER
iShapeIndex The ID of the shape to retrieve
iVertexIndex The Vertex-ID from the shape to retrieve
RETURNS
Returns the color of a vertex from a shape.

float GetShapeVertexTextureU(ushort iShapeIndex, int iVertexIndex)

Gets the texture U coordinate of a vertex from a shape.

PARAMETER
iShapeIndex The ID of the shape to retrieve
iVertexIndex The Vertex-ID from the shape to retrieve
RETURNS
Returns the texture U coordinate of a vertex from a shape.

float GetShapeVertexTextureV(ushort iShapeIndex, int iVertexIndex)

Gets the texture V coordinate of a vertex from a shape.

PARAMETER
iShapeIndex The ID of the shape to retrieve
iVertexIndex The Vertex-ID from the shape to retrieve
RETURNS
Returns the texture V coordinate of a vertex from a shape.

int GetShapeFixedToScreen(uint iShapeIndex)

Checks whether the shape has been fixed to the screen.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns 1 if the shape is fixed on the screen. Otherwise 0 is returned.

float GetShapeScreenX(uint iShapeIndex)

Get the X screen position of the shape. Different from GetShapeX which gets the position in world coordinates.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns the X screen position of the shape.

float GetShapeScreenY(uint iShapeIndex)

Get the Y screen position of the shape. Different from GetShapeY which gets the position in world coordinates.

PARAMETER
iShapeIndex The ID of the shape to retrieve
RETURNS
Returns the Y screen position of the shape.

Properties to Set

void SetShapeVisible(uint iShapeIndex, int iMode)

Sets the visibility of the shape. Shapes whose iMode is set to 0 are not drawn.

PARAMETER
iShapeIndex The ID of the shape to modify
iMode The visibility of this shape, 1 for visible, 0 for hidden

void SetShapePosition(uint iShapeIndex, float fPositionX, float fPositionY)

Sets the position of the shape. Positions are set in world coordinates.

PARAMETER
iShapeIndex The ID of the shape to modify
fPositionX The X position in world coordinates to set
fPositionY The Y position in world coordinates to set

void SetShapeScale(uint iShapeIndex, float fScaleH, float fScaleV)

Sets the scale of the shape.

PARAMETER
iShapeIndex The ID of the shape to modify
fScaleH The horizontal scale to set.
fScaleV The vertical scale to set.

void SetShapeUVAngle(uint iShapeIndex, float fAngle)

Sets the rotation of UV-Texture from the shape.

PARAMETER
iShapeIndex The ID of the shape to modify
fAngle The angle to rotate the uv texture.

void SetShapeImage(uint iShapeIndex, uint iImageIndex)

Sets the texture image of the shape.

PARAMETER
iShapeIndex The ID of the shape to modify
iImageIndex The image id to set as a texture.

void SetShapeSize(uint iShapeIndex, float fWidth, float fHeight)

Sets the size of the shape in pixels.

PARAMETER
iShapeIndex The ID of the shape to modify
fWidth The resulting width of the shape.
fHeight The resulting height of the shape.

void SetShapeDepth(uint iShapeIndex, float fDepth)

Sets the drawing depth of the shape.

PARAMETER
iShapeIndex The ID of the shape to modify
fDepth The drawing depth must between 0.0001 (front) and 0.9999 (back).

void MoveShapeAxis(uint iShapeIndex, float fMoveX, float fMoveY)

Moves the current axis. The positions of the vertices are recalculated.

PARAMETER
iShapeIndex The ID of the shape to modify
fMoveX Move the axis by fMoveX in X direction
fMoveY Move the axis by fMoveY in Y direction

void SetShapeUVAxis(uint iShapeIndex, float fAxisX, float fAxisY)

Sets a new reference point for the UV coordinates.

PARAMETER
iShapeIndex The ID of the shape to modify
fMoveX X value of the new reference point.
fMoveY Y value of the new reference point.

void InkShape(uint iShapeIndex, float fR, float fG, float fB, float fA)

Sets new color values of all Vertices in the shape.

PARAMETER
iShapeIndex The ID of the shape to modify
fR New value for the red component.
fG New value for the green component.
fB New value for the blue component.
fA New value for the alpha component.

void SetShapeVertexPosition(uint iShapeIndex, ushort iVertexIndex, float fPosX, float fPosY)

Sets the vertex specified with iVertexIndex to a new position. The values refer to the shape axis.

PARAMETER
iShapeIndex The ID of the shape to modify
iVertexIndex The Vertex ID of the shape to be modified.
fPosX New value for the X position.
fPosY New value for the Y position.

void SetShapeVertexPosition(uint iShapeIndex, ushort iVertexIndex, float fPosX, float fPosY)

Sets the color of the specified vertex.

PARAMETER
iShapeIndex The ID of the shape to modify
iVertexIndex The Vertex ID of the shape to be modified.
fR New value for the red component.
fG New value for the green component.
fB New value for the blue component.
fA New value for the alpha component.

void SetShapeVertexUV(uint iShapeIndex, ushort iVertexIndex, float fU, float fV)

Sets a new texture coordinate for the specified vertex.

PARAMETER
iShapeIndex The ID of the shape to modify
iVertexIndex The Vertex ID of the shape to be modified.
fU New value for the U position.
fV New value for the V position.

void FixShapeToScreen(uint iShapeIndex, int iMode)

Fixes a shape on the screen.

PARAMETER
iShapeIndex The ID of the shape to modify
iMode The mode to be set 0 = not fixed, 1 = fixed.

void FixShapeTransformation(uint iShapeIndex)

Fixes the transformation of a shape. Normally, scaling and rotation are calculated in each new frame. With this command all vertices are recalculated according to the rotation and scaling. This is recommended for static shapes whose rotation and scaling do not change anymoreor not every frame.

PARAMETER
iShapeIndex The ID of the shape to modify

Example

using System;
using AgkSharp;
using AGKCore;

namespace AGKCore
{
    static class AppInfo
    {
        public static string COMPANY_NAME = "MadBit";
        public static string WIN_TITLE = "DrawPrimitives";
    }
}

namespace DrawPrimitives
{
    static class Program
    {
        /// <summary>
        /// Der Haupteinstiegspunkt für die Anwendung.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Core.CreateWindow(AppInfo.WIN_TITLE, 1024, 768, false);
            if (!Core.InitAGK())
                return;

            Agk.SetVirtualResolution(1024, 768);

            float[] custVert = { -112, -122, 130, -64, 105, 120, -100, 85 };
            float[] custColor = { 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0.5f, 0.5f, 0.5f, 1 };
            float[] custUV = { 0, 0, 1, 0, 1, 1, 0, 1 };
            ushort[] custIndicies = { 0, 1, 2, 0, 2, 3 };

            Agk.LoadImage(1, "media/background5.jpg");

            Agk.CreateShape(1);
            Agk.LoadShapeFromMemory(1, 4, custVert, custColor, custUV, 6, custIndicies);
            Agk.SetShapePosition(1, 512, 128);

            Agk.CreateShapeTriangle(2, 128, 128);
            Agk.SetShapePosition(2, Agk.GetShapeRadius(2), 384);
            Agk.SetShapeImage(2, 1);

            Agk.CreateShapeRectangle(3, 128, 128);
            Agk.SetShapePosition(3, Agk.GetShapeX(2) + Agk.GetShapeRadius(3) * 2.0f, 384);
            Agk.SetShapeImage(3, 1);
            Agk.SetShapeUVAxis(3, 0.5f, 0.5f);

            Agk.CreateShapePolygon(4, 128, 128, 10);
            Agk.SetShapePosition(4, Agk.GetShapeX(3) + Agk.GetShapeRadius(4) * 2.0f, 384);
            Agk.SetShapeImage(4, 1);
            Agk.SetShapeDepth(4, 0.5f);

            Agk.CreateShapeStar(5, 128, 128, 0.38f, 6);
            Agk.SetShapePosition(5, Agk.GetShapeX(4) + Agk.GetShapeRadius(5) * 2.0f, 384);

            Agk.CreateShapeSymbol(6, 128, 128, 2);
            Agk.SetShapePosition(6, Agk.GetShapeRadius(6), 484);
            Agk.InkShape(6, 0.5f, 0.7f, 0, 1);
            Agk.MoveShapeAxis(6, 64, 0);

            while (Core.LoopAGK())
            {
                Agk.Print(Agk.ScreenFPS());
                Agk.SetShapeAngle(2, Agk.GetShapeAngle(2) + 1.0f);
                Agk.SetShapeAngle(3, Agk.GetShapeAngle(3) - 1.0f);
                Agk.SetShapeUVAngle(3, Agk.GetShapeAngle(3));
                Agk.SetShapeAngle(4, Agk.GetShapeAngle(4) + 0.5f);
                Agk.SetShapeAngle(5, Agk.GetShapeAngle(5) - 0.3f);

                Agk.Print(Agk.GetShapeScaleX(6));
                Agk.Print(Agk.GetShapeScaleY(6));
                Agk.Print(Agk.GetShapeAngle(6));
                Agk.Print(Agk.GetShapeUVAngle(6));

                Agk.Sync();
            }

            Core.CleanUp();
        }
    }
}

Alt text