feat: add Cross2D for Kreuzprodukt vector calculation
This commit is contained in:
+122
-117
@@ -1,190 +1,189 @@
|
|||||||
#ifndef ENGINE_H
|
#ifndef ENGINE_H
|
||||||
#define ENGINE_H
|
#define ENGINE_H
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <raygui.h>
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
#include <raygui.h>
|
|
||||||
#include <rini.h>
|
#include <rini.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
Texture2D texture;
|
||||||
Texture2D texture;
|
Rectangle sourceRec;
|
||||||
Rectangle sourceRec;
|
Rectangle destRec;
|
||||||
Rectangle destRec;
|
Vector2 frameSize;
|
||||||
Vector2 frameSize;
|
Vector2 origin;
|
||||||
Vector2 origin;
|
float rotation;
|
||||||
float rotation;
|
Color color;
|
||||||
Color color;
|
|
||||||
} Sprite;
|
} Sprite;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int state;
|
int state;
|
||||||
int currentFrame;
|
int currentFrame;
|
||||||
int maxFrame;
|
int maxFrame;
|
||||||
int framesCounter;
|
int framesCounter;
|
||||||
int framesSpeed;
|
int framesSpeed;
|
||||||
float animTimer;
|
float animTimer;
|
||||||
} Animation;
|
} Animation;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void** elements;
|
void **elements;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
unsigned int capacity;
|
unsigned int capacity;
|
||||||
} Array;
|
} Array;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char* path;
|
const char *path;
|
||||||
float frameWidth;
|
float frameWidth;
|
||||||
float frameHeight;
|
float frameHeight;
|
||||||
float rotation;
|
float rotation;
|
||||||
} TextureAsset;
|
} TextureAsset;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char* path;
|
const char *path;
|
||||||
} ShaderAsset;
|
} ShaderAsset;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char* path;
|
const char *path;
|
||||||
} SoundtrackAsset;
|
} SoundtrackAsset;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char* path;
|
const char *path;
|
||||||
} SoundAsset;
|
} SoundAsset;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const TextureAsset *textureAssets;
|
const TextureAsset *textureAssets;
|
||||||
const ShaderAsset *shaderAssets;
|
const ShaderAsset *shaderAssets;
|
||||||
const SoundtrackAsset *soundtrackAssets;
|
const SoundtrackAsset *soundtrackAssets;
|
||||||
const SoundAsset *soundAssets;
|
const SoundAsset *soundAssets;
|
||||||
} Assets;
|
} Assets;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *path;
|
char *path;
|
||||||
rini_config rini;
|
rini_config rini;
|
||||||
} Config;
|
} Config;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum { NOT_CLICKED, HOVER, CLICKED } ButtonState;
|
||||||
NOT_CLICKED,
|
|
||||||
HOVER,
|
|
||||||
CLICKED
|
|
||||||
} ButtonState;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
Sprite sprite;
|
||||||
Sprite sprite;
|
Vector2 notClicked;
|
||||||
Vector2 notClicked;
|
Vector2 hover;
|
||||||
Vector2 hover;
|
Vector2 clicked;
|
||||||
Vector2 clicked;
|
bool isHovered;
|
||||||
bool isHovered;
|
bool isClicked;
|
||||||
bool isClicked;
|
|
||||||
} ImageButton;
|
} ImageButton;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
Sprite sprite;
|
||||||
Sprite sprite;
|
|
||||||
} ImageElement;
|
} ImageElement;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
Rectangle rec;
|
||||||
Rectangle rec;
|
char *text;
|
||||||
char *text;
|
|
||||||
} Button;
|
} Button;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Vector2 screenPosition;
|
Vector2 screenPosition;
|
||||||
Vector2 worldPosition;
|
Vector2 worldPosition;
|
||||||
float zoomSpeed;
|
float zoomSpeed;
|
||||||
float minZoom;
|
float minZoom;
|
||||||
float maxZoom;
|
float maxZoom;
|
||||||
float scaleFactor;
|
float scaleFactor;
|
||||||
float wheelMove;
|
float wheelMove;
|
||||||
bool leftButton;
|
bool leftButton;
|
||||||
bool rightButton;
|
bool rightButton;
|
||||||
Texture2D cursorTexture;
|
Texture2D cursorTexture;
|
||||||
} Mouse;
|
} Mouse;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Sprite sprite;
|
Sprite sprite;
|
||||||
Vector2 position;
|
Vector2 position;
|
||||||
} Object;
|
} Object;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Object *data;
|
Object *data;
|
||||||
const Object *prototype;
|
const Object *prototype;
|
||||||
size_t count;
|
size_t count;
|
||||||
} ObjectArray;
|
} ObjectArray;
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
Vector2 position;
|
||||||
Vector2 position;
|
Vector2 direction;
|
||||||
Vector2 direction;
|
Vector2 velocity;
|
||||||
Vector2 velocity;
|
float speed;
|
||||||
float speed;
|
float weight;
|
||||||
} Physics;
|
} Physics;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Shader shader;
|
Shader shader;
|
||||||
int resolutionLoc;
|
int resolutionLoc;
|
||||||
int strengthLoc;
|
int strengthLoc;
|
||||||
float strength;
|
float strength;
|
||||||
} PostProcessing;
|
} PostProcessing;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Music music;
|
Music music;
|
||||||
bool playing;
|
bool playing;
|
||||||
bool paused;
|
bool paused;
|
||||||
} Soundtrack;
|
} Soundtrack;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Vector2 *data;
|
Vector2 *data;
|
||||||
size_t count;
|
size_t count;
|
||||||
} Vector2Array;
|
} Vector2Array;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
const char* title;
|
const char *title;
|
||||||
} Window;
|
} Window;
|
||||||
|
|
||||||
void UpdateAnimation(Animation *animation, float deltaTime);
|
void UpdateAnimation(Animation *animation, float deltaTime);
|
||||||
|
|
||||||
Array* CreateArray(unsigned int initCapacity);
|
Array *CreateArray(unsigned int initCapacity);
|
||||||
int AddElementToArray(Array* array, void* element);
|
int AddElementToArray(Array *array, void *element);
|
||||||
int RemoveElementFromArray(Array* array, unsigned int index);
|
int RemoveElementFromArray(Array *array, unsigned int index);
|
||||||
void* GetRandomElementFromArray(Array* array);
|
void *GetRandomElementFromArray(Array *array);
|
||||||
void UpdateArray(Array* array, void (*updateFunc)(void*));
|
void UpdateArray(Array *array, void (*updateFunc)(void *));
|
||||||
void RenderArray(Array* array, void (*renderFunc)(void*));
|
void RenderArray(Array *array, void (*renderFunc)(void *));
|
||||||
void FreeArray(Array** array);
|
void FreeArray(Array **array);
|
||||||
|
|
||||||
Camera2D* GetCamera(void);
|
Camera2D *GetCamera(void);
|
||||||
Rectangle GetCameraRectangle(void);
|
Rectangle GetCameraRectangle(void);
|
||||||
void CreateCamera(Vector2 playerPosition, float initZoom);
|
void CreateCamera(Vector2 playerPosition, float initZoom);
|
||||||
void UpdateCameraTarget(Vector2 *position, const float smoothness);
|
void UpdateCameraTarget(Vector2 *position, const float smoothness);
|
||||||
void UpdateCameraZoom(const float *scaleFactor, const float *minZoom, const float *maxZoom);
|
void UpdateCameraZoom(const float *scaleFactor, const float *minZoom,
|
||||||
void UpdateCamera2D(Vector2* position, Mouse* mouse);
|
const float *maxZoom);
|
||||||
|
void UpdateCamera2D(Vector2 *position, Mouse *mouse);
|
||||||
|
|
||||||
void InitConfig(Config *config, const char* path);
|
void InitConfig(Config *config, const char *path);
|
||||||
int GetConfigInt(Config *config, const char *key);
|
int GetConfigInt(Config *config, const char *key);
|
||||||
int GetConfigIntOrDefault(Config *config, const char *key, int default_value);
|
int GetConfigIntOrDefault(Config *config, const char *key, int default_value);
|
||||||
const char* GetConfigString(Config *config, const char *key);
|
const char *GetConfigString(Config *config, const char *key);
|
||||||
const char* GetConfigStringOrDefault(Config *config, const char *key, const char *default_value);
|
const char *GetConfigStringOrDefault(Config *config, const char *key,
|
||||||
const char* GetConfigDescription(Config *config, const char *key);
|
const char *default_value);
|
||||||
|
const char *GetConfigDescription(Config *config, const char *key);
|
||||||
int SetConfigInt(Config *config, const char *key, int value, const char *desc);
|
int SetConfigInt(Config *config, const char *key, int value, const char *desc);
|
||||||
int SetConfigString(Config *config, const char *key, const char *text, const char *desc);
|
int SetConfigString(Config *config, const char *key, const char *text,
|
||||||
|
const char *desc);
|
||||||
int SetConfigDescription(Config *config, const char *key, const char *desc);
|
int SetConfigDescription(Config *config, const char *key, const char *desc);
|
||||||
int AddCommentLine(Config *config, const char *comment);
|
int AddCommentLine(Config *config, const char *comment);
|
||||||
void SaveConfig(Config *config);
|
void SaveConfig(Config *config);
|
||||||
void CleanUpConfig(Config *config);
|
void CleanUpConfig(Config *config);
|
||||||
|
|
||||||
void InitFont(Font *font, const char* path);
|
void InitFont(Font *font, const char *path);
|
||||||
void CleanupFont(Font *font);
|
void CleanupFont(Font *font);
|
||||||
|
|
||||||
ImageButton CreateImageButton(ButtonState state, Texture2D *texture, const TextureAsset *asset, Vector2 *source, Vector2 *clicked, Vector2 *hover, Rectangle *destRec);
|
ImageButton CreateImageButton(ButtonState state, Texture2D *texture,
|
||||||
ImageElement CreateImageElement(Texture2D *texture, const TextureAsset *asset, Vector2 *source, Rectangle *destRec);
|
const TextureAsset *asset, Vector2 *source,
|
||||||
|
Vector2 *clicked, Vector2 *hover,
|
||||||
|
Rectangle *destRec);
|
||||||
|
ImageElement CreateImageElement(Texture2D *texture, const TextureAsset *asset,
|
||||||
|
Vector2 *source, Rectangle *destRec);
|
||||||
int isImageButtonClicked(ImageButton *b, Sound soundHover, Sound soundClick);
|
int isImageButtonClicked(ImageButton *b, Sound soundHover, Sound soundClick);
|
||||||
void renderImageButton(ImageButton *b);
|
void renderImageButton(ImageButton *b);
|
||||||
void renderImageElement(ImageElement *e);
|
void renderImageElement(ImageElement *e);
|
||||||
@@ -193,18 +192,24 @@ Button initButton(char *text, Vector2 dimensions, Vector2 position);
|
|||||||
int isButtonClicked(Button *b);
|
int isButtonClicked(Button *b);
|
||||||
void renderButton(Button *b);
|
void renderButton(Button *b);
|
||||||
|
|
||||||
Mouse CreateMouse(float zoomSpeed, float minZoom, float maxZoom, Texture2D *texture);
|
Mouse CreateMouse(float zoomSpeed, float minZoom, float maxZoom,
|
||||||
|
Texture2D *texture);
|
||||||
void UpdateMouseScreen(Mouse *mouse);
|
void UpdateMouseScreen(Mouse *mouse);
|
||||||
void UpdateMouse(Mouse *mouse);
|
void UpdateMouse(Mouse *mouse);
|
||||||
Vector2 GetDirectionVector(void);
|
Vector2 GetDirectionVector(void);
|
||||||
|
|
||||||
ObjectArray CreateObjectArray(const Object *prototype, const size_t count);
|
ObjectArray CreateObjectArray(const Object *prototype, const size_t count);
|
||||||
Object* GetRandomObject(ObjectArray *objects);
|
Object *GetRandomObject(ObjectArray *objects);
|
||||||
void AddObjectToArray(ObjectArray *objects, const Object *prototype, Vector2 position);
|
void AddObjectToArray(ObjectArray *objects, const Object *prototype,
|
||||||
void SetPositionForObjectArray(ObjectArray *objects, const Vector2Array *positions);
|
Vector2 position);
|
||||||
void SetRandomPositionForObjectArray(ObjectArray *objects, const Rectangle bounds);
|
void SetPositionForObjectArray(ObjectArray *objects,
|
||||||
void SwapAndPopObjectsArrayOnRecCollision(ObjectArray *objects, const Rectangle rec);
|
const Vector2Array *positions);
|
||||||
void SwapAndPopObjectsArrayOnPointCollision(ObjectArray *objects, const Vector2 point);
|
void SetRandomPositionForObjectArray(ObjectArray *objects,
|
||||||
|
const Rectangle bounds);
|
||||||
|
void SwapAndPopObjectsArrayOnRecCollision(ObjectArray *objects,
|
||||||
|
const Rectangle rec);
|
||||||
|
void SwapAndPopObjectsArrayOnPointCollision(ObjectArray *objects,
|
||||||
|
const Vector2 point);
|
||||||
void RenderObjectArray(const ObjectArray *objects);
|
void RenderObjectArray(const ObjectArray *objects);
|
||||||
|
|
||||||
Vector2 GetDirectionBetweenTwoVectors(Vector2 vec1, Vector2 vec2);
|
Vector2 GetDirectionBetweenTwoVectors(Vector2 vec1, Vector2 vec2);
|
||||||
@@ -215,12 +220,12 @@ void UpdatePhysicsPosition(Vector2 *position, Vector2 *velocity);
|
|||||||
void UpdatePhysicsSpeed(float *speed, float *newSpeed);
|
void UpdatePhysicsSpeed(float *speed, float *newSpeed);
|
||||||
void UpdatePhysics(Physics *physics, Vector2 direction);
|
void UpdatePhysics(Physics *physics, Vector2 direction);
|
||||||
|
|
||||||
PostProcessing CreatePostFX(const char* shaderPath);
|
PostProcessing CreatePostFX(const char *shaderPath);
|
||||||
void UpdatePostFX(PostProcessing *postFX);
|
void UpdatePostFX(PostProcessing *postFX);
|
||||||
void RenderPostFX(PostProcessing *postFX, RenderTexture2D *target);
|
void RenderPostFX(PostProcessing *postFX, RenderTexture2D *target);
|
||||||
void UnloadPostFX(PostProcessing *postFX);
|
void UnloadPostFX(PostProcessing *postFX);
|
||||||
|
|
||||||
Soundtrack LoadSoundtrack(const char* musicPath);
|
Soundtrack LoadSoundtrack(const char *musicPath);
|
||||||
void UpdateSoundtrack(Soundtrack *soundtrack, bool playing);
|
void UpdateSoundtrack(Soundtrack *soundtrack, bool playing);
|
||||||
|
|
||||||
void UpdateSpriteSourceRec(Sprite *sprite, const Vector2 *vector);
|
void UpdateSpriteSourceRec(Sprite *sprite, const Vector2 *vector);
|
||||||
@@ -233,9 +238,9 @@ bool IsVectorZero(Vector2 v);
|
|||||||
Vector2 GetRandomVector(const Rectangle bounds);
|
Vector2 GetRandomVector(const Rectangle bounds);
|
||||||
Vector2 RotationToVector2(float rotation);
|
Vector2 RotationToVector2(float rotation);
|
||||||
float Vector2ToRotation(Vector2 vec);
|
float Vector2ToRotation(Vector2 vec);
|
||||||
|
float Cross2D(Vector2 a, Vector2 b);
|
||||||
|
|
||||||
Vector2 GetPositionInsideRectangle(Rectangle rec);
|
Vector2 GetPositionInsideRectangle(Rectangle rec);
|
||||||
Vector2 GetPositionOutsideRectangle(Rectangle rec, int min, int max);
|
Vector2 GetPositionOutsideRectangle(Rectangle rec, int min, int max);
|
||||||
|
|
||||||
#endif //ENGINE_H
|
#endif // ENGINE_H
|
||||||
|
|
||||||
|
|||||||
+15
-16
@@ -1,27 +1,26 @@
|
|||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
|
|
||||||
bool IsVectorZero(Vector2 v) {
|
bool IsVectorZero(Vector2 v) {
|
||||||
float epsilon = 0.01f;
|
float epsilon = 0.01f;
|
||||||
return (fabs(v.x) < epsilon && fabs(v.y) < epsilon);
|
return (fabs(v.x) < epsilon && fabs(v.y) < epsilon);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 GetRandomVector(const Rectangle bounds) {
|
Vector2 GetRandomVector(const Rectangle bounds) {
|
||||||
return (Vector2){
|
return (Vector2){
|
||||||
bounds.x + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.width,
|
bounds.x + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.width,
|
||||||
bounds.y + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.height
|
bounds.y + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.height};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 RotationToVector2(float rotation)
|
Vector2 RotationToVector2(float rotation) {
|
||||||
{
|
float rad = rotation * (PI / 180.0f);
|
||||||
float rad = rotation * (PI / 180.0f);
|
Vector2 vec = {cosf(rad), sinf(rad)};
|
||||||
Vector2 vec = { cosf(rad), sinf(rad) };
|
return vec;
|
||||||
return vec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector2ToRotation(Vector2 vec)
|
float Vector2ToRotation(Vector2 vec) {
|
||||||
{
|
float rad = atan2f(vec.y, vec.x);
|
||||||
float rad = atan2f(vec.y, vec.x);
|
float deg = rad * (180.0f / PI);
|
||||||
float deg = rad * (180.0f / PI);
|
return deg;
|
||||||
return deg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Cross2D(Vector2 a, Vector2 b) { return a.x * b.y - a.y * b.x; }
|
||||||
|
|||||||
Reference in New Issue
Block a user