Changed rotation order to YZX

This commit is contained in:
2021-05-12 07:01:47 -07:00
parent 8349fed5a8
commit 1df6c5bfb8
7 changed files with 116 additions and 73 deletions

View File

@ -32,7 +32,7 @@
)
#define HOLDEM_GAME_CARD_WIDTH 0.05
#define HOLDEM_GAME_CARD_HEIGHT 0.07
#define HOLDEM_GAME_CARD_DEPTH 0.001
#define HOLDEM_GAME_CARD_DEPTH 0.0005
/** How many actions the queue can hold */
#define HOLDEM_GAME_ACTION_QUEUE_SIZE 12

View File

@ -98,7 +98,7 @@ void holdemRender() {
((float)lWidth/height), 0.2f, 1000.0f
);
// cameraLookAt(&HOLDEM_GAME_STATE.cameraLeft, 2, 2, 2, 0, 0, 0);
holdemLookHand(&HOLDEM_GAME_STATE.cameraLeft, 0x00);
holdemRenderLookHand(&HOLDEM_GAME_STATE.cameraLeft, 0x00);
shaderUseCamera(GAME_STATE.shaderWorld, &HOLDEM_GAME_STATE.cameraLeft);
holdemRenderWorld();
@ -132,9 +132,8 @@ void holdemRender() {
primitiveDraw(HOLDEM_GAME_STATE.quadRight, 0, -1);
}
void holdemLookSeat(camera_t *camera, uint8_t seat) {
void holdemRenderLookSeat(camera_t *camera, uint8_t seat) {
float x, z, angle;
angle = mathDeg2Rad(-45*seat);
x = sin(angle);
z = cos(angle);
@ -144,20 +143,23 @@ void holdemLookSeat(camera_t *camera, uint8_t seat) {
);
}
void holdemLookHand(camera_t *camera, uint8_t seat) {
float x, lx, z, lz, angle, distance;
void holdemRenderLookHand(camera_t *camera, uint8_t seat) {
float x, z, angle;
angle = mathDeg2Rad(-45*seat);
x = sin(angle);
z = cos(angle);
cameraLookAt(&HOLDEM_GAME_STATE.cameraLeft,
x*0.1, 0.8, z*0.1,
-x*0.5, 0.2, -z*0.5
);
}
void holdemRenderPlayer(float x, float y, float z, float yaw) {
void holdemRenderPlayer(uint8_t seat) {
float x, z, angle;
angle = mathDeg2Rad(-45*seat);
x = sin(angle) * -1;
z = cos(angle) * -1;
float w, h;
w = 0.6, h = (
(float)HOLDEM_GAME_STATE.kagamiTileset->divY /
@ -176,13 +178,19 @@ void holdemRenderPlayer(float x, float y, float z, float yaw) {
);
shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.kagamiTexture);
shaderUsePosition(GAME_STATE.shaderWorld, x, y, z, 0, mathDeg2Rad(yaw), 0);
shaderUsePosition(GAME_STATE.shaderWorld,
x, 0.34, z,
0, mathDeg2Rad(-45*seat), 0
);
primitiveDraw(HOLDEM_GAME_STATE.kagamiQuad, 0, -1);
}
void holdemRenderCard(card_t card,
float x, float y, float z, float pitch, float yaw, float roll
) {
void holdemRenderCard(uint8_t seat, card_t card) {
float x, z, angle;
angle = mathDeg2Rad(-45*seat);
x = sin(angle) * -0.75;
z = cos(angle) * -0.75;
tilesetdiv_t *cardFront = HOLDEM_GAME_STATE.cardTileset->divisions + card;
quadBuffer(HOLDEM_GAME_STATE.cardPrimitive, HOLDEM_GAME_CARD_DEPTH,
-HOLDEM_GAME_CARD_WIDTH, -HOLDEM_GAME_CARD_HEIGHT,
@ -193,7 +201,7 @@ void holdemRenderCard(card_t card,
);
shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.cardTexture);
shaderUsePosition(GAME_STATE.shaderWorld, x, y, z, pitch, yaw, roll);
shaderUsePosition(GAME_STATE.shaderWorld, x,0,z, mathDeg2Rad(90),angle,0);
primitiveDraw(HOLDEM_GAME_STATE.cardPrimitive, 0, -1);
}
@ -211,49 +219,59 @@ void holdemRenderWorld() {
);
shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.tableTexture);
primitiveDraw(HOLDEM_GAME_STATE.tablePrimitive, 0, -1);
holdemRenderCard(0x00, CARD_HEARTS_QUEEN);
holdemRenderCard(0x01, CARD_HEARTS_QUEEN);
holdemRenderCard(0x02, CARD_HEARTS_QUEEN);
holdemRenderCard(0x03, CARD_HEARTS_QUEEN);
holdemRenderCard(0x04, CARD_HEARTS_QUEEN);
holdemRenderCard(0x05, CARD_HEARTS_QUEEN);
holdemRenderCard(0x06, CARD_HEARTS_QUEEN);
holdemRenderCard(0x07, CARD_HEARTS_QUEEN);
// Players
holdemRenderPlayer(0x00);
holdemRenderPlayer(0x01);
holdemRenderPlayer(0x02);
holdemRenderPlayer(0x03);
holdemRenderPlayer(0x04);
holdemRenderPlayer(0x05);
holdemRenderPlayer(0x06);
holdemRenderPlayer(0x07);
pitch = mathDeg2Rad(-90);
for(j = 0; j < HOLDEM_GAME_STATE.match.cardsFacing; j++) {
holdemRenderCard(HOLDEM_GAME_STATE.match.cards[j], j*0.2, 0, -0.2, pitch, 0, 0);
}
// pitch = mathDeg2Rad(-90);
// for(j = 0; j < HOLDEM_GAME_STATE.match.cardsFacing; j++) {
// holdemRenderCard(HOLDEM_GAME_STATE.match.cards[j], j*0.2, 0, -0.2, pitch, 0, 0);
// }
// for(i = 0; i < HOLDEM_PLAYER_COUNT; i++) {
// player = HOLDEM_GAME_STATE.match.players + i;
// if(player->state & HOLDEM_STATE_FOLDED) continue;
// sprintf(name, "Player %i", i);
for(i = 0; i < HOLDEM_PLAYER_COUNT; i++) {
player = HOLDEM_GAME_STATE.match.players + i;
if(player->state & HOLDEM_STATE_FOLDED) continue;
sprintf(name, "Player %i", i);
// shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.fontTexture);
// spriteBatchFlush(HOLDEM_GAME_STATE.fontBatch);
// shaderUsePosition(GAME_STATE.shaderWorld, -0.1,0,i*0.2, mathDeg2Rad(-90),0,0);
// fontSpriteBatchBuffer(
// HOLDEM_GAME_STATE.fontBatch,
// HOLDEM_GAME_STATE.fontTileset,
// name, FONT_RIGHT_X, FONT_CENTER_Y, 0, -1, 0.1
// );
// spriteBatchDraw(HOLDEM_GAME_STATE.fontBatch, 0, -1);
shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.fontTexture);
spriteBatchFlush(HOLDEM_GAME_STATE.fontBatch);
shaderUsePosition(GAME_STATE.shaderWorld, -0.1,0,i*0.2, mathDeg2Rad(-90),0,0);
fontSpriteBatchBuffer(
HOLDEM_GAME_STATE.fontBatch,
HOLDEM_GAME_STATE.fontTileset,
name, FONT_RIGHT_X, FONT_CENTER_Y, 0, -1, 0.1
);
spriteBatchDraw(HOLDEM_GAME_STATE.fontBatch, 0, -1);
// for(j = 0; j < HOLDEM_PLAYER_HAND; j++) {
// // pitch = mathDeg2Rad(player->state & HOLDEM_STATE_SHOWING ? -90 : 90);
// holdemRenderCard(player->cards[j], j*0.2, 0, i*0.2, pitch, 0, 0);
// }
// }
for(j = 0; j < HOLDEM_PLAYER_HAND; j++) {
// pitch = mathDeg2Rad(player->state & HOLDEM_STATE_SHOWING ? -90 : 90);
holdemRenderCard(player->cards[j], j*0.2, 0, i*0.2, pitch, 0, 0);
}
}
// shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.fontTexture);
// spriteBatchFlush(HOLDEM_GAME_STATE.fontBatch);
// shaderUsePosition(GAME_STATE.shaderWorld, -0.1,0,-0.2, mathDeg2Rad(-90),0,0);
// fontSpriteBatchBuffer(
// HOLDEM_GAME_STATE.fontBatch,
// HOLDEM_GAME_STATE.fontTileset,
// "Dealer", FONT_RIGHT_X, FONT_CENTER_Y, 0, -1, 0.1
// );
// spriteBatchDraw(HOLDEM_GAME_STATE.fontBatch, 0, -1);
shaderUseTexture(GAME_STATE.shaderWorld, HOLDEM_GAME_STATE.fontTexture);
spriteBatchFlush(HOLDEM_GAME_STATE.fontBatch);
shaderUsePosition(GAME_STATE.shaderWorld, -0.1,0,-0.2, mathDeg2Rad(-90),0,0);
fontSpriteBatchBuffer(
HOLDEM_GAME_STATE.fontBatch,
HOLDEM_GAME_STATE.fontTileset,
"Dealer", FONT_RIGHT_X, FONT_CENTER_Y, 0, -1, 0.1
);
spriteBatchDraw(HOLDEM_GAME_STATE.fontBatch, 0, -1);
// Draw the players
float playerY = 0.34;
holdemRenderPlayer(0, playerY, -1, 0);
// holdemRenderPlayer(-1, playerY, -0, 90);
// holdemRenderPlayer(-0.75, playerY, 0.75, -45);
// holdemRenderPlayer(0.75, playerY, 0.75, 45);
// holdemRenderPlayer(1, playerY, 0, -90);
}

View File

@ -29,13 +29,33 @@ void holdemRenderInit();
*/
void holdemRender();
void holdemLookSeat(camera_t *camera, uint8_t seat);
void holdemLookHand(camera_t *camera, uint8_t seat);
/**
* Look at a specific seat
*
* @param camera Camera to adjust.
* @param seat Seat to look at.
*/
void holdemRenderLookSeat(camera_t *camera, uint8_t seat);
void holdemRenderPlayer(float x, float y, float z, float yaw);
/**
* Look at a specific seats hand.
*
* @param camera Camera to adjust.
* @param seat Seats hand to look at.
*/
void holdemRenderLookHand(camera_t *camera, uint8_t seat);
void holdemRenderCard(card_t card,
float x, float y, float z, float pitch, float yaw, float roll
);
/**
* Renders a Teax Hold'em player
*
* @param seat Seat that the player sits at.
*/
void holdemRenderPlayer(uint8_t seat);
// void holdemRenderCard(card_t card,
// float x, float y, float z, float pitch, float yaw, float roll
// );
void holdemRenderCard(uint8_t seat, card_t card);
void holdemRenderWorld();

View File

@ -126,15 +126,15 @@ void shaderUsePosition(shader_t *shader,
//Position
axis[0] = x, axis[1] = y, axis[2] = z;
glm_translate(MATRIX_POSITION, axis);
glm_translate_make(MATRIX_POSITION, axis);
//Rotation, we do each axis individually
axis[0] = 1, axis[1] = 0, axis[2] = 0;
glm_rotate(MATRIX_POSITION, pitch, axis);
axis[0] = 0, axis[1] = 1;
// Rotation (YZX order)
axis[0] = 0, axis[1] = 1, axis[2] = 0;
glm_rotate(MATRIX_POSITION, yaw, axis);
axis[1] = 0, axis[2] = 1;
glm_rotate(MATRIX_POSITION, roll, axis);
axis[0] = 1, axis[2] = 0;
glm_rotate(MATRIX_POSITION, pitch, axis);
//Send to the shader.
glUniformMatrix4fv(shader->uniModl, 1, GL_FALSE, MATRIX_POSITION[0]);
@ -151,17 +151,17 @@ void shaderUsePositionAndScale(shader_t *shader,
// Identify mat.
glm_mat4_identity(MATRIX_POSITION);
// Position
//Position
axis[0] = x, axis[1] = y, axis[2] = z;
glm_translate(MATRIX_POSITION, axis);
glm_translate_make(MATRIX_POSITION, axis);
// Rotation
axis[0] = 1, axis[1] = 0, axis[2] = 0;
glm_rotate(MATRIX_POSITION, pitch, axis);
axis[0] = 0, axis[1] = 1;
// Rotation (YZX order)
axis[0] = 0, axis[1] = 1, axis[2] = 0;
glm_rotate(MATRIX_POSITION, yaw, axis);
axis[1] = 0, axis[2] = 1;
glm_rotate(MATRIX_POSITION, roll, axis);
axis[0] = 1, axis[2] = 0;
glm_rotate(MATRIX_POSITION, pitch, axis);
// Scale
axis[0] = scaleX, axis[1] = scaleY, axis[2] = scaleZ;

View File

@ -48,7 +48,7 @@ void shaderUseTexture(shader_t *shader, texture_t *texture);
/**
* Set's the current translation matrix onto the shader for the next
* render to use.
* render to use. Rotation order is set to YZX.
*
* @param shader Shader to attach to.
* @param x X coordinate (world space).

View File

@ -34,7 +34,7 @@ bool gameUpdate(float platformDelta) {
gameTimeUpdate(platformDelta);
renderFrameStart();
inputUpdate();
shaderUse(GAME_STATE.shaderWorld);// TODO: remove
holdemGameUpdate();

View File

@ -13,6 +13,11 @@
#include "../input/input.h"
#include "../card/poker/holdemgame.h"
#include "../display/primitive.h"
#include "../display/primitives/cube.h"
#include "../display/texture.h"
#include "../util/math.h"
/**
* Initialize the game context.
*