feat: add Cross2D for Kreuzprodukt vector calculation

This commit is contained in:
huaqo-games
2026-06-29 18:13:31 +02:00
parent 59b51c2beb
commit c27ada5352
2 changed files with 137 additions and 133 deletions
+35 -30
View File
@@ -1,17 +1,16 @@
#ifndef ENGINE_H
#define ENGINE_H
#include <math.h>
#include <raygui.h>
#include <raylib.h>
#include <raymath.h>
#include <raygui.h>
#include <rini.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef struct
{
typedef struct {
Texture2D texture;
Rectangle sourceRec;
Rectangle destRec;
@@ -67,14 +66,9 @@ typedef struct {
rini_config rini;
} Config;
typedef enum {
NOT_CLICKED,
HOVER,
CLICKED
} ButtonState;
typedef enum { NOT_CLICKED, HOVER, CLICKED } ButtonState;
typedef struct
{
typedef struct {
Sprite sprite;
Vector2 notClicked;
Vector2 hover;
@@ -83,13 +77,11 @@ typedef struct
bool isClicked;
} ImageButton;
typedef struct
{
typedef struct {
Sprite sprite;
} ImageElement;
typedef struct
{
typedef struct {
Rectangle rec;
char *text;
} Button;
@@ -118,12 +110,12 @@ typedef struct {
size_t count;
} ObjectArray;
typedef struct
{
typedef struct {
Vector2 position;
Vector2 direction;
Vector2 velocity;
float speed;
float weight;
} Physics;
typedef struct {
@@ -164,17 +156,20 @@ Camera2D* GetCamera(void);
Rectangle GetCameraRectangle(void);
void CreateCamera(Vector2 playerPosition, float initZoom);
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,
const float *maxZoom);
void UpdateCamera2D(Vector2 *position, Mouse *mouse);
void InitConfig(Config *config, const char *path);
int GetConfigInt(Config *config, const char *key);
int GetConfigIntOrDefault(Config *config, const char *key, int default_value);
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 *default_value);
const char *GetConfigDescription(Config *config, const char *key);
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 AddCommentLine(Config *config, const char *comment);
void SaveConfig(Config *config);
@@ -183,8 +178,12 @@ void CleanUpConfig(Config *config);
void InitFont(Font *font, const char *path);
void CleanupFont(Font *font);
ImageButton CreateImageButton(ButtonState state, Texture2D *texture, const TextureAsset *asset, Vector2 *source, Vector2 *clicked, Vector2 *hover, Rectangle *destRec);
ImageElement CreateImageElement(Texture2D *texture, const TextureAsset *asset, Vector2 *source, Rectangle *destRec);
ImageButton CreateImageButton(ButtonState state, Texture2D *texture,
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);
void renderImageButton(ImageButton *b);
void renderImageElement(ImageElement *e);
@@ -193,18 +192,24 @@ Button initButton(char *text, Vector2 dimensions, Vector2 position);
int isButtonClicked(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 UpdateMouse(Mouse *mouse);
Vector2 GetDirectionVector(void);
ObjectArray CreateObjectArray(const Object *prototype, const size_t count);
Object *GetRandomObject(ObjectArray *objects);
void AddObjectToArray(ObjectArray *objects, const Object *prototype, Vector2 position);
void SetPositionForObjectArray(ObjectArray *objects, const Vector2Array *positions);
void SetRandomPositionForObjectArray(ObjectArray *objects, const Rectangle bounds);
void SwapAndPopObjectsArrayOnRecCollision(ObjectArray *objects, const Rectangle rec);
void SwapAndPopObjectsArrayOnPointCollision(ObjectArray *objects, const Vector2 point);
void AddObjectToArray(ObjectArray *objects, const Object *prototype,
Vector2 position);
void SetPositionForObjectArray(ObjectArray *objects,
const Vector2Array *positions);
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);
Vector2 GetDirectionBetweenTwoVectors(Vector2 vec1, Vector2 vec2);
@@ -233,9 +238,9 @@ bool IsVectorZero(Vector2 v);
Vector2 GetRandomVector(const Rectangle bounds);
Vector2 RotationToVector2(float rotation);
float Vector2ToRotation(Vector2 vec);
float Cross2D(Vector2 a, Vector2 b);
Vector2 GetPositionInsideRectangle(Rectangle rec);
Vector2 GetPositionOutsideRectangle(Rectangle rec, int min, int max);
#endif // ENGINE_H
+5 -6
View File
@@ -8,20 +8,19 @@ bool IsVectorZero(Vector2 v) {
Vector2 GetRandomVector(const Rectangle bounds) {
return (Vector2){
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);
Vector2 vec = {cosf(rad), sinf(rad)};
return vec;
}
float Vector2ToRotation(Vector2 vec)
{
float Vector2ToRotation(Vector2 vec) {
float rad = atan2f(vec.y, vec.x);
float deg = rad * (180.0f / PI);
return deg;
}
float Cross2D(Vector2 a, Vector2 b) { return a.x * b.y - a.y * b.x; }