mirror of
https://github.com/simtactics/niotso.git
synced 2025-03-22 19:02:20 +00:00
87 lines
No EOL
3 KiB
C++
87 lines
No EOL
3 KiB
C++
/*
|
|
libvitaboy - Copyright (c) 2012 Fatbag <X-Fi6@phppoll.org>
|
|
|
|
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.
|
|
*/
|
|
|
|
#include "libvitaboy.hpp"
|
|
|
|
VBFile_t VBFile;
|
|
|
|
void ReadPropEntry(KeyValuePair_t& Entry){
|
|
Entry.Key = VBFile.readstring();
|
|
printf(" | | | | | Key: %s\n", Entry.Key);
|
|
Entry.Value = VBFile.readstring();
|
|
printf(" | | | | | Value: %s\n", Entry.Value);
|
|
}
|
|
|
|
void ReadPropEntries(Prop_t& Prop){
|
|
unsigned count = Prop.EntriesCount = VBFile.readint32();
|
|
printf(" | | | | EntriesCount: %u\n", Prop.EntriesCount);
|
|
Prop.Entries = (KeyValuePair_t*) malloc(count * sizeof(KeyValuePair_t));
|
|
|
|
for(unsigned i=0; i<count; i++){
|
|
printf(" | | | | [Entry %u]\n", i+1);
|
|
ReadPropEntry(Prop.Entries[i]);
|
|
}
|
|
}
|
|
|
|
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 CombineQuaternions(Rotation_t * Destination, Rotation_t * Source){
|
|
// the constructor takes its arguments as (x, y, z, w)
|
|
float dx = Destination->x;
|
|
float dy = Destination->y;
|
|
float dz = Destination->z;
|
|
float dw = Destination->w;
|
|
float sx = Source->x;
|
|
float sy = Source->y;
|
|
float sz = Source->z;
|
|
float sw = Source->w;
|
|
|
|
Destination->x = dw*sx + dx*sw + dy*sz - dz*sy;
|
|
Destination->y = dw*sy + dy*sw + dz*sx - dx*sz;
|
|
Destination->z = dw*sz + dz*sw + dx*sy - dy*sx;
|
|
Destination->w = dw*sw - dx*sx - dy*sy - dz*sz;
|
|
}
|
|
|
|
void FindQuaternionMatrix(float * Matrix, Rotation_t * Quaternion){
|
|
float x2 = Quaternion->x * Quaternion->x;
|
|
float y2 = Quaternion->y * Quaternion->y;
|
|
float z2 = Quaternion->z * Quaternion->z;
|
|
float xy = Quaternion->x * Quaternion->y;
|
|
float xz = Quaternion->x * Quaternion->z;
|
|
float yz = Quaternion->y * Quaternion->z;
|
|
float wx = Quaternion->w * Quaternion->x;
|
|
float wy = Quaternion->w * Quaternion->y;
|
|
float wz = Quaternion->w * Quaternion->z;
|
|
|
|
Matrix[0] = 1.0f - 2.0f * (y2 + z2);
|
|
Matrix[1] = 2.0f * (xy - wz);
|
|
Matrix[2] = 2.0f * (xz + wy);
|
|
Matrix[3] = 0.0f;
|
|
Matrix[4] = 2.0f * (xy + wz);
|
|
Matrix[5] = 1.0f - 2.0f * (x2 + z2);
|
|
Matrix[6] = 2.0f * (yz - wx);
|
|
Matrix[7] = 0.0f;
|
|
Matrix[8] = 2.0f * (xz - wy);
|
|
Matrix[9] = 2.0f * (yz + wx);
|
|
Matrix[10] = 1.0f - 2.0f * (x2 + y2);
|
|
Matrix[11] = 0.0f;
|
|
Matrix[12] = 0.0f;
|
|
Matrix[13] = 0.0f;
|
|
Matrix[14] = 0.0f;
|
|
Matrix[15] = 1.0f;
|
|
} |