mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-07-21 23:04:53 -04:00
Mirrored rendering by libvitaboy Renderer
The next task is to add functionality to the far library to make it suitable for use directly by libvitaboy Renderer.# Please enter the commit message for your changes. Lines starting
This commit is contained in:
parent
6393955683
commit
bb904c4698
14 changed files with 116 additions and 75 deletions
|
@ -148,6 +148,7 @@ static int InitGL()
|
|||
glDisable(GL_BLEND);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
glFrontFace(GL_CW);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -160,6 +161,7 @@ static int ResizeScene(uint16_t width, uint16_t height)
|
|||
|
||||
// Calculate The Aspect Ratio Of The Window
|
||||
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);
|
||||
// glScalef(-1.0f, 1.0f, 1.0f);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
@ -300,28 +302,17 @@ static void AdvanceFrame(Skeleton_t& Skeleton, Animation_t& Animation, float Tim
|
|||
Rotation_t& Rotation = Animation.Motions[i].Rotations[Frame];
|
||||
Rotation_t& NextRotation = Animation.Motions[i].Rotations[NextFrame];
|
||||
|
||||
//Use Slerp to interpolate
|
||||
float w1, w2 = 1;
|
||||
float cosTheta = DotProduct(&Rotation, &NextRotation);
|
||||
if(cosTheta < 0){
|
||||
cosTheta *= -1;
|
||||
w2 *= -1;
|
||||
}
|
||||
float theta = (float) acos(cosTheta);
|
||||
float sinTheta = (float) sin(theta);
|
||||
|
||||
if(sinTheta > 0.001f){
|
||||
w1 = (float) sin((1.0f-FractionShown)*theta)/sinTheta;
|
||||
w2 *= (float) sin(FractionShown *theta)/sinTheta;
|
||||
} else {
|
||||
w1 = 1.0f - FractionShown;
|
||||
w2 = FractionShown;
|
||||
}
|
||||
//Use nlerp to interpolate
|
||||
float w1 = 1.0f - FractionShown, w2 = FractionShown;
|
||||
if(DotProduct(&Rotation, &NextRotation) < 0)
|
||||
w1 *= -1;
|
||||
|
||||
Bone.Rotation.x = w1*Rotation.x + w2*NextRotation.x;
|
||||
Bone.Rotation.y = w1*Rotation.y + w2*NextRotation.y;
|
||||
Bone.Rotation.z = w1*Rotation.z + w2*NextRotation.z;
|
||||
Bone.Rotation.w = w1*Rotation.w + w2*NextRotation.w;
|
||||
|
||||
Normalize(&Bone.Rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ void ReadMotion(Animation_t& Animation, Motion_t& Motion){
|
|||
unsigned pos = VBFile.getpos();
|
||||
VBFile.seekto(Animation.TranslationsOffset + 12*Motion.FirstTranslation);
|
||||
for(unsigned i=0; i<Motion.FrameCount; i++){
|
||||
Motion.Translations[i].x = VBFile.readfloat();
|
||||
Motion.Translations[i].x = -VBFile.readfloat();
|
||||
Motion.Translations[i].y = VBFile.readfloat();
|
||||
Motion.Translations[i].z = VBFile.readfloat();
|
||||
}
|
||||
|
@ -94,8 +94,8 @@ void ReadMotion(Animation_t& Animation, Motion_t& Motion){
|
|||
VBFile.seekto(Animation.RotationsOffset + 16*Motion.FirstRotation);
|
||||
for(unsigned i=0; i<Motion.FrameCount; i++){
|
||||
Motion.Rotations[i].x = VBFile.readfloat();
|
||||
Motion.Rotations[i].y = VBFile.readfloat();
|
||||
Motion.Rotations[i].z = VBFile.readfloat();
|
||||
Motion.Rotations[i].y = -VBFile.readfloat();
|
||||
Motion.Rotations[i].z = -VBFile.readfloat();
|
||||
Motion.Rotations[i].w = VBFile.readfloat();
|
||||
}
|
||||
VBFile.seekto(pos);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include "libvitaboy.hpp"
|
||||
|
||||
VBFile_t VBFile;
|
||||
|
@ -51,6 +52,17 @@ float DotProduct(Rotation_t * q1, Rotation_t * q2){
|
|||
return q1->x*q2->x + q1->y*q2->y + q1->z*q2->z + q1->w*q2->w;
|
||||
}
|
||||
|
||||
void Normalize(Rotation_t * q){
|
||||
float magnitude = q->x*q->x + q->y*q->y + q->z*q->z + q->w*q->w;
|
||||
if(magnitude != 0){
|
||||
magnitude = 1.0f/sqrt(magnitude);
|
||||
q->x *= magnitude;
|
||||
q->y *= magnitude;
|
||||
q->z *= magnitude;
|
||||
q->w *= magnitude;
|
||||
}
|
||||
}
|
||||
|
||||
void FindQuaternionMatrix(float * Matrix, Rotation_t * Quaternion){
|
||||
float x2 = Quaternion->x * Quaternion->x;
|
||||
float y2 = Quaternion->y * Quaternion->y;
|
||||
|
|
|
@ -25,6 +25,10 @@
|
|||
#include <stdio.h>
|
||||
#include <FileHandler.hpp>
|
||||
|
||||
/****
|
||||
** Bytestream
|
||||
*/
|
||||
|
||||
class VBFile_t {
|
||||
private:
|
||||
const uint8_t *Buffer, *Position;
|
||||
|
@ -139,6 +143,7 @@ void ReadPropEntry(KeyValuePair_t& Entry);
|
|||
void ReadPropEntries(Prop_t& Prop);
|
||||
void ReadPropsList(PropsList_t& PropsList);
|
||||
float DotProduct(Rotation_t * q1, Rotation_t * q2);
|
||||
void Normalize(Rotation_t * q);
|
||||
void CombineQuaternions(Rotation_t * Destination, Rotation_t * Source);
|
||||
void FindQuaternionMatrix(float * Matrix, Rotation_t * Quaternion);
|
||||
|
||||
|
@ -214,6 +219,7 @@ struct Appearance_t {
|
|||
|
||||
void ReadAppearance(Appearance_t& Appearance);
|
||||
|
||||
|
||||
/****
|
||||
** Binding (*.bnd)
|
||||
*/
|
||||
|
|
|
@ -72,10 +72,10 @@ void ReadMesh(Mesh_t& Mesh){
|
|||
Mesh.VertexData = (Vertex_t*) malloc(Mesh.TotalVertexCount * sizeof(Vertex_t));
|
||||
Mesh.TransformedVertexData = (Vertex_t*) malloc(Mesh.TotalVertexCount * sizeof(Vertex_t));
|
||||
for(unsigned i=0; i<Mesh.TotalVertexCount; i++){
|
||||
Mesh.VertexData[i].Coord.x = VBFile.readfloat();
|
||||
Mesh.VertexData[i].Coord.x = -VBFile.readfloat();
|
||||
Mesh.VertexData[i].Coord.y = VBFile.readfloat();
|
||||
Mesh.VertexData[i].Coord.z = VBFile.readfloat();
|
||||
Mesh.TransformedVertexData[i].NormalCoord.x = VBFile.readfloat();
|
||||
Mesh.TransformedVertexData[i].NormalCoord.x = -VBFile.readfloat();
|
||||
Mesh.TransformedVertexData[i].NormalCoord.y = VBFile.readfloat();
|
||||
Mesh.TransformedVertexData[i].NormalCoord.z = VBFile.readfloat();
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ void ReadBone(Skeleton_t& Skeleton, Bone_t& Bone, unsigned Index){
|
|||
}
|
||||
|
||||
printf(" | Translation:\n");
|
||||
Bone.Translation.x = VBFile.readfloat();
|
||||
Bone.Translation.x = -VBFile.readfloat();
|
||||
printf(" | | x: %g\n", Bone.Translation.x);
|
||||
Bone.Translation.y = VBFile.readfloat();
|
||||
printf(" | | y: %g\n", Bone.Translation.y);
|
||||
|
@ -58,9 +58,9 @@ void ReadBone(Skeleton_t& Skeleton, Bone_t& Bone, unsigned Index){
|
|||
printf(" | Rotation:\n");
|
||||
Bone.Rotation.x = VBFile.readfloat();
|
||||
printf(" | | x: %g\n", Bone.Rotation.x);
|
||||
Bone.Rotation.y = VBFile.readfloat();
|
||||
Bone.Rotation.y = -VBFile.readfloat();
|
||||
printf(" | | y: %g\n", Bone.Rotation.y);
|
||||
Bone.Rotation.z = VBFile.readfloat();
|
||||
Bone.Rotation.z = -VBFile.readfloat();
|
||||
printf(" | | z: %g\n", Bone.Rotation.z);
|
||||
Bone.Rotation.w = VBFile.readfloat();
|
||||
printf(" | | w: %g\n", Bone.Rotation.w);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue