Added the dealer proper.
This commit is contained in:
20
src/display/animation/animation.c
Normal file
20
src/display/animation/animation.c
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "animation.h"
|
||||
|
||||
float animForwardAndBackward(float t) {
|
||||
return (t < 0.5 ? t : 1 - t);
|
||||
}
|
||||
|
||||
float animForwardAndBackwardScaled(float t) {
|
||||
return animForwardAndBackward(t) * 2.0f;
|
||||
}
|
||||
|
||||
float animTimeScaleFromFrameTime(int32_t frames, float time) {
|
||||
return 1.0f / (float)frames / time;
|
||||
}
|
37
src/display/animation/animation.h
Normal file
37
src/display/animation/animation.h
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include <dawn/dawn.h>
|
||||
|
||||
/**
|
||||
* Animation tool for converting 0-1 space into a 0-0.5 back to zero space. This
|
||||
* is intended to make a "Forward then backwards" effect for animation. This
|
||||
* method will not scale t.
|
||||
* @param t Time in space to back and fourth on between 0 and 1.
|
||||
* @returns Forward and backwards time. 0 to 0.5 are as such, 0.5 to 1 are from
|
||||
* 0.5 to 0.
|
||||
*/
|
||||
float animForwardAndBackward(float t);
|
||||
|
||||
/**
|
||||
* Animation tool for converting 0-1 space into a 0-1-0 space. Scaled version of
|
||||
* animForwardAndBackward().
|
||||
* @param t Time in space to back and fourth on between 0 and 1.
|
||||
* @returns Forward and backwards time.
|
||||
*/
|
||||
float animForwardAndBackwardScaled(float t);
|
||||
|
||||
/**
|
||||
* Returns the time scale (speed to multiply time range by) for a given frame
|
||||
* time and frame count. E.g. 3 frames at 0.5 time each would have a time scale
|
||||
* of 1.5.
|
||||
*
|
||||
* @param frames Frames to get the scale of.
|
||||
* @param time Time to get the scale of.
|
||||
* @return The time scale.
|
||||
*/
|
||||
float animTimeScaleFromFrameTime(int32_t frames, float time);
|
@ -13,7 +13,7 @@ void skywallInit(primitive_t *primitive) {
|
||||
vertice_t vertices[SKYWALL_VERTICE_COUNT];
|
||||
indice_t indices[SKYWALL_INDICE_COUNT];
|
||||
int32_t n, i, j;
|
||||
float x, z, p, r;
|
||||
float x, y, z, p, r;
|
||||
|
||||
// For each slice. We iterate slices+1 to do the wrapping mentioned below.
|
||||
for(i = 0; i < SKYWALL_SLICE_COUNT+1; i++) {
|
||||
@ -33,12 +33,13 @@ void skywallInit(primitive_t *primitive) {
|
||||
// Determine the X/Z for the given radian
|
||||
x = SKYWALL_SIZE * (float)cos(r);
|
||||
z = SKYWALL_SIZE * (float)sin(r);
|
||||
y = SKYWALL_SIZE * 1.333f;
|
||||
|
||||
// Get the start index for the ertices
|
||||
n = i * SKYWALL_VERTICES_PER_SLICE;
|
||||
vertices[n].x = x, vertices[n].y = -SKYWALL_SIZE, vertices[n].z = z;
|
||||
vertices[n].x = x, vertices[n].y = -y, vertices[n].z = z;
|
||||
vertices[n].u = p, vertices[n].v = 1;
|
||||
vertices[n+1].x = x, vertices[n+1].y = SKYWALL_SIZE, vertices[n+1].z = z;
|
||||
vertices[n+1].x = x, vertices[n+1].y = y, vertices[n+1].z = z;
|
||||
vertices[n+1].u = p, vertices[n+1].v = 0;
|
||||
|
||||
if(i == SKYWALL_SLICE_COUNT) continue;
|
||||
|
@ -23,6 +23,6 @@
|
||||
#define SKYWALL_INDICE_COUNT SKYWALL_INDICES_PER_SLICE*SKYWALL_SLICE_COUNT
|
||||
|
||||
/** How big the skywall cylinder is */
|
||||
#define SKYWALL_SIZE 100
|
||||
#define SKYWALL_SIZE 10
|
||||
|
||||
void skywallInit(primitive_t *primitive);
|
@ -26,7 +26,16 @@ bool pokerGameInit(game_t *game) {
|
||||
1000, 1920,
|
||||
367,256, 280,280
|
||||
);
|
||||
pokerGame->scene.characterCount = 1;
|
||||
|
||||
vnCharacterInit(pokerGame->scene.characters + 1, &pokerGame->assets.pennyTexture,
|
||||
1000, 1920,
|
||||
367,256, 280,280
|
||||
);
|
||||
(pokerGame->scene.characters + 0)->x -= 0.3f;
|
||||
(pokerGame->scene.characters + 1)->x += 0.3f;
|
||||
(pokerGame->scene.characters + 1)->talking = true;
|
||||
|
||||
pokerGame->scene.characterCount = 2;
|
||||
|
||||
|
||||
// Initialize the UI.
|
||||
|
@ -14,9 +14,9 @@ void vnCharacterInit(
|
||||
int32_t faceX, int32_t faceY,
|
||||
int32_t faceWidth, int32_t faceHeight
|
||||
) {
|
||||
character->x = 0.5f;
|
||||
character->y = -1.17f;
|
||||
character->z = -0.35f;
|
||||
character->x = 0;
|
||||
character->y = -2.2f;
|
||||
character->z = -0.3f;
|
||||
|
||||
character->yaw = 0;
|
||||
character->pitch = 0;
|
||||
@ -26,16 +26,9 @@ void vnCharacterInit(
|
||||
character->scaleY = 1;
|
||||
|
||||
character->texture = texture;
|
||||
character->talking = true;
|
||||
character->talking = false;
|
||||
character->blinkStart = 0;
|
||||
|
||||
// Init the primitive.
|
||||
primitiveInit(&character->primitive,
|
||||
QUAD_VERTICE_COUNT * VN_CHARACTER_QUAD_COUNT,
|
||||
QUAD_INDICE_COUNT * VN_CHARACTER_QUAD_COUNT
|
||||
);
|
||||
|
||||
|
||||
character->baseWidth = baseWidth;
|
||||
character->baseHeight = baseHeight;
|
||||
character->faceX = faceX;
|
||||
@ -43,13 +36,21 @@ void vnCharacterInit(
|
||||
character->faceWidth = faceWidth;
|
||||
character->faceHeight = faceHeight;
|
||||
|
||||
character->emotion = VN_CHARACTER_EMOTION_HAPPY;
|
||||
|
||||
// Init the primitive.
|
||||
primitiveInit(&character->primitive,
|
||||
QUAD_VERTICE_COUNT * VN_CHARACTER_QUAD_COUNT,
|
||||
QUAD_INDICE_COUNT * VN_CHARACTER_QUAD_COUNT
|
||||
);
|
||||
|
||||
// Buffer the base quad, this never changes (currently)
|
||||
_vnCharacterBuffer(character,
|
||||
0, 0, baseWidth, baseHeight, 0, 0, 0
|
||||
);
|
||||
_vnCharacterFaceBuffer(character, 0, 0, VN_CHARACTER_QUAD_EYEBROWS);
|
||||
_vnCharacterFaceBuffer(character, 0, 1, VN_CHARACTER_QUAD_EYES);
|
||||
_vnCharacterFaceBuffer(character, 0, 2, VN_CHARACTER_QUAD_MOUTH);
|
||||
_vnCharacterFaceBuffer(character, 0, VN_CHARACTER_QUAD_EYEBROWS);
|
||||
_vnCharacterFaceBuffer(character, 0, VN_CHARACTER_QUAD_EYES);
|
||||
_vnCharacterFaceBuffer(character, 0, VN_CHARACTER_QUAD_MOUTH);
|
||||
}
|
||||
|
||||
void _vnCharacterBuffer(vncharacter_t *character,
|
||||
@ -77,63 +78,78 @@ void _vnCharacterBuffer(vncharacter_t *character,
|
||||
}
|
||||
|
||||
void _vnCharacterFaceBuffer(vncharacter_t *character,
|
||||
int32_t col, int32_t row, int32_t i
|
||||
int32_t col, int32_t i
|
||||
) {
|
||||
_vnCharacterBuffer(character,
|
||||
character->faceX, character->faceY,
|
||||
character->faceWidth, character->faceHeight,
|
||||
character->baseWidth + (character->faceWidth * col),
|
||||
character->faceHeight * row,
|
||||
character->faceHeight * (i -1),
|
||||
i
|
||||
);
|
||||
}
|
||||
|
||||
void vnCharacterUpdate(vncharacter_t *character, engine_t *engine) {
|
||||
float n;
|
||||
uint8_t eyes, mouth, eyebrows;
|
||||
float t;
|
||||
|
||||
// Update the blinking frames
|
||||
n = (engine->time.current - character->blinkStart) * 3.0f;
|
||||
if(n > 1.0f) {
|
||||
character->blinkStart = engine->time.current + randFloatRange(
|
||||
1, VN_CHARACTER_BLINK_TIME_RANGE_MAX
|
||||
);
|
||||
} else if(n > 0) {
|
||||
n = easeInQuad(easeTimeToForwardAndBackward(n) * 4);
|
||||
_vnCharacterFaceBuffer(character,
|
||||
(int32_t)n, 1, VN_CHARACTER_QUAD_EYES
|
||||
);
|
||||
}
|
||||
// Setup frames based on the emotion.
|
||||
mouth = character->emotion % 0x04;
|
||||
eyes = (character->emotion/0x04) % 0x04;
|
||||
eyebrows = ((character->emotion/0x04)/0x04) % 0x05;
|
||||
|
||||
// Updating the talking frames
|
||||
_vnCharacterFaceBuffer(character, eyebrows, VN_CHARACTER_QUAD_EYEBROWS);
|
||||
_vnCharacterFaceBuffer(character, eyes, VN_CHARACTER_QUAD_EYES);
|
||||
|
||||
mouth *= VN_CHARACTER_TALKING_FRAME_COUNT;
|
||||
if(character->talking) {
|
||||
n = easeTimeToForwardAndBackward(fmod(engine->time.current * 1.6, 1)) * 6;
|
||||
_vnCharacterFaceBuffer(character,
|
||||
(int32_t)n, 2, VN_CHARACTER_QUAD_MOUTH
|
||||
);
|
||||
} else {
|
||||
_vnCharacterFaceBuffer(character,
|
||||
0, 2, VN_CHARACTER_QUAD_MOUTH
|
||||
);
|
||||
t = animForwardAndBackwardScaled(mathModFloat(
|
||||
engine->time.current * animTimeScaleFromFrameTime(3, 0.2f), 1.0f
|
||||
));
|
||||
mouth += (uint8_t)(t * VN_CHARACTER_TALKING_FRAME_COUNT);
|
||||
}
|
||||
_vnCharacterFaceBuffer(character, mouth, VN_CHARACTER_QUAD_MOUTH);
|
||||
|
||||
// Update the scale frames for talking/breathing
|
||||
|
||||
|
||||
|
||||
|
||||
// float n;
|
||||
// // Update the blinking frames
|
||||
// n = (engine->time.current - character->blinkStart) * 3.0f;
|
||||
// if(n > 1.0f) {
|
||||
// character->blinkStart = engine->time.current + randFloatRange(
|
||||
// 1, VN_CHARACTER_BLINK_TIME_RANGE_MAX
|
||||
// );
|
||||
// } else if(n > 0) {
|
||||
// n = easeInQuad(easeTimeToForwardAndBackward(n) * 4);
|
||||
// _vnCharacterFaceBuffer(character,
|
||||
// (int32_t)n, 1, VN_CHARACTER_QUAD_EYES
|
||||
// );
|
||||
// }
|
||||
// if(character->talking) {
|
||||
// n = easeTimeToForwardAndBackward(
|
||||
// mathModFloat(engine->time.current * 1.6, 1)
|
||||
// ) * 6.0f;
|
||||
// _vnCharacterFaceBuffer(character,
|
||||
// (int32_t)n, 2, VN_CHARACTER_QUAD_MOUTH
|
||||
// );
|
||||
// } else {
|
||||
// _vnCharacterFaceBuffer(character,
|
||||
// 0, 2, VN_CHARACTER_QUAD_MOUTH
|
||||
// );
|
||||
// }
|
||||
|
||||
// Update the scale frames for breathing / talk breathing
|
||||
float speed, amount;
|
||||
if(character->talking) {
|
||||
speed = 1.0f;
|
||||
amount = 400.0f;
|
||||
} else {
|
||||
speed = 0.4f;
|
||||
amount = 400.0f;
|
||||
// n = easeTimeToForwardAndBackward(fmod(engine->time.current, speed) / speed)*2;
|
||||
// n = easeInOutCubic(n) / amount - (1/(amount*2));
|
||||
// character->scaleX = 1 + n;
|
||||
// character->scaleY = 1 + n*2;
|
||||
}
|
||||
|
||||
n = easeTimeToForwardAndBackward(fmod(engine->time.current, 1 / speed) * speed) * 2.0f;
|
||||
n = easeInOutQuad(n) / amount - (1/(amount*2));
|
||||
character->scaleX = 1 + n;
|
||||
character->scaleY = 1 - n;
|
||||
speed = 0.2f;
|
||||
amount = 300.0f;
|
||||
t = animForwardAndBackwardScaled(
|
||||
mathModFloat(engine->time.current, 1 / speed) * speed
|
||||
);
|
||||
t = easeInOutQuad(t) / amount - (1/(amount*2));
|
||||
character->scaleX = 1 + t;
|
||||
character->scaleY = 1 - t;
|
||||
}
|
||||
|
||||
void vnCharacterRender(vncharacter_t *character, shader_t *shader) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "../display/primitive.h"
|
||||
#include "../display/shader.h"
|
||||
#include "../display/primitives/quad.h"
|
||||
#include "../display/animation/animation.h"
|
||||
|
||||
/**
|
||||
* Initialize a VN Character.
|
||||
@ -55,12 +56,9 @@ void _vnCharacterBuffer(vncharacter_t *character,
|
||||
*
|
||||
* @param character Character to buffer to.
|
||||
* @param col Face Column.
|
||||
* @param row Face Row.
|
||||
* @param i Quad index to buffer to.
|
||||
*/
|
||||
void _vnCharacterFaceBuffer(vncharacter_t *character,
|
||||
int32_t col, int32_t row, int32_t i
|
||||
);
|
||||
void _vnCharacterFaceBuffer(vncharacter_t *character, int32_t col, int32_t i);
|
||||
|
||||
void vnCharacterUpdate(vncharacter_t *character, engine_t *engine);
|
||||
void vnCharacterRender(vncharacter_t *character, shader_t *shader);
|
||||
|
@ -35,8 +35,8 @@ void vnSceneDispose(vnscene_t *scene) {
|
||||
void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader) {
|
||||
// Adjust 3D Space position
|
||||
cameraLookAt(&scene->camera,
|
||||
0.5, 0.5, 0.75,
|
||||
0.5, 0.5, -0.5
|
||||
0.5, -0.5f, 0.5f,
|
||||
0.5, -0.5f, -0.5
|
||||
);
|
||||
|
||||
// Set Camera Perspective
|
||||
|
Reference in New Issue
Block a user