// --------------------------------------------------------------------------- // Project Name : Nook // File Name : Mesh.c // Author : Mary Khuu // Creation Date : 19 Feb 2021 // Purpose : Deals with all things needed for sprites // All content © 2021 DigiPen (USA) Corporation, all rights reserved. // --------------------------------------------------------------------------- #include "Sprite.h" //function to create a quadratic mesh AEGfxVertexList* createQuadMesh(float halfSizeX, float halfSizeY, float u, float v, const char* meshName) { AEGfxVertexList* mesh; AEGfxMeshStart(); AEGfxTriAdd( -halfSizeX, -halfSizeY, 0x00FFFFFF, 0.0f, v, halfSizeX, -halfSizeY, 0x00FFFFFF, u, v, -halfSizeX, halfSizeY, 0x00FFFFFF, 0.0f, 0.0f); AEGfxTriAdd( halfSizeX, -halfSizeY, 0x00FFFFFF, u, v, halfSizeX, halfSizeY, 0x00FFFFFF, u, 0.0f, -halfSizeX, halfSizeY, 0x00FFFFFF, 0.0f, 0.0f); mesh = AEGfxMeshEnd(); AE_WARNING_MESG(mesh, "Failed to create %s!", meshName); if (mesh != 0) { return mesh; } else { return 0; } } //same as above but less parameters, assume halfsize is the same in x and y and u = v AEGfxVertexList* createEqualQuadMesh(float halfSize, float uv, const char* meshName) { AEGfxVertexList* mesh; AEGfxMeshStart(); AEGfxTriAdd( -halfSize, -halfSize, 0x00FFFFFF, 0.0f, uv, halfSize, -halfSize, 0x00FFFFFF, uv, uv, -halfSize, halfSize, 0x00FFFFFF, 0.0f, 0.0f); AEGfxTriAdd( halfSize, -halfSize, 0x00FFFFFF, uv, uv, halfSize, halfSize, 0x00FFFFFF, uv, 0.0f, -halfSize, halfSize, 0x00FFFFFF, 0.0f, 0.0f); mesh = AEGfxMeshEnd(); AE_WARNING_MESG(mesh, "Failed to create %s!", meshName); if (mesh != 0) { return mesh; } else { return 0; } } int getMaxFrames(int rows, int columns) { return rows * columns; } void animateFrames(int* currentFrame, float* time, float frameDelay, float dt) { (*time) += dt; if (*time >= frameDelay) { (*currentFrame)++; *time = 0; } } void checkEndFrames(int* currentFrame, int maxFrame) { if (*currentFrame >= maxFrame) { *currentFrame = 0; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter