Added AABB Point

This commit is contained in:
2021-08-17 08:25:20 -07:00
parent 0557ba3274
commit 41c460b90b
20 changed files with 310 additions and 55 deletions

View File

@ -25,11 +25,11 @@ void frameBufferInit(framebuffer_t *fb, int32_t w, int32_t h) {
// Render Buffer
glGenRenderbuffers(1, &fb->rboId);
glBindRenderbuffer(GL_RENDERBUFFER, fb->rboId);
// glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, w, h);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, w, h);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
// glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
// GL_RENDERBUFFER, fb->rboId
// );
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
GL_RENDERBUFFER, fb->rboId
);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
uint32_t error;

View File

@ -18,7 +18,7 @@ void renderInit() {
glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);
glClearColor(1.0, 0, 0, 1.0);
glClearColor(0,0,0, 1.0);
}
void renderFrameStart(render_t *render) {

View File

@ -7,6 +7,11 @@
#include "game.h"
#include "../physics/vector.h"
primitive_t primitive;
texture_t texture;
bool gameInit(game_t *game) {
// Init the engine and the rendering pipeline
engineInit(&game->engine, game);

View File

@ -7,6 +7,10 @@
#include "pokergame.h"
primitive_t primitive;
primitive_t dot;
float x, y;
bool pokerGameInit(game_t *game) {
pokergame_t *pokerGame = &game->pokerGame;
@ -21,6 +25,11 @@ bool pokerGameInit(game_t *game) {
pokerGameActionStartAdd(pokerGame);
queueNext(&pokerGame->scene.conversation.actionQueue);
//
quadInit(&primitive, 0, 0,0,0,0, 64,64,1,1);
quadInit(&dot, 0, 0,0,0,0, 2,2,1,1);
x = 0, y = 0;
return true;
}
@ -29,7 +38,7 @@ void pokerGameUpdate(game_t *game) {
pokerGame = &game->pokerGame;
// Update the scene
vnSceneUpdate(&pokerGame->scene, &game->engine);
// vnSceneUpdate(&pokerGame->scene, &game->engine);
// Bind the shader.
shaderUse(&pokerGame->assets.shader);
@ -38,7 +47,26 @@ void pokerGameUpdate(game_t *game) {
// Render the visual novel scene
// vnSceneRenderWorld(&pokerGame->scene, &game->engine, &pokerGame->assets.shader);
vnSceneRenderGui(&pokerGame->scene, &game->engine, &pokerGame->assets.shader);
pokerUiRender(pokerGame);
shaderUseTexture(&pokerGame->assets.shader, &pokerGame->assets.testTexture);
x = inputGetAxis(&game->engine.input, INPUT_MOUSE_X);
y = inputGetAxis(&game->engine.input, INPUT_MOUSE_Y);
aabbpointhit_t hitting;
bool hit = aabbPoint2D(x, y, 64,64, 64,64, &hitting);
shaderUsePosition(&pokerGame->assets.shader, 64,64,0, 0,0,0);
primitiveDraw(&primitive, 0, -1);
if(hit) {
shaderUsePosition(&pokerGame->assets.shader, hitting.hitX,hitting.hitY,0, 0,0,0);
} else {
shaderUsePosition(&pokerGame->assets.shader, x,y,0, 0,0,0);
}
primitiveDraw(&dot, 0, -1);
// pokerUiRender(pokerGame);
}
void pokerGameDispose(game_t *game) {

View File

@ -15,6 +15,8 @@
#include "pokerui.h"
#include "../../ui/frame.h"
#include "../../physics/aabb.h"
#include "../../input/input.h"
/**
* Initializes the game state for the poker game.

57
src/physics/aabb.c Normal file
View File

@ -0,0 +1,57 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "aabb.h"
bool aabbPoint2D(
float pointX, float pointY,
float x, float y, float width, float height,
aabbpointhit_t *hit
) {
float dx, px, sx, halfWidth;
float dy, py, sy, halfHeight;
if(hit == NULL) {
// Check X Axis, are we outside the box
if(pointX < x || pointY < y) return false;
if(pointX > x+width || pointY > y+height) return false;
return true;
}
halfWidth = width / 2;
halfHeight = height / 2;
x += halfWidth;
y += halfHeight;
dx = pointX - x;
px = halfWidth - mathAbs(dx);
if(px <= 0) return false;
dy = pointY - y;
py = halfHeight - mathAbs(dy);
if(py <= 0) return false;
if(px < py) {
sx = mathSign(dx);
// float deltaX = px *sx;
hit->normalX = sx;
hit->normalY = 0;
hit->hitX = x + (halfWidth * sx);
hit->hitY = pointY;
} else {
sy = mathSign(dy);
// float deltaY = py * sy;
hit->normalX = 0;
hit->normalY = sy;
hit->hitX = pointX;
hit->hitY = x + (halfHeight * sy);
}
return true;
}

17
src/physics/aabb.h Normal file
View File

@ -0,0 +1,17 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "sphere.h"
#include "../input/input.h"
bool aabbPoint2D(
float pointX, float pointY,
float x, float y, float width, float height,
aabbpointhit_t *hit
);

20
src/physics/sphere.c Normal file
View File

@ -0,0 +1,20 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "sphere.h"
bool sphereDistance2D(float x0, float y0, float x1, float y1, float radius) {
x0 = vectorDistance2D(x0, y0, x1, y1);
return x0 <= radius;
}
bool sphereDistance3D(
float x0, float y0, float z0, float x1, float y1, float z1, float radius
) {
x0 = vectorDistance3D(x0, y0, z0, x1, y1, z1);
return x0 <= radius;
}

38
src/physics/sphere.h Normal file
View File

@ -0,0 +1,38 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
#include "vector.h"
/**
* Checks whether a point is colliding with a circle.
*
* @param x0 X Position of the vector.
* @param y0 Y position of the vector.
* @param x1 Center point of the circle. X Coordinate.
* @param y1 Center point of the circle. Y Coordinate.
* @param radius Radius of the circle
* @return True if the point is colliding, otherwise false.
*/
bool sphereDistance2D(float x0, float y0, float x1, float y1, float radius);
/**
* Checks whether a point is colliding with a sphere.
*
* @param x0 X Position of the vector.
* @param y0 Y Position of the vector.
* @param z0 Z Position of the vector.
* @param x1 Center point of the circle, X Coordinate.
* @param y1 Center point of the circle, Y Coordinate.
* @param z1 Center point of the circle, Z Coordinate.
* @param radius Radius of the sphere.
* @return True if the point is colliding with the sphere.
*/
bool sphereDistance3D(
float x0, float y0, float z0, float x1, float y1, float z1, float radius
);

24
src/physics/vector.c Normal file
View File

@ -0,0 +1,24 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "vector.h"
float vectorDistance2D(float x0, float y0, float x1, float y1) {
x0 = x1 - x0;
y0 = y1 - y0;
return sqrt(x0*x0 + y0*y0);
}
float vectorDistance3D(
float x0, float y0, float z0, float x1, float y1, float z1
) {
x0 = x1 - x0;
y0 = y1 - y0;
z0 = z1 - z0;
return sqrt(x0*x0 + y0*y0 + z0*z0);
}

35
src/physics/vector.h Normal file
View File

@ -0,0 +1,35 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include <dawn/dawn.h>
/**
* Calculate the distance between two points in 2D space.
*
* @param x0 First Position X Coordinate.
* @param y0 First Position Y Coordinate.
* @param x1 Second Position X Coordinate.
* @param y1 Second Position Y Coordinate.
* @return The distance measurement.
*/
float vectorDistance2D(float x0, float y0, float x1, float y1);
/**
* Calculate the distance between two points in 3D space.
*
* @param x0 First Position X Coordinate.
* @param y0 First Position Y Coordinate.
* @param z0 First Position Z Coordinate.
* @param x1 Second Position X Coordinate.
* @param y1 Second Position Y Coordinate.
* @param z1 Second Position Z Coordinate.
* @return The distance measurement.
*/
float vectorDistance3D(
float x0, float y0, float z0, float x1, float y1, float z1
);

View File

@ -80,5 +80,5 @@ void vnSceneRenderGui(vnscene_t *scene, engine_t *engine, shader_t *shader) {
shaderUseCamera(shader, &scene->camera);
// Render Conversation Element
vnConversationRender(&scene->conversation, shader);
// vnConversationRender(&scene->conversation, shader);
}