Character is rendering in-game
This commit is contained in:
@ -7,14 +7,16 @@
|
||||
|
||||
#include "vncharacter.h"
|
||||
|
||||
|
||||
void vnCharacterInit(
|
||||
vncharacter_t *character, texture_t *texture,
|
||||
int32_t baseWidth, int32_t baseHeight,
|
||||
int32_t faceX, int32_t faceY,
|
||||
int32_t faceWidth, int32_t faceHeight
|
||||
) {
|
||||
character->x = 0;
|
||||
character->y = 0;
|
||||
character->z = 0;
|
||||
character->x = 0.5f;
|
||||
character->y = -1.17f;
|
||||
character->z = -0.35f;
|
||||
|
||||
character->yaw = 0;
|
||||
character->pitch = 0;
|
||||
@ -23,97 +25,115 @@ void vnCharacterInit(
|
||||
character->scaleX = 1;
|
||||
character->scaleY = 1;
|
||||
|
||||
character->talking = false;
|
||||
character->texture = texture;
|
||||
character->talking = true;
|
||||
character->blinkStart = 0;
|
||||
|
||||
// Init the primitive.
|
||||
character->texture = texture;
|
||||
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;
|
||||
character->faceY = faceY;
|
||||
character->faceWidth = faceWidth;
|
||||
character->faceHeight = faceHeight;
|
||||
|
||||
// Buffer the base quad, this never changes (currently)
|
||||
quadBuffer(&character->primitive, 0,
|
||||
0,0,0,0,
|
||||
((float)baseWidth / (float)baseHeight), baseHeight, 1, 1,
|
||||
0, 0
|
||||
_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);
|
||||
}
|
||||
|
||||
// character->blinkStart = randFloatRange(0, VN_CHARACTER_BLINK_TIME_RANGE_MAX);
|
||||
void _vnCharacterBuffer(vncharacter_t *character,
|
||||
int32_t x, int32_t y, int32_t width, int32_t height, int32_t tx, int32_t ty,
|
||||
int32_t i
|
||||
) {
|
||||
// Calc size for each pixel.
|
||||
float ps = 1.0f / (float)character->baseHeight;// Prefer Height
|
||||
float tpx = 1.0f / (float)character->texture->width;
|
||||
float tpy = 1.0f / (float)character->texture->height;
|
||||
|
||||
// character->name = "";
|
||||
// Center on the X axis
|
||||
x -= (float)character->baseWidth / 2.0f;
|
||||
|
||||
// // Setup Textures
|
||||
// character->textureEyes = textureEyes;
|
||||
// character->textureBody = textureBody;
|
||||
// character->textureMouth = textureMouth;
|
||||
// character->textureFace = textureFace;
|
||||
// Put on the feet
|
||||
y -= character->baseHeight;
|
||||
|
||||
// // Tileset
|
||||
// tilesetInit(&character->tilesetEyes, 1, 6,
|
||||
// textureEyes->width, textureEyes->height,
|
||||
// 0, 0, 0, 0
|
||||
// );
|
||||
// tilesetInit(&character->tilesetMouth, 1, 11,
|
||||
// textureMouth->width, textureMouth->height,
|
||||
// 0, 0, 0, 0
|
||||
// );
|
||||
quadBuffer(&character->primitive, 0.001f * (float)i,
|
||||
(float)x * ps, 1 - (float)y * ps,
|
||||
(float)tx * tpx, (float)ty * tpy,
|
||||
(float)(x + width) * ps, 1 - (float)(y + height) * ps,
|
||||
(float)(tx + width) * tpx, (float)(ty + height) * tpy,
|
||||
i * QUAD_VERTICE_COUNT, i * QUAD_INDICE_COUNT
|
||||
);
|
||||
}
|
||||
|
||||
// vnCharacterSetEyes(character, 0);
|
||||
// vnCharacterSetMouth(character, 9);
|
||||
|
||||
// div.x0 = 0, div.x1 = 1;
|
||||
// div.y0 = 0, div.y1 = 1;
|
||||
|
||||
// _vnCharacterQuad(&character->primitiveBody, &div);
|
||||
// _vnCharacterQuad(&character->primitiveFace, &div);
|
||||
void _vnCharacterFaceBuffer(vncharacter_t *character,
|
||||
int32_t col, int32_t row, int32_t i
|
||||
) {
|
||||
_vnCharacterBuffer(character,
|
||||
character->faceX, character->faceY,
|
||||
character->faceWidth, character->faceHeight,
|
||||
character->baseWidth + (character->faceWidth * col),
|
||||
character->faceHeight * row,
|
||||
i
|
||||
);
|
||||
}
|
||||
|
||||
void vnCharacterUpdate(vncharacter_t *character, engine_t *engine) {
|
||||
// float n;
|
||||
float n;
|
||||
|
||||
// // Update the blinking frames
|
||||
// n = (engine->time.current - character->blinkStart) * 1.5;
|
||||
// if(n >= 1) {
|
||||
// character->blinkStart = engine->time.current + randFloatRange(
|
||||
// 1, VN_CHARACTER_BLINK_TIME_RANGE_MAX
|
||||
// );
|
||||
// } else if(n > 0) {
|
||||
// n = easeInQuad(easeTimeToForwardAndBackward(n) * 2);
|
||||
// vnCharacterSetEyes(character, n * character->tilesetEyes.count);
|
||||
// }
|
||||
// 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
|
||||
);
|
||||
}
|
||||
|
||||
// // Updating the talking frames
|
||||
// if(character->talking) {
|
||||
// vnCharacterSetMouth(character,
|
||||
// (int32_t)(engine->time.current*12) % character->tilesetMouth.count
|
||||
// );
|
||||
// } else {
|
||||
// vnCharacterSetMouth(character, 9);
|
||||
// }
|
||||
// Updating the talking frames
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
// // Update the scale frames
|
||||
// float speed, amount;
|
||||
// if(character->talking) {
|
||||
// speed = 2.5;
|
||||
// amount = 100;
|
||||
// n = easeTimeToForwardAndBackward(fmod(engine->time.current, 1 / speed) * speed) * 2;
|
||||
// n = easeInOutQuad(n) / amount - (1/(amount*2));
|
||||
// character->scaleX = 1 + n;
|
||||
// character->scaleY = 1 - n;
|
||||
// } else {
|
||||
// speed = 10;
|
||||
// amount = 50;
|
||||
// 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;
|
||||
// }
|
||||
// Update the scale frames for talking/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;
|
||||
}
|
||||
|
||||
void vnCharacterRender(vncharacter_t *character, shader_t *shader) {
|
||||
@ -125,4 +145,8 @@ void vnCharacterRender(vncharacter_t *character, shader_t *shader) {
|
||||
|
||||
shaderUseTexture(shader, character->texture);
|
||||
primitiveDraw(&character->primitive, 0, -1);
|
||||
}
|
||||
|
||||
void vnCharacterDispose(vncharacter_t *character) {
|
||||
primitiveDispose(&character->primitive);
|
||||
}
|
Reference in New Issue
Block a user