From bb904c469869aa3deed19eaad2ac8038bb5a94c0 Mon Sep 17 00:00:00 2001 From: Fatbag Date: Sat, 27 Oct 2012 23:45:56 -0500 Subject: [PATCH] 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 --- Libraries/FileHandler/far/CMakeLists.txt | 2 +- Libraries/FileHandler/far/config.h | 32 ++++++------- Libraries/FileHandler/far/{libfar.c => far.c} | 46 +++++++++---------- Libraries/FileHandler/far/{libfar.h => far.h} | 10 ++-- Libraries/FileHandler/far/farextract.c | 8 ++-- Libraries/libvitaboy/Renderer.cpp | 25 ++++------ Libraries/libvitaboy/anim.cpp | 6 +-- Libraries/libvitaboy/libvitaboy.cpp | 12 +++++ Libraries/libvitaboy/libvitaboy.hpp | 6 +++ Libraries/libvitaboy/mesh.cpp | 4 +- Libraries/libvitaboy/skel.cpp | 6 +-- README.md | 2 +- Tools/Translate Tool/CMakeLists.txt | 0 Tools/Translate Tool/TranslateTool.hpp | 32 +++++++++++++ 14 files changed, 116 insertions(+), 75 deletions(-) rename Libraries/FileHandler/far/{libfar.c => far.c} (94%) rename Libraries/FileHandler/far/{libfar.h => far.h} (95%) create mode 100644 Tools/Translate Tool/CMakeLists.txt create mode 100644 Tools/Translate Tool/TranslateTool.hpp diff --git a/Libraries/FileHandler/far/CMakeLists.txt b/Libraries/FileHandler/far/CMakeLists.txt index 93dc44b..dad2be1 100644 --- a/Libraries/FileHandler/far/CMakeLists.txt +++ b/Libraries/FileHandler/far/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.6) project(far) set(FAR_SOURCES - libfar.c + far.c refpack_dec.c ) diff --git a/Libraries/FileHandler/far/config.h b/Libraries/FileHandler/far/config.h index c98611b..696a822 100644 --- a/Libraries/FileHandler/far/config.h +++ b/Libraries/FileHandler/far/config.h @@ -1,24 +1,24 @@ -/* config.h - libfar build configuration */ +/* config.h - far build configuration */ /* Define if you have the header file. */ #define HAVE_STDINT_H /* compile-in support */ -#define LIBFAR_ARCHIVEREAD -#define LIBFAR_ARCHIVEWRITE -#define LIBFAR_REFPACK_DECOMPRESS -#define LIBFAR_REFPACK_COMPRESS -#define LIBFAR_SUPPORT_FAR -#define LIBFAR_SUPPORT_DBPF -#define LIBFAR_SUPPORT_PERSIST -#define LIBFAR_DEBUGSUPPORT -#define LIBFAR_FILEIO -#define LIBFAR_EMBEDDEDFUNCTIONS +#define FAR_ARCHIVEREAD +#define FAR_ARCHIVEWRITE +#define FAR_REFPACK_DECOMPRESS +#define FAR_REFPACK_COMPRESS +#define FAR_SUPPORT_FAR +#define FAR_SUPPORT_DBPF +#define FAR_SUPPORT_PERSIST +#define FAR_DEBUGSUPPORT +#define FAR_FILEIO +#define FAR_EMBEDDEDFUNCTIONS /* end of compile-in support */ -/* preferences -- on non-numerical definitions, define to 1 for "yes", 0 for "no"; */ -#define LIBFAR_DEFAULT_1A 0 -#define LIBFAR_DEFAULT_DBPF_COMPRESSED 0 -#define LIBFAR_DEFAULT_MAX_FILE_NAME_LENGTH 255 -#define LIBFAR_DEFAULT_REFPACK_HNSV 0xFB +/* preferences -- on non-numerical definitions, define to 1 for "yes", 0 for "no" */ +#define FAR_DEFAULT_1A 0 +#define FAR_DEFAULT_DBPF_COMPRESSED 0 +#define FAR_DEFAULT_MAX_FILE_NAME_LENGTH 255 +#define FAR_DEFAULT_REFPACK_HNSV 0xFB /* end of default preferences */ diff --git a/Libraries/FileHandler/far/libfar.c b/Libraries/FileHandler/far/far.c similarity index 94% rename from Libraries/FileHandler/far/libfar.c rename to Libraries/FileHandler/far/far.c index f0eb198..b52bd00 100644 --- a/Libraries/FileHandler/far/libfar.c +++ b/Libraries/FileHandler/far/far.c @@ -22,14 +22,14 @@ #include #include -#include "libfar.h" +#include "far.h" -#if defined(LIBFAR_SUPPORT_PERSIST) - #define LIBFAR_MINSIZE_ANY MINSIZE_PERSIST -#elif defined(LIBFAR_SUPPORT_FAR) - #define LIBFAR_MINSIZE_ANY MINSIZE_FAR +#if defined(FAR_SUPPORT_PERSIST) + #define FAR_MINSIZE_ANY MINSIZE_PERSIST +#elif defined(FAR_SUPPORT_FAR) + #define FAR_MINSIZE_ANY MINSIZE_FAR #else - #define LIBFAR_MINSIZE_ANY MINSIZE_DBPF + #define FAR_MINSIZE_ANY MINSIZE_DBPF #endif #ifndef read_int32 @@ -52,10 +52,10 @@ /* These options can be changed during runtime */ static int libfarOptions[] = { - LIBFAR_DEFAULT_1A, - LIBFAR_DEFAULT_DBPF_COMPRESSED, - LIBFAR_DEFAULT_MAX_FILE_NAME_LENGTH, - LIBFAR_DEFAULT_REFPACK_HNSV + FAR_DEFAULT_1A, + FAR_DEFAULT_DBPF_COMPRESSED, + FAR_DEFAULT_MAX_FILE_NAME_LENGTH, + FAR_DEFAULT_REFPACK_HNSV }; void libfar_set_option(int Option, int Value){ @@ -68,22 +68,22 @@ int libfar_get_option(int Option){ int far_identify(const uint8_t * Buffer, unsigned FileSize) { if(!FileSize) FileSize = ~0; - else if(FileSize < LIBFAR_MINSIZE_ANY) + else if(FileSize < FAR_MINSIZE_ANY) return FAR_TYPE_INVALID; - #ifdef LIBFAR_SUPPORT_FAR + #ifdef FAR_SUPPORT_FAR if(FileSize >= MINSIZE_FAR) if(!memcmp(Buffer, Header_FAR, 8)) return FAR_TYPE_FAR; #endif - #ifdef LIBFAR_SUPPORT_DBPF + #ifdef FAR_SUPPORT_DBPF if(FileSize >= MINSIZE_DBPF) if(!memcmp(Buffer, Header_DBPF, 4)) return FAR_TYPE_DBPF; #endif - #ifdef LIBFAR_SUPPORT_PERSIST + #ifdef FAR_SUPPORT_PERSIST if(FileSize >= MINSIZE_PERSIST) if(Buffer[0] == 0x01) return FAR_TYPE_PERSIST; @@ -158,10 +158,10 @@ FAREntryNode * far_add_entry(FARFile * FARFileInfo, int Position) int far_read_header(FARFile * FARFileInfo, const uint8_t * Buffer, unsigned FileSize) { if(!FileSize) FileSize = ~0; - else if(FileSize < LIBFAR_MINSIZE_ANY) + else if(FileSize < FAR_MINSIZE_ANY) return 0; - #ifdef LIBFAR_SUPPORT_FAR + #ifdef FAR_SUPPORT_FAR if(FARFileInfo->Type == FAR_TYPE_FAR){ FARFileInfo->MajorVersion = read_uint32(Buffer+8); FARFileInfo->IndexOffset = read_uint32(Buffer+12); @@ -170,7 +170,7 @@ int far_read_header(FARFile * FARFileInfo, const uint8_t * Buffer, unsigned File return 0; if(FARFileInfo->MajorVersion == 1) - FARFileInfo->Revision = !libfarOptions[LIBFAR_CONFIG_DEFAULT_TO_1A]; + FARFileInfo->Revision = !libfarOptions[FAR_CONFIG_DEFAULT_TO_1A]; if(FARFileInfo->IndexOffset > FileSize-4) return 0; @@ -187,7 +187,7 @@ int far_read_header(FARFile * FARFileInfo, const uint8_t * Buffer, unsigned File } #endif - #ifdef LIBFAR_SUPPORT_DBPF + #ifdef FAR_SUPPORT_DBPF if(FARFileInfo->Type == FAR_TYPE_DBPF){ int i; @@ -239,7 +239,7 @@ int far_read_entry(const FARFile * FARFileInfo, FAREntry * FAREntryInfo, if(MaxEntrySize == 0) MaxEntrySize = ~0; if(ArchiveSize == 0) ArchiveSize = ~0; - #ifdef LIBFAR_SUPPORT_FAR + #ifdef FAR_SUPPORT_FAR if(FARFileInfo->Type == FAR_TYPE_FAR){ unsigned MinEntrySize = (MajorVersion == 1) ? ( @@ -269,7 +269,7 @@ int far_read_entry(const FARFile * FARFileInfo, FAREntry * FAREntryInfo, } if(FAREntryInfo->FilenameLength > MaxEntrySize - MinEntrySize) return 0; - if(FAREntryInfo->FilenameLength > (unsigned)libfarOptions[LIBFAR_CONFIG_MAX_FILE_NAME_LENGTH]) return 0; + if(FAREntryInfo->FilenameLength > (unsigned)libfarOptions[FAR_CONFIG_MAX_FILE_NAME_LENGTH]) return 0; if(FAREntryInfo->CompressedSize > FAREntryInfo->DecompressedSize) return 0; if(FAREntryInfo->DecompressedSize != 0){ @@ -286,7 +286,7 @@ int far_read_entry(const FARFile * FARFileInfo, FAREntry * FAREntryInfo, } #endif - #ifdef LIBFAR_SUPPORT_DBPF + #ifdef FAR_SUPPORT_DBPF if(FARFileInfo->Type == FAR_TYPE_DBPF){ if(MaxEntrySize < SIZEOF_ENTRY_DBPF) return 0; @@ -346,7 +346,7 @@ int far_read_entry_data(const FARFile * FARFileInfo, FAREntry * FAREntryInfo, ui int Compressed = (FARFileInfo->Type == FAR_TYPE_FAR) ? ( (FARFileInfo->MajorVersion == 1) ? ( FAREntryInfo->DecompressedSize != FAREntryInfo->CompressedSize - ) : FAREntryInfo->DataType == 0x80) : libfarOptions[LIBFAR_CONFIG_DBPF_COMPRESSED]; + ) : FAREntryInfo->DataType == 0x80) : libfarOptions[FAR_CONFIG_DBPF_COMPRESSED]; FAREntryInfo->CompressedData = Buffer+FAREntryInfo->DataOffset; @@ -390,7 +390,7 @@ int far_read_persist_data(PersistFile * PersistData, uint8_t * CompressedData) if(!RefPackDecompress(PersistData->CompressedData, PersistData->CompressedSize-9, PersistData->DecompressedData, PersistData->DecompressedSize, - libfarOptions[LIBFAR_CONFIG_REFPACK_HNSV])){ + libfarOptions[FAR_CONFIG_REFPACK_HNSV])){ free(PersistData->DecompressedData); return 0; } diff --git a/Libraries/FileHandler/far/libfar.h b/Libraries/FileHandler/far/far.h similarity index 95% rename from Libraries/FileHandler/far/libfar.h rename to Libraries/FileHandler/far/far.h index 2159add..7b59b35 100644 --- a/Libraries/FileHandler/far/libfar.h +++ b/Libraries/FileHandler/far/far.h @@ -21,10 +21,10 @@ */ /* libfarOptions array members */ -#define LIBFAR_CONFIG_DEFAULT_TO_1A 0 -#define LIBFAR_CONFIG_DBPF_COMPRESSED 1 -#define LIBFAR_CONFIG_MAX_FILE_NAME_LENGTH 2 -#define LIBFAR_CONFIG_REFPACK_HNSV 3 +#define FAR_CONFIG_DEFAULT_TO_1A 0 +#define FAR_CONFIG_DBPF_COMPRESSED 1 +#define FAR_CONFIG_MAX_FILE_NAME_LENGTH 2 +#define FAR_CONFIG_REFPACK_HNSV 3 /* Archive types */ #define FAR_TYPE_INVALID 0 @@ -33,7 +33,7 @@ #define FAR_TYPE_PERSIST 3 /* Numerical constants */ -#define LIBFAR_ARCHIVE_MINIMUM_SIZE 14 +#define FAR_ARCHIVE_MINIMUM_SIZE 14 #define MINSIZE_FAR 20 #define MINSIZE_DBPF 64 #define MINSIZE_ENTRY_FAR_1A 16 diff --git a/Libraries/FileHandler/far/farextract.c b/Libraries/FileHandler/far/farextract.c index 990c02d..d4a29cf 100644 --- a/Libraries/FileHandler/far/farextract.c +++ b/Libraries/FileHandler/far/farextract.c @@ -22,7 +22,7 @@ #include #include #include "config.h" -#include "libfar.h" +#include "far.h" enum { profile_ts1 = 1, @@ -100,9 +100,9 @@ int main(int argc, char *argv[]){ ** Handle profile settings */ if(!profile) profile = profile_tso; - libfar_set_option(LIBFAR_CONFIG_DEFAULT_TO_1A, (profile == profile_ts1)); - libfar_set_option(LIBFAR_CONFIG_DBPF_COMPRESSED, (profile >= profile_sc4)); - libfar_set_option(LIBFAR_CONFIG_REFPACK_HNSV, 0xFB); + libfar_set_option(FAR_CONFIG_DEFAULT_TO_1A, (profile == profile_ts1)); + libfar_set_option(FAR_CONFIG_DBPF_COMPRESSED, (profile >= profile_sc4)); + libfar_set_option(FAR_CONFIG_REFPACK_HNSV, 0xFB); /**** ** Open the file and read in the entire contents to memory diff --git a/Libraries/libvitaboy/Renderer.cpp b/Libraries/libvitaboy/Renderer.cpp index 0982ba4..a33c07f 100644 --- a/Libraries/libvitaboy/Renderer.cpp +++ b/Libraries/libvitaboy/Renderer.cpp @@ -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); } } } diff --git a/Libraries/libvitaboy/anim.cpp b/Libraries/libvitaboy/anim.cpp index 576608f..612cb8a 100644 --- a/Libraries/libvitaboy/anim.cpp +++ b/Libraries/libvitaboy/anim.cpp @@ -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 #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; diff --git a/Libraries/libvitaboy/libvitaboy.hpp b/Libraries/libvitaboy/libvitaboy.hpp index a23683c..f2126c1 100644 --- a/Libraries/libvitaboy/libvitaboy.hpp +++ b/Libraries/libvitaboy/libvitaboy.hpp @@ -25,6 +25,10 @@ #include #include +/**** +** 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) */ diff --git a/Libraries/libvitaboy/mesh.cpp b/Libraries/libvitaboy/mesh.cpp index 8067510..cfc14f0 100644 --- a/Libraries/libvitaboy/mesh.cpp +++ b/Libraries/libvitaboy/mesh.cpp @@ -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 + Author(s): Fatbag + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +namespace Translation { + extern wchar_t Path[1024], Filename[1024]; + + extern bool IsOpen; + extern bool IsModified; + + bool Add(const wchar_t * Path); + bool Close(); + bool Open(); + bool PopulateEntries(); + bool Save(); + bool SaveAs(); + bool SetWorkspace(); +} \ No newline at end of file