From 8c70df06e40ca5174daf51734b23adf578a8eeaf Mon Sep 17 00:00:00 2001 From: aap Date: Sat, 6 Feb 2016 18:17:25 +0100 Subject: [PATCH] removed stuff thats now in librwgta --- tools/d3d9/camera.cpp | 169 ----- tools/d3d9/camera.h | 37 - tools/d3d9/d3d9.vcxproj | 211 ------ tools/d3d9/d3dInit.cpp | 391 ---------- tools/d3d9/d3dUtility.cpp | 111 --- tools/d3d9/d3dUtility.h | 31 - tools/d3d9/math.cpp | 1237 ------------------------------- tools/d3d9/math/conversion.h | 93 --- tools/d3d9/math/dquat.h | 45 -- tools/d3d9/math/mat3.h | 43 -- tools/d3d9/math/mat4.h | 52 -- tools/d3d9/math/math.h | 21 - tools/d3d9/math/quat.h | 54 -- tools/d3d9/math/vec3.h | 40 - tools/d3d9/math/vec4.h | 39 - tools/dffwrite/dffwrite.cpp | 120 --- tools/dffwrite/dffwrite.vcxproj | 212 ------ tools/insttest/Makefile | 16 - tools/insttest/insttest.cpp | 265 ------- tools/insttest/insttest.vcxproj | 215 ------ tools/rsltest/Makefile | 16 - tools/rsltest/rsl.cpp | 701 ------------------ tools/rsltest/rsl.h | 481 ------------ tools/rsltest/rsltest.cpp | 1029 ------------------------- tools/rsltest/rsltest.vcxproj | 92 --- tools/txdwrite/txdwrite.cpp | 164 ---- 26 files changed, 5885 deletions(-) delete mode 100644 tools/d3d9/camera.cpp delete mode 100644 tools/d3d9/camera.h delete mode 100644 tools/d3d9/d3d9.vcxproj delete mode 100644 tools/d3d9/d3dInit.cpp delete mode 100644 tools/d3d9/d3dUtility.cpp delete mode 100644 tools/d3d9/d3dUtility.h delete mode 100644 tools/d3d9/math.cpp delete mode 100644 tools/d3d9/math/conversion.h delete mode 100644 tools/d3d9/math/dquat.h delete mode 100644 tools/d3d9/math/mat3.h delete mode 100644 tools/d3d9/math/mat4.h delete mode 100644 tools/d3d9/math/math.h delete mode 100644 tools/d3d9/math/quat.h delete mode 100644 tools/d3d9/math/vec3.h delete mode 100644 tools/d3d9/math/vec4.h delete mode 100644 tools/dffwrite/dffwrite.cpp delete mode 100644 tools/dffwrite/dffwrite.vcxproj delete mode 100644 tools/insttest/Makefile delete mode 100644 tools/insttest/insttest.cpp delete mode 100644 tools/insttest/insttest.vcxproj delete mode 100644 tools/rsltest/Makefile delete mode 100644 tools/rsltest/rsl.cpp delete mode 100644 tools/rsltest/rsl.h delete mode 100644 tools/rsltest/rsltest.cpp delete mode 100644 tools/rsltest/rsltest.vcxproj delete mode 100644 tools/txdwrite/txdwrite.cpp diff --git a/tools/d3d9/camera.cpp b/tools/d3d9/camera.cpp deleted file mode 100644 index 3fb9ada..0000000 --- a/tools/d3d9/camera.cpp +++ /dev/null @@ -1,169 +0,0 @@ -#include "math/math.h" -#include "camera.h" - -using namespace std; - -void -Camera::look(void) -{ - projMat = Mat4::perspective(fov, aspectRatio, n, f); - viewMat = Mat4::lookat(position, target, up); - -// state->mat4(PMAT,true)->val = Mat4::perspective(fov, aspectRatio, n, f); -// Mat4 mv = Mat4::lookat(position, target, up); -// state->mat4(MVMAT, true)->val = mv; -// state->mat3(NORMALMAT, true)->val = Mat3(mv); -} - -void -Camera::setPosition(Vec3 q) -{ - position = q; -} - -Vec3 -Camera::getPosition(void) -{ - return position; -} - -void -Camera::setTarget(Vec3 q) -{ - position -= target - q; - target = q; -} - -Vec3 -Camera::getTarget(void) -{ - return target; -} - -float -Camera::getHeading(void) -{ - Vec3 dir = target - position; - float a = atan2(dir.y, dir.x)-PI/2.0f; - return local_up.z < 0.0f ? a-PI : a; -} - -void -Camera::turn(float yaw, float pitch) -{ - yaw /= 2.0f; - pitch /= 2.0f; - Quat dir = Quat(target - position); - Quat r(cos(yaw), 0.0f, 0.0f, sin(yaw)); - dir = r*dir*r.K(); - local_up = Vec3(r*Quat(local_up)*r.K()); - - Quat right = dir.wedge(Quat(local_up)).U(); - r = Quat(cos(pitch), right*sin(pitch)); - dir = r*dir*r.K(); - local_up = Vec3(right.wedge(dir).U()); - if(local_up.z >=0) up.z = 1; - else up.z = -1; - - target = position + Vec3(dir); -} - -void -Camera::orbit(float yaw, float pitch) -{ - yaw /= 2.0f; - pitch /= 2.0f; - Quat dir = Quat(target - position); - Quat r(cos(yaw), 0.0f, 0.0f, sin(yaw)); - dir = r*dir*r.K(); - local_up = Vec3(r*Quat(local_up)*r.K()); - - Quat right = dir.wedge(Quat(local_up)).U(); - r = Quat(cos(-pitch), right*sin(-pitch)); - dir = r*dir*r.K(); - local_up = Vec3(right.wedge(dir).U()); - if(local_up.z >=0) up.z = 1; - else up.z = -1; - - position = target - Vec3(dir); -} - -void -Camera::dolly(float dist) -{ - Vec3 dir = (target - position).normalized()*dist; - position += dir; - target += dir; -} - -void -Camera::zoom(float dist) -{ - Vec3 dir = target - position; - float curdist = dir.norm(); - if(dist >= curdist) - dist = curdist-0.01f; - dir = dir.normalized()*dist; - position += dir; -} - -void -Camera::pan(float x, float y) -{ - Vec3 dir = (target-position).normalized(); - Vec3 right = dir.cross(up).normalized(); -// Vec3 local_up = right.cross(dir).normalized(); - dir = right*x + local_up*y; - position += dir; - target += dir; - -} - -float -Camera::sqDistanceTo(Vec3 q) -{ - return (position - q).normsq(); -} - -float -Camera::distanceTo(Vec3 q) -{ - return (position - q).norm(); -} - -void -Camera::setFov(float f) -{ - fov = f; -} - -float -Camera::getFov(void) -{ - return fov; -} - -void -Camera::setAspectRatio(float r) -{ - aspectRatio = r; -} - -void -Camera::setNearFar(float n, float f) -{ - this->n = n; - this->f = f; -} - -Camera::Camera() -{ - position = Vec3(0.0f, 6.0f, 0.0f); - target = Vec3(0.0f, 0.0f, 0.0f); - local_up = up = Vec3(0.0f, 0.0f, 1.0f); - fov = 70.0f; - aspectRatio = 1.0f; - n = 0.1f; - f = 100.0f; -} - diff --git a/tools/d3d9/camera.h b/tools/d3d9/camera.h deleted file mode 100644 index 0a47263..0000000 --- a/tools/d3d9/camera.h +++ /dev/null @@ -1,37 +0,0 @@ -class Camera -{ -private: - Vec3 position; - Vec3 target; - Vec3 up; - Vec3 local_up; - - float fov, aspectRatio; - float n, f; - -public: - Mat4 projMat; - Mat4 viewMat; - - void setPosition(Vec3 q); - Vec3 getPosition(void); - void setTarget(Vec3 q); - Vec3 getTarget(void); - float getHeading(void); - - void turn(float yaw, float pitch); - void orbit(float yaw, float pitch); - void dolly(float dist); - void zoom(float dist); - void pan(float x, float y); - - void setFov(float f); - float getFov(void); - void setAspectRatio(float r); - void setNearFar(float n, float f); - - void look(void); - float distanceTo(Vec3 q); - float sqDistanceTo(Vec3 q); - Camera(void); -}; diff --git a/tools/d3d9/d3d9.vcxproj b/tools/d3d9/d3d9.vcxproj deleted file mode 100644 index ced30c8..0000000 --- a/tools/d3d9/d3d9.vcxproj +++ /dev/null @@ -1,211 +0,0 @@ - - - - - Debug - null - Win32 - - - Debug - null - x64 - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {E5D477C8-4CAF-43BF-B7E3-6689503D469F} - d3d9 - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - - - - - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration) - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration) - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration) - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration) - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration) - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration) - - - - Level3 - Disabled - true - _CRT_SECURE_NO_WARNINGS;RW_D3D9;%(PreprocessorDefinitions) - - - true - d3d9.lib;winmm.lib;librw.lib;%(AdditionalDependencies) - - - - - Level3 - Disabled - true - _CRT_SECURE_NO_WARNINGS;RW_D3D9;%(PreprocessorDefinitions) - - - true - d3d9.lib;winmm.lib;librw.lib;%(AdditionalDependencies) - - - - - Level3 - Disabled - true - _CRT_SECURE_NO_WARNINGS;RW_D3D9;%(PreprocessorDefinitions) - - - true - d3d9.lib;winmm.lib;librw.lib;%(AdditionalDependencies) - - - - - Level3 - Disabled - true - _CRT_SECURE_NO_WARNINGS;RW_D3D9;%(PreprocessorDefinitions) - - - true - d3d9.lib;winmm.lib;librw.lib;%(AdditionalDependencies) - - - - - Level3 - MaxSpeed - true - true - true - _CRT_SECURE_NO_WARNINGS;RW_D3D9;%(PreprocessorDefinitions) - - - true - true - true - d3d9.lib;winmm.lib;librw.lib;%(AdditionalDependencies) - - - - - Level3 - MaxSpeed - true - true - true - _CRT_SECURE_NO_WARNINGS;RW_D3D9;%(PreprocessorDefinitions) - - - true - true - true - d3d9.lib;winmm.lib;librw.lib;%(AdditionalDependencies) - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tools/d3d9/d3dInit.cpp b/tools/d3d9/d3dInit.cpp deleted file mode 100644 index 93620ab..0000000 --- a/tools/d3d9/d3dInit.cpp +++ /dev/null @@ -1,391 +0,0 @@ -#include "d3dUtility.h" -#include -using namespace DirectX; - -#include -#include -#include "math/math.h" -#include "camera.h" - -IDirect3DDevice9 *Device = 0; - -Camera *camera; - -namespace rw { - -namespace d3d { - -void -createTexture(Texture *tex) -{ - D3dRaster *raster = PLUGINOFFSET(D3dRaster, tex->raster, nativeRasterOffset); - int32 w, h; - w = tex->raster->width; - h = tex->raster->height; - - assert((tex->raster->format & 0xF00) == Raster::C8888); - - IDirect3DTexture9 *texture; - Device->CreateTexture(w, h, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL); - D3DLOCKED_RECT lr; - texture->LockRect(0, &lr, 0, 0); - DWORD *dst = (DWORD*)lr.pBits; - uint8 *src = tex->raster->texels; - for(int i = 0; i < h; i++){ - for(int j = 0; j < w; j++){ - dst[j] = D3DCOLOR_ARGB(src[3], src[0], src[1], src[2]); - src += 4; - } - dst += lr.Pitch/4; - } - texture->UnlockRect(0); - raster->texture = texture; - raster->format = D3DFMT_A8R8G8B8; -} - -void -setTexture(Texture *tex) -{ - static DWORD filternomip[] = { - 0, D3DTEXF_POINT, D3DTEXF_LINEAR, - D3DTEXF_POINT, D3DTEXF_LINEAR, - D3DTEXF_POINT, D3DTEXF_LINEAR - }; - static DWORD wrap[] = { - 0, D3DTADDRESS_WRAP, D3DTADDRESS_MIRROR, - D3DTADDRESS_CLAMP, D3DTADDRESS_BORDER - }; - - D3dRaster *raster = PLUGINOFFSET(D3dRaster, tex->raster, nativeRasterOffset); - if(tex->raster){ - if(raster->texture == NULL) - createTexture(tex); - Device->SetTexture(0, (IDirect3DTexture9*)raster->texture); - Device->SetSamplerState(0, D3DSAMP_MAGFILTER, filternomip[tex->filterAddressing & 0xFF]); - Device->SetSamplerState(0, D3DSAMP_MINFILTER, filternomip[tex->filterAddressing & 0xFF]); - Device->SetSamplerState(0, D3DSAMP_ADDRESSU, wrap[(tex->filterAddressing >> 8) & 0xF]); - Device->SetSamplerState(0, D3DSAMP_ADDRESSV, wrap[(tex->filterAddressing >> 12) & 0xF]); - }else - Device->SetTexture(0, NULL); -} - -void -setMaterial(Material *mat) -{ - D3DMATERIAL9 mat9; - D3DCOLORVALUE black = { 0, 0, 0, 0 }; - float ambmult = mat->surfaceProps.ambient/255.0f; - float diffmult = mat->surfaceProps.diffuse/255.0f; - mat9.Ambient.r = mat->color[0]*ambmult; - mat9.Ambient.g = mat->color[1]*ambmult; - mat9.Ambient.b = mat->color[2]*ambmult; - mat9.Ambient.a = mat->color[3]*ambmult; - mat9.Diffuse.r = mat->color[0]*diffmult; - mat9.Diffuse.g = mat->color[1]*diffmult; - mat9.Diffuse.b = mat->color[2]*diffmult; - mat9.Diffuse.a = mat->color[3]*diffmult; - mat9.Power = 0.0f; - mat9.Emissive = black; - mat9.Specular = black; - Device->SetMaterial(&mat9); -} - -} - -namespace d3d9 { -using namespace d3d; - -void -drawAtomic(Atomic *atomic) -{ - Geometry *geo = atomic->geometry; - if((geo->geoflags & Geometry::NATIVE) == 0) - return; - InstanceDataHeader *header = (InstanceDataHeader*)geo->instData; - - atomic->frame->updateLTM(); - Device->SetTransform(D3DTS_WORLD, (D3DMATRIX*)atomic->frame->ltm); - - Device->SetStreamSource(0, (IDirect3DVertexBuffer9*)header->vertexStream[0].vertexBuffer, - 0, header->vertexStream[0].stride); - Device->SetIndices((IDirect3DIndexBuffer9*)header->indexBuffer); - Device->SetVertexDeclaration((IDirect3DVertexDeclaration9*)header->vertexDeclaration); - - InstanceData *inst = header->inst; - for(uint32 i = 0; i < header->numMeshes; i++){ - if(inst->material->texture) - setTexture(inst->material->texture); - else - Device->SetTexture(0, NULL); - setMaterial(inst->material); - Device->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_ARGB(0xFF, 0x40, 0x40, 0x40)); - Device->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); - Device->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); - if(geo->geoflags & Geometry::PRELIT) - Device->SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1); - Device->DrawIndexedPrimitive((D3DPRIMITIVETYPE)header->primType, inst->baseIndex, - 0, inst->numVertices, - inst->startIndex, inst->numPrimitives); - inst++; - } -} -} - -namespace d3d8 { -using namespace d3d; - -void -drawAtomic(Atomic *atomic) -{ - Geometry *geo = atomic->geometry; - if((geo->geoflags & Geometry::NATIVE) == 0) - return; - InstanceDataHeader *header = (InstanceDataHeader*)geo->instData; - - atomic->frame->updateLTM(); - Device->SetTransform(D3DTS_WORLD, (D3DMATRIX*)atomic->frame->ltm); - - InstanceData *inst = header->inst; - for(uint32 i = 0; i < header->numMeshes; i++){ - if(inst->material->texture) - setTexture(inst->material->texture); - else - Device->SetTexture(0, NULL); - setMaterial(inst->material); - Device->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_ARGB(0xFF, 0x40, 0x40, 0x40)); - Device->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); - Device->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); - if(geo->geoflags & Geometry::PRELIT) - Device->SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1); - - Device->SetFVF(inst->vertexShader); - Device->SetStreamSource(0, (IDirect3DVertexBuffer9*)inst->vertexBuffer, 0, inst->stride); - Device->SetIndices((IDirect3DIndexBuffer9*)inst->indexBuffer); - uint32 numPrim = inst->primType == D3DPT_TRIANGLESTRIP ? inst->numIndices-2 : inst->numIndices/3; - Device->DrawIndexedPrimitive((D3DPRIMITIVETYPE)inst->primType, inst->baseIndex, - 0, inst->numVertices, 0, numPrim); - inst++; - } -} -} - -} - -rw::Clump *clump; -void (*renderCB)(rw::Atomic*) = NULL; - -void -initrw(void) -{ - gta::attachPlugins(); - rw::d3d::registerNativeRaster(); - - rw::currentTexDictionary = new rw::TexDictionary; - //rw::Image::setSearchPath("D:\\rockstargames\\ps2\\gta3\\MODELS\\gta3_archive\\txd_extracted\\;" - // "D:\\rockstargames\\ps2\\gtavc\\MODELS\\gta3_archive\\txd_extracted\\;" - // "D:\\rockstargames\\ps2\\gtasa\\models\\gta3_archive\\txd_extracted\\"); - - rw::platform = rw::PLATFORM_D3D8; - rw::d3d::device = Device; - - if(0){ - char *filename = "D:\\rockstargames\\pc\\gtavc\\models\\gta3_archive\\admiral.txd"; - rw::StreamFile in; - if(in.open(filename, "rb") == NULL){ - MessageBox(0, "couldn't open file\n", 0, 0); - printf("couldn't open file\n"); - } - rw::findChunk(&in, rw::ID_TEXDICTIONARY, NULL, NULL); - rw::TexDictionary *txd; - txd = rw::TexDictionary::streamRead(&in); - assert(txd); - in.close(); - rw::currentTexDictionary = txd; - - rw::StreamFile out; - out.open("out.txd", "wb"); - txd->streamWrite(&out); - out.close(); - } - -// char *filename = "D:\\rockstargames\\pc\\gtavc\\models\\gta3_archive\\admiral.dff"; -// char *filename = "D:\\rockstargames\\pc\\gta3\\models\\gta3_archive\\kuruma.dff"; -// char *filename = "D:\\rockstargames\\pc\\gtavc\\models\\gta3_archive\\player.dff"; -// char *filename = "D:\\rockstargames\\pc\\gtavc\\models\\gta3_archive\\od_newscafe_dy.dff"; -// char *filename = "D:\\rockstargames\\pc\\gtasa\\models\\gta3_archive\\admiral.dff"; - char *filename = "D:\\rockstargames\\pc\\gtasa\\models\\gta3_archive\\lae2_roads89.dff"; -// char *filename = "D:\\rockstargames\\pc\\gtasa\\models\\gta3_archive\\casinoblock41_nt.dff"; -// char *filename = "D:\\rockstargames\\pc\\gtasa\\models\\cutscene_archive\\csremington92.dff"; -// char *filename = "C:\\gtasa\\test\\hanger.dff"; -// char *filename = "C:\\Users\\aap\\Desktop\\tmp\\out.dff"; -// char *filename = "out2.dff"; -// char *filename = "C:\\Users\\aap\\src\\librw\\tools\\insttest\\out.dff"; - rw::StreamFile in; - if(in.open(filename, "rb") == NULL){ - MessageBox(0, "couldn't open file\n", 0, 0); - printf("couldn't open file\n"); - } - rw::findChunk(&in, rw::ID_CLUMP, NULL, NULL); - clump = rw::Clump::streamRead(&in); - assert(clump); - in.close(); - - for(int i = 0; i < clump->numAtomics; i++){ - rw::Atomic *a = clump->atomicList[i]; - if(a->pipeline && a->pipeline->platform == rw::PLATFORM_PS2) - a->pipeline = NULL; - a->getPipeline()->instance(a); - } - if(rw::platform == rw::PLATFORM_D3D8) - renderCB = rw::d3d8::drawAtomic; - else if(rw::platform == rw::PLATFORM_D3D9) - renderCB = rw::d3d9::drawAtomic; - - rw::StreamFile out; - out.open("out.dff", "wb"); - clump->streamWrite(&out); - out.close(); -} - -bool -Setup() -{ - D3DLIGHT9 light; - light.Type = D3DLIGHT_DIRECTIONAL; - light.Diffuse = { 0.8f, 0.8f, 0.8f, 1.0f }; - light.Specular = { 0.0f, 0.0f, 0.0f, 0.0f }; - light.Ambient = { 0.0f, 0.0f, 0.0f, 0.0f }; - light.Position = { 0.0f, 0.0f, 0.0f }; - light.Direction = { 0.0f, 0.0f, -1.0f }; - light.Range = 0.0f; - light.Falloff = 0.0f; - light.Attenuation0 = 0.0f; - light.Attenuation1 = 0.0f; - light.Attenuation2 = 0.0f; - light.Theta = 0.0f; - light.Phi = 0.0f; - - initrw(); - - Device->SetRenderState(D3DRS_LIGHTING, true); - Device->SetLight(0, &light); - Device->LightEnable(0, 1); - - Device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); - Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); - Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); - Device->SetRenderState(D3DRS_ALPHABLENDENABLE, 1); - Device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); - - camera = new Camera; - camera->setAspectRatio(640.0f/480.0f); - camera->setNearFar(0.1f, 450.0f); - camera->setTarget(Vec3(0.0f, 0.0f, 0.0f)); -// camera->setPosition(Vec3(0.0f, 5.0f, 0.0f)); -// camera->setPosition(Vec3(0.0f, -70.0f, 0.0f)); - camera->setPosition(Vec3(0.0f, -10.0f, 0.0f)); -// camera->setPosition(Vec3(0.0f, -1.0f, 3.0f)); - - return true; -} - -void -Cleanup() -{ -} - -bool -Display(float timeDelta) -{ - if(Device == NULL) - return true; - - Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, - 0xff808080, 1.0f, 0); - Device->BeginScene(); - - camera->look(); - Device->SetTransform(D3DTS_VIEW, (D3DMATRIX*)camera->viewMat.cr); - Device->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)camera->projMat.cr); - - for(rw::int32 i = 0; i < clump->numAtomics; i++){ - char *name = PLUGINOFFSET(char, clump->atomicList[i]->frame, - gta::nodeNameOffset); - if(strstr(name, "_dam") || strstr(name, "_vlo")) - continue; - renderCB(clump->atomicList[i]); - } - - Device->EndScene(); - - Device->Present(0, 0, 0, 0); - return true; -} - -LRESULT CALLBACK -d3d::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch(msg){ - case WM_DESTROY: - PostQuitMessage(0); - break; - - case WM_KEYDOWN: - switch(wParam){ - case 'W': - camera->orbit(0.0f, 0.1f); - break; - case 'S': - camera->orbit(0.0f, -0.1f); - break; - case 'A': - camera->orbit(-0.1f, 0.0f); - break; - case 'D': - camera->orbit(0.1f, 0.0f); - break; - case 'R': - camera->zoom(0.1f); - break; - case 'F': - camera->zoom(-0.1f); - break; - case VK_ESCAPE: - DestroyWindow(hwnd); - break; - } - break; - case WM_CLOSE: - DestroyWindow(hwnd); - break; - } - return DefWindowProc(hwnd, msg, wParam, lParam); -} - -int WINAPI -WinMain(HINSTANCE hinstance, HINSTANCE prevInstance, - PSTR cmdLine, int showCmd) -{ -/* AllocConsole(); - freopen("CONIN$", "r", stdin); - freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr);*/ - - if(!d3d::InitD3D(hinstance, 640, 480, true, D3DDEVTYPE_HAL, &Device)){ - MessageBox(0, "InitD3D() - FAILED", 0, 0); - return 0; - } - - if(!Setup()){ - MessageBox(0, "Setup() - FAILED", 0, 0); - return 0; - } - - d3d::EnterMsgLoop(Display); - - Cleanup(); - - Device->Release(); - - return 0; -} \ No newline at end of file diff --git a/tools/d3d9/d3dUtility.cpp b/tools/d3d9/d3dUtility.cpp deleted file mode 100644 index d05ce26..0000000 --- a/tools/d3d9/d3dUtility.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "d3dUtility.h" - -bool -d3d::InitD3D(HINSTANCE hInstance, - int width, int height, - bool windowed, - D3DDEVTYPE deviceType, - IDirect3DDevice9 **device) -{ - WNDCLASS wc; - wc.style = CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc = (WNDPROC)d3d::WndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = hInstance; - wc.hIcon = LoadIcon(0, IDI_APPLICATION); - wc.hCursor = LoadCursor(0, IDC_ARROW); - wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); - wc.lpszMenuName = 0; - wc.lpszClassName = "Direct3D9App"; - if(!RegisterClass(&wc)){ - MessageBox(0, "RegisterClass() - FAILED", 0, 0); - return false; - } - - HWND hwnd = 0; - hwnd = CreateWindow("Direct3D9App", "Direct3D9App", - WS_BORDER | WS_CAPTION | WS_SYSMENU | - WS_MINIMIZEBOX | WS_MAXIMIZEBOX, - 0, 0, width, height, 0, 0, hInstance, 0); - if(!hwnd){ - MessageBox(0, "CreateWindow() - FAILED", 0, 0); - return false; - } - ShowWindow(hwnd, SW_SHOW); - UpdateWindow(hwnd); - - HRESULT hr = 0; - IDirect3D9 *d3d9 = 0; - d3d9 = Direct3DCreate9(D3D_SDK_VERSION); - if(!d3d9){ - MessageBox(0, "Direct3DCreate9() - FAILED", 0, 0); - return false; - } - - D3DCAPS9 caps; - d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, deviceType, &caps); - int vp = 0; - if(caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) - vp = D3DCREATE_HARDWARE_VERTEXPROCESSING; - else - vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; - - D3DPRESENT_PARAMETERS d3dpp; - d3dpp.BackBufferWidth = width; - d3dpp.BackBufferHeight = height; - d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; - d3dpp.BackBufferCount = 1; - d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; - d3dpp.MultiSampleQuality = 0; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.hDeviceWindow = hwnd; - d3dpp.Windowed = windowed; - d3dpp.EnableAutoDepthStencil = true; - d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; - d3dpp.Flags = 0; - d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - - hr = d3d9->CreateDevice(D3DADAPTER_DEFAULT, deviceType, hwnd, - vp, &d3dpp, device); - if(FAILED(hr)){ - // try again using a 16-bit depth buffer - d3dpp.AutoDepthStencilFormat = D3DFMT_D16; - - hr = d3d9->CreateDevice(D3DADAPTER_DEFAULT, deviceType, - hwnd, vp, &d3dpp, device); - - if(FAILED(hr)){ - d3d9->Release(); - MessageBox(0, "CreateDevice() - FAILED", 0, 0); - return false; - } - } - d3d9->Release(); - return true; -} - -int -d3d::EnterMsgLoop(bool (*ptr_display)(float timeDelta)) -{ - MSG msg; - ZeroMemory(&msg, sizeof(MSG)); - - static float lastTime = (float)timeGetTime(); - - while(msg.message != WM_QUIT){ - if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)){ - TranslateMessage(&msg); - DispatchMessage(&msg); - }else{ - float currTime = (float)timeGetTime(); - float timeDelta = (currTime - lastTime)*0.001f; - - ptr_display(timeDelta); - - lastTime = currTime; - } - } - return msg.wParam; -} \ No newline at end of file diff --git a/tools/d3d9/d3dUtility.h b/tools/d3d9/d3dUtility.h deleted file mode 100644 index 0852b8f..0000000 --- a/tools/d3d9/d3dUtility.h +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include - -namespace d3d -{ -bool InitD3D(HINSTANCE hInstance, int width, int height, bool windowed, - D3DDEVTYPE deviceType, IDirect3DDevice9 **device); - -int EnterMsgLoop(bool (*ptr_display)(float timeDelta)); - -LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); - -/* -template void Release(T t) -{ - if(t){ - t->Release(); - t = 0; - } -} - -template void Delete(T t) -{ - if(t){ - delete t; - t = 0; - } -} -*/ - -} \ No newline at end of file diff --git a/tools/d3d9/math.cpp b/tools/d3d9/math.cpp deleted file mode 100644 index 58bfd70..0000000 --- a/tools/d3d9/math.cpp +++ /dev/null @@ -1,1237 +0,0 @@ -#include "math/math.h" - -/* - * Vec3 - */ - -std::ostream& -operator<<(std::ostream& of, const Vec3 &v) -{ - v.print(of); - return of; -} - - -Vec3::Vec3(void) - : x(0.0f), y(0.0f), z(0.0f) -{ -} - -Vec3::Vec3(float x, float y, float z) - : x(x), y(y), z(z) -{ -} - -Vec3::Vec3(float *v) - : x(v[0]), y(v[1]), z(v[2]) -{ -} - -float* -Vec3::ptr(void) -{ - return &x; -} - -Vec3 -Vec3::operator-(void) const -{ - return Vec3(-x, -y, -z); -} - -Vec3 -Vec3::operator+(const Vec3 &rhs) const -{ - return Vec3(this->x+rhs.x, this->y+rhs.y, this->z+rhs.z); -} - -Vec3 -Vec3::operator-(const Vec3 &rhs) const -{ - return Vec3(this->x-rhs.x, this->y-rhs.y, this->z-rhs.z); -} - -Vec3 -Vec3::operator*(float rhs) const -{ - return Vec3(this->x*rhs, this->y*rhs, this->z*rhs); -} - -Vec3 -Vec3::operator/(float rhs) const -{ - return Vec3(this->x/rhs, this->y/rhs, this->z/rhs); -} - -Vec3& -Vec3::operator+=(const Vec3 &rhs) -{ - *this = *this + rhs; - return *this; -} - -Vec3& -Vec3::operator-=(const Vec3 &rhs) -{ - *this = *this - rhs; - return *this; -} - -Vec3& -Vec3::operator*=(float rhs) -{ - *this = *this * rhs; - return *this; -} - -Vec3& -Vec3::operator/=(float rhs) -{ - *this = *this / rhs; - return *this; -} - -bool -Vec3::operator==(const Vec3 &rhs) const -{ - return (this->x == rhs.x) && - (this->y == rhs.y) && - (this->z == rhs.z); -} - -bool -Vec3::operator!=(const Vec3 &rhs) const -{ - return (this->x != rhs.x) || - (this->y != rhs.y) || - (this->z != rhs.z); -} - -float -Vec3::norm(void) const -{ - return sqrt(normsq()); -} - -float -Vec3::normsq(void) const -{ - return x*x + y*y + z*z; -} - -Vec3 -Vec3::normalized(void) const -{ - return Vec3(*this)/norm(); -} - -float -Vec3::dot(const Vec3 &rhs) const -{ - return this->x*rhs.x + this->y*rhs.y + this->z*rhs.z; -} - -Vec3 -Vec3::cross(const Vec3 &rhs) const -{ - return Vec3(this->y*rhs.z - this->z*rhs.y, - this->z*rhs.x - this->x*rhs.z, - this->x*rhs.y - this->y*rhs.x); -} - -void -Vec3::print(std::ostream &of) const -{ - of << "V3(" << x << ", " << y << ", " << z << ")"; -} - -/* - * Vec4 - */ - -std::ostream& -operator<<(std::ostream& of, const Vec4 &v) -{ - v.print(of); - return of; -} - - -Vec4::Vec4(void) - : x(0.0f), y(0.0f), z(0.0f), w(0.0f) -{ -} - -Vec4::Vec4(float x, float y, float z, float w) - : x(x), y(y), z(z), w(w) -{ -} - -Vec4::Vec4(float *v) - : x(v[0]), y(v[1]), z(v[2]), w(v[3]) -{ -} - -float* -Vec4::ptr(void) -{ - return &x; -} - -Vec4 -Vec4::operator-(void) const -{ - return Vec4(-x, -y, -z, -w); -} - -Vec4 -Vec4::operator+(const Vec4 &rhs) const -{ - return Vec4(this->x+rhs.x, this->y+rhs.y, this->z+rhs.z, this->w+rhs.w); -} - -Vec4 -Vec4::operator-(const Vec4 &rhs) const -{ - return Vec4(this->x-rhs.x, this->y-rhs.y, this->z-rhs.z, this->w-rhs.w); -} - -Vec4 -Vec4::operator*(float rhs) const -{ - return Vec4(this->x*rhs, this->y*rhs, this->z*rhs, this->w*rhs); -} - -Vec4 -Vec4::operator/(float rhs) const -{ - return Vec4(this->x/rhs, this->y/rhs, this->z/rhs, this->w/rhs); -} - -Vec4& -Vec4::operator+=(const Vec4 &rhs) -{ - *this = *this + rhs; - return *this; -} - -Vec4& -Vec4::operator-=(const Vec4 &rhs) -{ - *this = *this - rhs; - return *this; -} - -Vec4& -Vec4::operator*=(float rhs) -{ - *this = *this * rhs; - return *this; -} - -Vec4& -Vec4::operator/=(float rhs) -{ - *this = *this / rhs; - return *this; -} - -bool -Vec4::operator==(const Vec4 &rhs) const -{ - return (this->x == rhs.x) && - (this->y == rhs.y) && - (this->z == rhs.z) && - (this->w == rhs.w); -} - -bool -Vec4::operator!=(const Vec4 &rhs) const -{ - return (this->x != rhs.x) || - (this->y != rhs.y) || - (this->z != rhs.z) || - (this->w != rhs.w); -} - -float -Vec4::norm(void) const -{ - return sqrt(normsq()); -} - -float -Vec4::normsq(void) const -{ - return x*x + y*y + z*z + w*w; -} - -Vec4 -Vec4::normalized(void) const -{ - return Vec4(*this)/norm(); -} - -float -Vec4::dot(const Vec4 &rhs) const -{ - return this->x*rhs.x + this->y*rhs.y + this->z*rhs.z + this->w*rhs.w; -} - -void -Vec4::print(std::ostream &of) const -{ - of << "V4(" << x << ", " << y << ", " << z << ", " << w << ")"; -} - -/* - * Quat - */ - -std::ostream& -operator<<(std::ostream& of, const Quat &v) -{ - v.print(of); - return of; -} - - -Quat::Quat(void) - : w(0.0f), x(0.0f), y(0.0f), z(0.0f) -{ -} - -Quat::Quat(float w) - : w(w), x(0.0f), y(0.0f), z(0.0f) -{ -} - -Quat::Quat(float x, float y, float z) - : w(0.0f), x(x), y(y), z(z) -{ -} - -Quat::Quat(float w, float x, float y, float z) - : w(w), x(x), y(y), z(z) -{ -} - -float* -Quat::ptr(void) -{ - return &w; -} - -Quat -Quat::operator-(void) const -{ - return Quat(-w, -x, -y, -z); -} - -Quat -Quat::operator+(const Quat &rhs) const -{ - return Quat(this->w+rhs.w, this->x+rhs.x, this->y+rhs.y, this->z+rhs.z); -} - -Quat -Quat::operator-(const Quat &rhs) const -{ - return Quat(this->w-rhs.w, this->x-rhs.x, this->y-rhs.y, this->z-rhs.z); -} - -Quat -Quat::operator*(const Quat &rhs) const -{ - return Quat( - this->w*rhs.w - this->x*rhs.x - this->y*rhs.y - this->z*rhs.z, - this->w*rhs.x + this->x*rhs.w + this->y*rhs.z - this->z*rhs.y, - this->w*rhs.y + this->y*rhs.w + this->z*rhs.x - this->x*rhs.z, - this->w*rhs.z + this->z*rhs.w + this->x*rhs.y - this->y*rhs.x); -} - -Quat -Quat::operator*(float rhs) const -{ - return Quat(this->w*rhs, this->x*rhs, this->y*rhs, this->z*rhs); -} - -Quat -Quat::operator/(float rhs) const -{ - return Quat(this->w/rhs, this->x/rhs, this->y/rhs, this->z/rhs); -} - -Quat& -Quat::operator+=(const Quat &rhs) -{ - *this = *this + rhs; - return *this; -} - -Quat& -Quat::operator-=(const Quat &rhs) -{ - *this = *this - rhs; - return *this; -} - -Quat& -Quat::operator*=(const Quat &rhs) -{ - *this = *this * rhs; - return *this; -} - -Quat& -Quat::operator*=(float rhs) -{ - *this = *this * rhs; - return *this; -} - -Quat& -Quat::operator/=(float rhs) -{ - *this = *this / rhs; - return *this; -} - -bool -Quat::operator==(const Quat &rhs) const -{ - return (this->w == rhs.w) && - (this->x == rhs.x) && - (this->y == rhs.y) && - (this->z == rhs.z); -} - -bool -Quat::operator!=(const Quat &rhs) const -{ - return (this->w != rhs.w) || - (this->x != rhs.x) || - (this->y != rhs.y) || - (this->z != rhs.z); -} - -Quat -Quat::inv(void) const -{ - return K() / N(); -} - -Quat -Quat::K(void) const -{ - return Quat(w, -x, -y, -z); -} - -Quat -Quat::S(void) const -{ - return Quat(w); -} - -Quat -Quat::V(void) const -{ - return Quat(x, y, z); -} - -float -Quat::T(void) const -{ - return sqrt(N()); -} - -float -Quat::N(void) const -{ - return w*w + x*x + y*y + z*z; -} - -Quat -Quat::U(void) const -{ - return Quat(*this)/T(); -} - -Quat -Quat::wedge(const Quat &rhs) const -{ - return Quat(0.0f, - this->y*rhs.z - this->z*rhs.y, - this->z*rhs.x - this->x*rhs.z, - this->x*rhs.y - this->y*rhs.x); -} - -float -Quat::inner(const Quat &rhs) const -{ - return this->w*rhs.w + this->x*rhs.x + this->y*rhs.y + this->z*rhs.z; -} - -Quat -Quat::lerp(const Quat &q2, float t) const -{ - Quat q1 = *this; - float cos = q1.inner(q2); - if(cos < 0) - q1 = -q1; - return (q1*(1.0f - t) + q2*t).U(); -} - -Quat -Quat::slerp(const Quat &q2, float t) const -{ - Quat q1 = *this; - float cos = q1.inner(q2); - if(cos < 0){ - cos = -cos; - q1 = -q1; - } - float phi = acos(cos); - if(phi > 0.00001){ - float s = sin(phi); - q1 = q1*sin((1.0f-t)*phi)/s + q2*sin(t*phi)/s; - } - return q1; -} - -void -Quat::print(std::ostream &of) const -{ - of << "Q(" << w << ", " << x << ", " << y << ", " << z << ")"; -} - -/* - * Quat - */ - -std::ostream& -operator<<(std::ostream& of, const DQuat &v) -{ - v.print(of); - return of; -} - - -DQuat::DQuat(void) - : q1(), q2() -{ -} - -DQuat::DQuat(const Quat &q1, const Quat &q2) - : q1(q1), q2(q2) -{ -} - -DQuat -DQuat::operator-(void) const -{ - return DQuat(-q1, -q2); -} - -DQuat -DQuat::operator+(const DQuat &rhs) const -{ - return DQuat(this->q1+rhs.q1, this->q2+rhs.q2); -} - -DQuat -DQuat::operator-(const DQuat &rhs) const -{ - return DQuat(this->q1-rhs.q1, this->q2-rhs.q2); -} - -DQuat -DQuat::operator*(const DQuat &rhs) const -{ - return DQuat(this->q1*rhs.q1, this->q1*rhs.q2 + this->q2*rhs.q1); -} - -DQuat -DQuat::operator*(float rhs) const -{ - return DQuat(this->q1*rhs, this->q2*rhs); -} - -DQuat -DQuat::operator/(float rhs) const -{ - return DQuat(this->q1/rhs, this->q2/rhs); -} - -DQuat& -DQuat::operator+=(const DQuat &rhs) -{ - *this = *this + rhs; - return *this; -} - -DQuat& -DQuat::operator-=(const DQuat &rhs) -{ - *this = *this - rhs; - return *this; -} - -DQuat& -DQuat::operator*=(const DQuat &rhs) -{ - *this = *this * rhs; - return *this; -} - -DQuat& -DQuat::operator*=(float rhs) -{ - *this = *this * rhs; - return *this; -} - -DQuat& -DQuat::operator/=(float rhs) -{ - *this = *this / rhs; - return *this; -} - -bool -DQuat::operator==(const DQuat &rhs) const -{ - return (this->q1 == rhs.q1) && - (this->q2 == rhs.q2); -} - -bool -DQuat::operator!=(const DQuat &rhs) const -{ - return (this->q1 != rhs.q1) || - (this->q2 != rhs.q2); -} - -DQuat -DQuat::K(void) const -{ - return DQuat(q1.K(), -q2.K()); -} - -void -DQuat::print(std::ostream &of) const -{ - of << "DQ(" << q1 << ", " << q2 << ")"; -} - -/* - * Mat3 - */ - -std::ostream& -operator<<(std::ostream& of, const Mat3 &v) -{ - v.print(of); - return of; -} - -Mat3::Mat3(void) -{ - for(int i = 0; i < 3*3; i++) - cr[i] = 0.0f; -} - -Mat3::Mat3(float f) -{ - for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++) - e[i][j] = (i == j) ? f : 0.0f; -} - -Mat3::Mat3(float *f) -{ - for(int i = 0; i < 3*3; i++) - cr[i] = f[i]; -} - -Mat3::Mat3(float e00, float e10, float e20, - float e01, float e11, float e21, - float e02, float e12, float e22) -{ - e[0][0] = e00; e[1][0] = e10; e[2][0] = e20; - e[0][1] = e01; e[1][1] = e11; e[2][1] = e21; - e[0][2] = e02; e[1][2] = e12; e[2][2] = e22; -} - -float* -Mat3::ptr(void) -{ - return &e[0][0]; -} - -Mat3 -Mat3::rotation(float theta, const Vec3 &v) -{ - Mat3 m(1.0f); - float c = cos(theta); - float s = sin(theta); - m.e[0][0] = v.x*v.x*(1-c) + c; - m.e[1][0] = v.x*v.y*(1-c) - v.z*s; - m.e[2][0] = v.x*v.z*(1-c) + v.y*s; - - m.e[0][1] = v.y*v.x*(1-c) + v.z*s; - m.e[1][1] = v.y*v.y*(1-c) + c; - m.e[2][1] = v.y*v.z*(1-c) - v.x*s; - - m.e[0][2] = v.z*v.x*(1-c) - v.y*s; - m.e[1][2] = v.z*v.y*(1-c) + v.x*s; - m.e[2][2] = v.z*v.z*(1-c) + c; - return m; -} - -Mat3 -Mat3::scale(const Vec3 &v) -{ - Mat3 m(1.0f); - m.e[0][0] = v.x; - m.e[1][1] = v.y; - m.e[2][2] = v.z; - return m; -} - -Mat3 -Mat3::transpose(void) const -{ - float e[3][3]; - for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++){ - e[j][i] = this->e[i][j]; - e[i][j] = this->e[j][i]; - } - return Mat3(&e[0][0]); -} - -Mat3 -Mat3::operator+(const Mat3 &rhs) const -{ - float e[9]; - for(int i = 0; i < 3*3; i++) - e[i] = this->cr[i] + rhs.cr[i]; - return Mat3(e); -} - -Mat3 -Mat3::operator-(const Mat3 &rhs) const -{ - float e[9]; - for(int i = 0; i < 3*3; i++) - e[i] = this->cr[i] - rhs.cr[i]; - return Mat3(e); -} - -Mat3 -Mat3::operator*(float rhs) const -{ - float e[9]; - for(int i = 0; i < 3*3; i++) - e[i] = this->cr[i]*rhs; - return Mat3(e); -} - -Mat3 -Mat3::operator/(float rhs) const -{ - float e[9]; - for(int i = 0; i < 3*3; i++) - e[i] = this->cr[i]/rhs; - return Mat3(e); -} - -Mat3 -Mat3::operator*(const Mat3 &rhs) const -{ - float e[3][3]; - for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++) - e[i][j] = this->e[0][j]*rhs.e[i][0] + - this->e[1][j]*rhs.e[i][1] + - this->e[2][j]*rhs.e[i][2]; - return Mat3(&e[0][0]); -} - -Vec3 -Mat3::operator*(const Vec3 &rhs) const -{ - float e[3]; - for(int i = 0; i < 3; i++) - e[i] = this->e[0][i]*rhs.x + - this->e[1][i]*rhs.y + - this->e[2][i]*rhs.z; - return Vec3(e); -} - -Mat3& -Mat3::operator+=(const Mat3 &rhs) -{ - *this = *this + rhs; - return *this; -} - -Mat3& -Mat3::operator-=(const Mat3 &rhs) -{ - *this = *this - rhs; - return *this; -} - -Mat3& -Mat3::operator*=(float rhs) -{ - *this = *this * rhs; - return *this; -} - -Mat3& -Mat3::operator/=(float rhs) -{ - *this = *this / rhs; - return *this; -} - -Mat3& -Mat3::operator*=(const Mat3 &rhs) -{ - *this = *this * rhs; - return *this; -} - -void -Mat3::print(std::ostream &of) const -{ - #define CM << ", " << - of << "M3(" << e[0][0] CM e[1][0] CM e[2][0] << std::endl; - of << " " << e[0][1] CM e[1][1] CM e[2][1] << std::endl; - of << " " << e[0][2] CM e[1][2] CM e[2][2] << ")"; - #undef CM -} - -/* - * Mat3 - */ - -std::ostream& -operator<<(std::ostream& of, const Mat4 &v) -{ - v.print(of); - return of; -} - -Mat4::Mat4(void) -{ - for(int i = 0; i < 4*4; i++) - cr[i] = 0.0f; -} - -Mat4::Mat4(float f) -{ - for(int i = 0; i < 4; i++) - for(int j = 0; j < 4; j++) - e[i][j] = (i == j) ? f : 0.0f; -} - -Mat4::Mat4(float *f) -{ - for(int i = 0; i < 4*4; i++) - cr[i] = f[i]; -} - -Mat4::Mat4(float e00, float e10, float e20, float e30, - float e01, float e11, float e21, float e31, - float e02, float e12, float e22, float e32, - float e03, float e13, float e23, float e33) -{ - e[0][0] = e00; e[1][0] = e10; e[2][0] = e20; e[3][0] = e30; - e[0][1] = e01; e[1][1] = e11; e[2][1] = e21; e[3][1] = e31; - e[0][2] = e02; e[1][2] = e12; e[2][2] = e22; e[3][2] = e32; - e[0][3] = e03; e[1][3] = e13; e[2][3] = e23; e[3][3] = e33; -} - -float* -Mat4::ptr(void) -{ - return &e[0][0]; -} - -Mat4 -Mat4::perspective(float fov, float aspect, float n, float f) -{ - float r = n*tan(fov*3.14159f/360.0f); - float t = r/aspect; - return frustum(-r, r, -t, t, n, f); -} - -Mat4 -Mat4::frustum(float l, float r, float b, float t, - float n, float f) -{ - Mat4 m(1.0f); - m.e[0][0] = (2.0f*n)/(r-l); - m.e[1][1] = (2.0f*n)/(t-b); - m.e[2][0] = (r+l)/(r-l); - m.e[2][1] = (t+b)/(t-b); -// TODO: -// m.e[2][2] = -(f+n)/(f-n); -// m.e[2][3] = -1.0f; -// m.e[3][2] = -2.0f*f*n/(f-n); - m.e[2][2] = (f+n)/(f-n); - m.e[2][3] = 1.0f; - m.e[3][2] = -1.0f*f*n/(f-n); - m.e[3][3] = 0.0f; - return m; -} - -Mat4 -Mat4::ortho(float l, float r, float b, float t, - float n, float f) -{ - Mat4 m(1.0f); - m.e[0][0] = 2.0f/(r-l); - m.e[3][0] = -(r+l)/(r-l); - m.e[1][1] = 2.0f/(t-b); - m.e[3][1] = -(t+b)/(t-b); - m.e[2][2] = -2.0f/(f-n); - m.e[3][2] = -(f+n)/(f-n); - return m; -} - -Mat4 -Mat4::lookat(const Vec3 &pos, const Vec3 &target, const Vec3 &up) -{ - Vec3 forward = (target - pos).normalized(); - Vec3 side = forward.cross(up).normalized(); - Vec3 nup = side.cross(forward); - Mat4 m(1.0f); - m.e[0][0] = side.x; - m.e[1][0] = side.y; - m.e[2][0] = side.z; - m.e[0][1] = nup.x; - m.e[1][1] = nup.y; - m.e[2][1] = nup.z; - m.e[0][2] = -forward.x; - m.e[1][2] = -forward.y; - m.e[2][2] = -forward.z; - m = m*Mat4::translation(-pos); -// TODO: - m.e[0][2] *= -1.0f; - m.e[1][2] *= -1.0f; - m.e[2][2] *= -1.0f; - m.e[3][2] *= -1.0f; - return m; -} - -Mat4 -Mat4::translation(const Vec3 &v) -{ - Mat4 m(1.0f); - m.e[3][0] = v.x; - m.e[3][1] = v.y; - m.e[3][2] = v.z; - return m; -} - -Mat4 -Mat4::rotation(float theta, const Vec3 &v) -{ - Mat4 m(1.0f); - float c = cos(theta); - float s = sin(theta); - m.e[0][0] = v.x*v.x*(1-c) + c; - m.e[1][0] = v.x*v.y*(1-c) - v.z*s; - m.e[2][0] = v.x*v.z*(1-c) + v.y*s; - - m.e[0][1] = v.y*v.x*(1-c) + v.z*s; - m.e[1][1] = v.y*v.y*(1-c) + c; - m.e[2][1] = v.y*v.z*(1-c) - v.x*s; - - m.e[0][2] = v.z*v.x*(1-c) - v.y*s; - m.e[1][2] = v.z*v.y*(1-c) + v.x*s; - m.e[2][2] = v.z*v.z*(1-c) + c; - return m; -} - -Mat4 -Mat4::scale(const Vec3 &v) -{ - Mat4 m(1.0f); - m.e[0][0] = v.x; - m.e[1][1] = v.y; - m.e[2][2] = v.z; - return m; -} - -Mat4 -Mat4::transpose(void) const -{ - float e[4][4]; - for(int i = 0; i < 4; i++) - for(int j = 0; j < 4; j++){ - e[j][i] = this->e[i][j]; - e[i][j] = this->e[j][i]; - } - return Mat4(&e[0][0]); -} - -Mat4 -Mat4::operator+(const Mat4 &rhs) const -{ - float e[16]; - for(int i = 0; i < 4*4; i++) - e[i] = this->cr[i] + rhs.cr[i]; - return Mat4(e); -} - -Mat4 -Mat4::operator-(const Mat4 &rhs) const -{ - float e[16]; - for(int i = 0; i < 4*4; i++) - e[i] = this->cr[i] - rhs.cr[i]; - return Mat4(e); -} - -Mat4 -Mat4::operator*(float rhs) const -{ - float e[16]; - for(int i = 0; i < 4*4; i++) - e[i] = this->cr[i]*rhs; - return Mat4(e); -} - -Mat4 -Mat4::operator/(float rhs) const -{ - float e[16]; - for(int i = 0; i < 4*4; i++) - e[i] = this->cr[i]/rhs; - return Mat4(e); -} - -Mat4 -Mat4::operator*(const Mat4 &rhs) const -{ - float e[4][4]; - for(int i = 0; i < 4; i++) - for(int j = 0; j < 4; j++) - e[i][j] = this->e[0][j]*rhs.e[i][0] + - this->e[1][j]*rhs.e[i][1] + - this->e[2][j]*rhs.e[i][2] + - this->e[3][j]*rhs.e[i][3]; - return Mat4(&e[0][0]); -} - -Vec4 -Mat4::operator*(const Vec4 &rhs) const -{ - float e[4]; - for(int i = 0; i < 4; i++) - e[i] = this->e[0][i]*rhs.x + - this->e[1][i]*rhs.y + - this->e[2][i]*rhs.z + - this->e[3][i]*rhs.w; - return Vec4(e); -} - -Mat4& -Mat4::operator+=(const Mat4 &rhs) -{ - *this = *this + rhs; - return *this; -} - -Mat4& -Mat4::operator-=(const Mat4 &rhs) -{ - *this = *this - rhs; - return *this; -} - -Mat4& -Mat4::operator*=(float rhs) -{ - *this = *this * rhs; - return *this; -} - -Mat4& -Mat4::operator/=(float rhs) -{ - *this = *this / rhs; - return *this; -} - -Mat4& -Mat4::operator*=(const Mat4 &rhs) -{ - *this = *this * rhs; - return *this; -} - -void -Mat4::print(std::ostream &of) const -{ - #define CM << ", " << - of << "M4(" << e[0][0] CM e[1][0] CM e[2][0] CM e[3][0] << std::endl; - of << " " << e[0][1] CM e[1][1] CM e[2][1] CM e[3][1] << std::endl; - of << " " << e[0][2] CM e[1][2] CM e[2][2] CM e[3][2] << std::endl; - of << " " << e[0][3] CM e[1][3] CM e[2][3] CM e[3][3] << ")"; - #undef CM -} - - - - - -Vec3::Vec3(const Vec4 &v) - : x(v.x), y(v.y), z(v.z) -{ -} - -Vec3::Vec3(const Quat &q) - : x(q.x), y(q.y), z(q.z) -{ -} - -Vec4::Vec4(const Vec3 &v, float w) - : x(v.x), y(v.y), z(v.z), w(w) -{ -} - -Vec4::Vec4(const Quat &q) - : x(q.x), y(q.y), z(q.z), w(q.w) -{ -} - -Quat::Quat(const Vec3 &v) - : w(0), x(v.x), y(v.y), z(v.z) -{ -} - -Quat::Quat(float w, const Vec3 &v) - : w(w), x(v.x), y(v.y), z(v.z) -{ -} - -Quat::Quat(const Vec4 &v) - : w(v.w), x(v.x), y(v.y), z(v.z) -{ -} - -Quat::Quat(const Mat3 &m) -{ - float trace, s, q[4]; - int i, j, k; - - int nxt[3] = {1, 2, 0}; - - trace = m.e[0][0] + m.e[1][1] + m.e[2][2]; - if(trace > 0.0f){ - s = sqrt(trace + 1.0f); - this->w = s / 2.0f; - s = 0.5f / s; - this->x = (m.e[2][1] - m.e[1][2]) * s; - this->y = (m.e[0][2] - m.e[2][0]) * s; - this->z = (m.e[1][0] - m.e[0][1]) * s; - }else{ - i = 0; - if(m.e[1][1] > m.e[0][0]) i = 1; - if(m.e[2][2] > m.e[i][i]) i = 2; - j = nxt[i]; - k = nxt[j]; - s = sqrt((m.e[i][i] - m.e[j][j] - m.e[k][k]) + 1.0); - q[i] = s*0.5f; - if(q[i] != 0.0f) s = 0.5f / s; - q[3] = (m.e[k][j] - m.e[j][k]) * s; - q[j] = (m.e[j][i] + m.e[i][j]) * s; - q[k] = (m.e[k][i] + m.e[i][k]) * s; - this->w = q[3]; - this->x = q[0]; - this->y = q[1]; - this->z = q[2]; - } -} - -Mat3::Mat3(const Mat4 &m) -{ - for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++) - this->e[i][j] = m.e[i][j]; -} - -Mat4::Mat4(const Mat3 &m) -{ - for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++) - this->e[i][j] = m.e[i][j]; - this->e[0][3] = 0.0f; - this->e[1][3] = 0.0f; - this->e[2][3] = 0.0f; - this->e[3][3] = 1.0f; - this->e[3][2] = 0.0f; - this->e[3][1] = 0.0f; - this->e[3][0] = 0.0f; -} - -Mat3 -Mat3::rotation(const Quat &v) -{ - Mat3 m(1.0f); - m.e[0][0] = v.w*v.w + v.x*v.x - v.y*v.y - v.z*v.z; - m.e[1][0] = 2*v.x*v.y - 2*v.w*v.z; - m.e[2][0] = 2*v.w*v.y + 2*v.x*v.z; - m.e[0][1] = 2*v.w*v.z + 2*v.x*v.y; - m.e[1][1] = v.w*v.w - v.x*v.x + v.y*v.y - v.z*v.z; - m.e[2][1] = 2*v.y*v.z - 2*v.w*v.x; - m.e[0][2] = 2*v.x*v.z - 2*v.w*v.y; - m.e[1][2] = 2*v.w*v.x + 2*v.y*v.z; - m.e[2][2] = v.w*v.w - v.x*v.x - v.y*v.y + v.z*v.z; - return m; -} - -Mat4 -Mat4::rotation(const Quat &q) -{ - Mat4 m(1.0f); - m.e[0][0] = q.w*q.w + q.x*q.x - q.y*q.y - q.z*q.z; - m.e[1][0] = 2*q.x*q.y - 2*q.w*q.z; - m.e[2][0] = 2*q.w*q.y + 2*q.x*q.z; - m.e[0][1] = 2*q.w*q.z + 2*q.x*q.y; - m.e[1][1] = q.w*q.w - q.x*q.x + q.y*q.y - q.z*q.z; - m.e[2][1] = 2*q.y*q.z - 2*q.w*q.x; - m.e[0][2] = 2*q.x*q.z - 2*q.w*q.y; - m.e[1][2] = 2*q.w*q.x + 2*q.y*q.z; - m.e[2][2] = q.w*q.w - q.x*q.x - q.y*q.y + q.z*q.z; - return m; -} - -Mat4 -Mat4::transrot(const DQuat &q) -{ - const Quat &q1 = q.q1; - const Quat &q2 = q.q2; - Mat4 m(1.0f); - m.e[0][0] = q1.w*q1.w + q1.x*q1.x - q1.y*q1.y - q1.z*q1.z; - m.e[1][0] = 2*q1.x*q1.y - 2*q1.w*q1.z; - m.e[2][0] = 2*q1.w*q1.y + 2*q1.x*q1.z; - m.e[0][1] = 2*q1.w*q1.z + 2*q1.x*q1.y; - m.e[1][1] = q1.w*q1.w - q1.x*q1.x + q1.y*q1.y - q1.z*q1.z; - m.e[2][1] = 2*q1.y*q1.z - 2*q1.w*q1.x; - m.e[0][2] = 2*q1.x*q1.z - 2*q1.w*q1.y; - m.e[1][2] = 2*q1.w*q1.x + 2*q1.y*q1.z; - m.e[2][2] = q1.w*q1.w - q1.x*q1.x - q1.y*q1.y + q1.z*q1.z; - m.e[3][0] = 2*(q1.w*q2.x - q2.w*q1.x + q1.y*q2.z - q1.z*q2.y); - m.e[3][1] = 2*(q1.w*q2.y - q2.w*q1.y + q1.z*q2.x - q1.x*q2.z); - m.e[3][2] = 2*(q1.w*q2.z - q2.w*q1.z + q1.x*q2.y - q1.y*q2.x); - return m; -} - diff --git a/tools/d3d9/math/conversion.h b/tools/d3d9/math/conversion.h deleted file mode 100644 index 01e7897..0000000 --- a/tools/d3d9/math/conversion.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef MATH_CONVERSION_H -#define MATH_CONVERSION_H - -Vec3::Vec3(const Vec4 &v) - : x(v.x), y(v.y), z(v.z) -{ -} - -Vec3::Vec3(const Quat &q) - : x(q.x), y(q.y), z(q.z) -{ -} - -Vec4::Vec4(const Vec3 &v, float w) - : x(v.x), y(v.y), z(v.z), w(w) -{ -} - -Vec4::Vec4(const Quat &q) - : x(q.x), y(q.y), z(q.z), w(q.w) -{ -} - -Quat::Quat(const Vec3 &v) - : x(v.x), y(v.y), z(v.z) -{ -} - -Quat::Quat(float w, const Vec3 &v) - : w(w), x(v.x), y(v.y), z(v.z) -{ -} - -Quat::Quat(const Vec4 &v) - : w(v.w), x(v.x), y(v.y), z(v.z) -{ -} - -Mat3::Mat3(const Mat4 &m) -{ - for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++) - this->e[i][j] = m.e[i][j]; -} - -Mat4::Mat4(const Mat3 &m) -{ - for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++) - this->e[i][j] = m.e[i][j]; - this->e[0][3] = 0.0f; - this->e[1][3] = 0.0f; - this->e[2][3] = 0.0f; - this->e[3][3] = 1.0f; - this->e[3][2] = 0.0f; - this->e[3][1] = 0.0f; - this->e[3][0] = 0.0f; -} - -Mat4 -Mat4::rotation(const Quat &v) -{ - Mat4 m(1.0f); - m.e[0][0] = v.w*v.w + v.x*v.x - v.y*v.y - v.z*v.z; - m.e[1][0] = 2*v.x*v.y - 2*v.w*v.z; - m.e[2][0] = 2*v.w*v.y + 2*v.x*v.z; - m.e[0][1] = 2*v.w*v.z + 2*v.x*v.y; - m.e[1][1] = v.w*v.w - v.x*v.x + v.y*v.y - v.z*v.z; - m.e[2][1] = 2*v.y*v.z - 2*v.w*v.x; - m.e[0][2] = 2*v.x*v.z - 2*v.w*v.y; - m.e[1][2] = 2*v.w*v.x + 2*v.y*v.z; - m.e[2][2] = v.w*v.w - v.x*v.x - v.y*v.y + v.z*v.z; - return m; -} - -Mat3 -Mat3::rotation(const Quat &v) -{ - Mat3 m(1.0f); - m.e[0][0] = v.w*v.w + v.x*v.x - v.y*v.y - v.z*v.z; - m.e[1][0] = 2*v.x*v.y - 2*v.w*v.z; - m.e[2][0] = 2*v.w*v.y + 2*v.x*v.z; - m.e[0][1] = 2*v.w*v.z + 2*v.x*v.y; - m.e[1][1] = v.w*v.w - v.x*v.x + v.y*v.y - v.z*v.z; - m.e[2][1] = 2*v.y*v.z - 2*v.w*v.x; - m.e[0][2] = 2*v.x*v.z - 2*v.w*v.y; - m.e[1][2] = 2*v.w*v.x + 2*v.y*v.z; - m.e[2][2] = v.w*v.w - v.x*v.x - v.y*v.y + v.z*v.z; - return m; -} - -#endif - diff --git a/tools/d3d9/math/dquat.h b/tools/d3d9/math/dquat.h deleted file mode 100644 index 2690cea..0000000 --- a/tools/d3d9/math/dquat.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef MATH_DQUAT_H -#define MATH_DQUAT_H - -#include -#include - -class Vec3; -class Vec4; - -class DQuat { -public: - Quat q1, q2; - - DQuat(void); - DQuat(const Quat &q1, const Quat &q2); - DQuat operator-(void) const; - DQuat operator+(const DQuat &rhs) const; - DQuat operator-(const DQuat &rhs) const; - DQuat operator*(const DQuat &rhs) const; - DQuat operator*(float rhs) const; - DQuat operator/(float rhs) const; - DQuat &operator+=(const DQuat &rhs); - DQuat &operator-=(const DQuat &rhs); - DQuat &operator*=(const DQuat &rhs); - DQuat &operator*=(float rhs); - DQuat &operator/=(float rhs); - bool operator==(const DQuat &rhs) const; - bool operator!=(const DQuat &rhs) const; - -// DQuat inv(void) const; - DQuat K(void) const; /* conjugate */ -// DQuat S(void) const; /* scalar */ -// DQuat V(void) const; /* vector */ -// float T(void) const; /* tensor */ -// float N(void) const; /* norm = tensor^2 */ -// DQuat U(void) const; /* versor */ -// DQuat wedge(const Quat &rhs) const; -// float inner(const Quat &rhs) const; -// DQuat slerp(const Quat &rhs, float t) const; - - void print(std::ostream &of) const; -}; - -#endif - diff --git a/tools/d3d9/math/mat3.h b/tools/d3d9/math/mat3.h deleted file mode 100644 index e1c6034..0000000 --- a/tools/d3d9/math/mat3.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef MATH_MATRIX3_H -#define MATH_MATRIX3_H - -#include -#include - -class Mat4; - -class Mat3 { -public: - union { - float e[3][3]; - float cr[9]; - }; - - Mat3(void); - Mat3(float f); - Mat3(float *f); - Mat3(float e00, float e10, float e20, - float e01, float e11, float e21, - float e02, float e12, float e22); - Mat3(const Mat4 &m); - float *ptr(void); - static Mat3 rotation(float theta, const Vec3 &v); - static Mat3 rotation(const Quat &v); - static Mat3 scale(const Vec3 &v); - Mat3 transpose(void) const; - Mat3 operator+(const Mat3 &rhs) const; - Mat3 operator-(const Mat3 &rhs) const; - Mat3 operator*(float rhs) const; - Mat3 operator/(float rhs) const; - Mat3 operator*(const Mat3 &rhs) const; - Vec3 operator*(const Vec3 &rhs) const; - Mat3 &operator+=(const Mat3 &rhs); - Mat3 &operator-=(const Mat3 &rhs); - Mat3 &operator*=(float rhs); - Mat3 &operator/=(float rhs); - Mat3 &operator*=(const Mat3 &rhs); - void print(std::ostream &of) const; -}; - -#endif - diff --git a/tools/d3d9/math/mat4.h b/tools/d3d9/math/mat4.h deleted file mode 100644 index 1bac359..0000000 --- a/tools/d3d9/math/mat4.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef MATH_MATRIX4_H -#define MATH_MATRIX4_H - -#include -#include - -class Mat3; - -class Mat4 { -public: - union { - float e[4][4]; - float cr[16]; - }; - - Mat4(void); - Mat4(float f); - Mat4(float *f); - Mat4(float e00, float e10, float e20, float e30, - float e01, float e11, float e21, float e31, - float e02, float e12, float e22, float e32, - float e03, float e13, float e23, float e33); - Mat4(const Mat3 &m); - float *ptr(void); - static Mat4 perspective(float fov, float aspect, float n, float f); - static Mat4 frustum(float l, float r, float b, float t, - float n, float f); - static Mat4 ortho(float l, float r, float b, float t, - float n, float f); - static Mat4 lookat(const Vec3 &pos, const Vec3 &target, const Vec3 &up); - static Mat4 translation(const Vec3 &v); - static Mat4 rotation(float theta, const Vec3 &v); - static Mat4 rotation(const Quat &q); - static Mat4 transrot(const DQuat &q); - static Mat4 scale(const Vec3 &v); - Mat4 transpose(void) const; - Mat4 operator+(const Mat4 &rhs) const; - Mat4 operator-(const Mat4 &rhs) const; - Mat4 operator*(float rhs) const; - Mat4 operator/(float rhs) const; - Mat4 operator*(const Mat4 &rhs) const; - Vec4 operator*(const Vec4 &rhs) const; - Mat4 &operator+=(const Mat4 &rhs); - Mat4 &operator-=(const Mat4 &rhs); - Mat4 &operator*=(float rhs); - Mat4 &operator/=(float rhs); - Mat4 &operator*=(const Mat4 &rhs); - void print(std::ostream &of) const; -}; - -#endif - diff --git a/tools/d3d9/math/math.h b/tools/d3d9/math/math.h deleted file mode 100644 index 0c04fa3..0000000 --- a/tools/d3d9/math/math.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef MATH_H -#define MATH_H - -#include "vec3.h" -#include "vec4.h" -#include "quat.h" -#include "dquat.h" -#include "mat3.h" -#include "mat4.h" - -std::ostream &operator<<(std::ostream& of, const Vec3 &v); -std::ostream &operator<<(std::ostream& of, const Vec4 &v); -std::ostream &operator<<(std::ostream& of, const Quat &v); -std::ostream &operator<<(std::ostream& of, const DQuat &v); -std::ostream &operator<<(std::ostream& of, const Mat3 &v); -std::ostream &operator<<(std::ostream& of, const Mat4 &v); - -#define PI 3.14159265359f - - -#endif diff --git a/tools/d3d9/math/quat.h b/tools/d3d9/math/quat.h deleted file mode 100644 index 7da753a..0000000 --- a/tools/d3d9/math/quat.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef MATH_QUAT_H -#define MATH_QUAT_H - -#include -#include - -class Vec3; -class Vec4; -class Mat3; - -/* Hamilton style */ - -class Quat { -public: - float w, x, y, z; - - Quat(void); - Quat(float w); - Quat(float x, float y, float z); - Quat(float w, float x, float y, float z); - Quat(float w, const Vec3 &v); - Quat(const Vec3 &v); - Quat(const Vec4 &v); - Quat(const Mat3 &m); - float *ptr(void); - Quat operator-(void) const; - Quat operator+(const Quat &rhs) const; - Quat operator-(const Quat &rhs) const; - Quat operator*(const Quat &rhs) const; - Quat operator*(float rhs) const; - Quat operator/(float rhs) const; - Quat &operator+=(const Quat &rhs); - Quat &operator-=(const Quat &rhs); - Quat &operator*=(const Quat &rhs); - Quat &operator*=(float rhs); - Quat &operator/=(float rhs); - bool operator==(const Quat &rhs) const; - bool operator!=(const Quat &rhs) const; - Quat inv(void) const; - Quat K(void) const; /* conjugate */ - Quat S(void) const; /* scalar */ - Quat V(void) const; /* vector */ - float T(void) const; /* tensor */ - float N(void) const; /* norm = tensor^2 */ - Quat U(void) const; /* versor */ - Quat wedge(const Quat &rhs) const; - float inner(const Quat &rhs) const; - Quat lerp(const Quat &rhs, float t) const; - Quat slerp(const Quat &rhs, float t) const; - void print(std::ostream &of) const; -}; - -#endif - diff --git a/tools/d3d9/math/vec3.h b/tools/d3d9/math/vec3.h deleted file mode 100644 index 5b21593..0000000 --- a/tools/d3d9/math/vec3.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef MATH_VECTOR3_H -#define MATH_VECTOR3_H - -#include -#include - -class Vec4; -class Quat; - -class Vec3 { -public: - float x, y, z; - - Vec3(void); - Vec3(float x, float y, float z); - Vec3(float *v); - Vec3(const Vec4 &v); - Vec3(const Quat &q); - float *ptr(void); - Vec3 operator-(void) const; - Vec3 operator+(const Vec3 &rhs) const; - Vec3 operator-(const Vec3 &rhs) const; - Vec3 operator*(float rhs) const; - Vec3 operator/(float rhs) const; - Vec3 &operator+=(const Vec3 &rhs); - Vec3 &operator-=(const Vec3 &rhs); - Vec3 &operator*=(float rhs); - Vec3 &operator/=(float rhs); - bool operator==(const Vec3 &rhs) const; - bool operator!=(const Vec3 &rhs) const; - float norm(void) const; - float normsq(void) const; - Vec3 normalized(void) const; - float dot(const Vec3 &rhs) const; - Vec3 cross(const Vec3 &rhs) const; - void print(std::ostream &of) const; -}; - -#endif - diff --git a/tools/d3d9/math/vec4.h b/tools/d3d9/math/vec4.h deleted file mode 100644 index 90920f7..0000000 --- a/tools/d3d9/math/vec4.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef MATH_VECTOR4_H -#define MATH_VECTOR4_H - -#include -#include - -class Vec3; -class Quat; - -class Vec4 { -public: - float x, y, z, w; - - Vec4(void); - Vec4(float x, float y, float z, float w); - Vec4(float *v); - Vec4(const Vec3 &v, float w = 0.0f); - Vec4(const Quat &w); - float *ptr(void); - Vec4 operator-(void) const; - Vec4 operator+(const Vec4 &rhs) const; - Vec4 operator-(const Vec4 &rhs) const; - Vec4 operator*(float rhs) const; - Vec4 operator/(float rhs) const; - Vec4 &operator+=(const Vec4 &rhs); - Vec4 &operator-=(const Vec4 &rhs); - Vec4 &operator*=(float rhs); - Vec4 &operator/=(float rhs); - bool operator==(const Vec4 &rhs) const; - bool operator!=(const Vec4 &rhs) const; - float norm(void) const; - float normsq(void) const; - Vec4 normalized(void) const; - float dot(const Vec4 &rhs) const; - void print(std::ostream &of) const; -}; - -#endif - diff --git a/tools/dffwrite/dffwrite.cpp b/tools/dffwrite/dffwrite.cpp deleted file mode 100644 index e4daeb8..0000000 --- a/tools/dffwrite/dffwrite.cpp +++ /dev/null @@ -1,120 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include -#include - -using namespace std; -using namespace rw; - -int -main(int argc, char *argv[]) -{ -// rw::version = 0x31000; -// rw::build = 0; - -// rw::version = 0; -// rw::version = 0x32000; - rw::version = 0x33002; - rw::platform = PLATFORM_D3D8; -// rw::version = 0x30200; - - gta::attachPlugins(); - - rw::Clump *c; - - if(argc < 2){ - printf("usage: %s input.dff [output.dff]\n", argv[0]); - return 0; - } - -// rw::StreamFile in; -// in.open(argv[1], "rb"); - - ChunkHeaderInfo header; - if(0){ - FILE *cf = fopen(argv[1], "rb"); - assert(cf != NULL); - fseek(cf, 0, SEEK_END); - rw::uint32 len = ftell(cf); - fseek(cf, 0, SEEK_SET); - rw::uint8 *data = new rw::uint8[len]; - fread(data, len, 1, cf); - fclose(cf); - rw::StreamMemory in; - in.open(data, len); - - rw::findChunk(&in, rw::ID_CLUMP, NULL, NULL); - rw::debugFile = argv[1]; - c = rw::Clump::streamRead(&in); - assert(c != NULL); - - in.close(); - delete[] data; - }else{ - rw::StreamFile in; - if(in.open(argv[1], "rb") == NULL){ - printf("couldn't open file\n"); - return 1; - } - debugFile = argv[1]; - readChunkHeaderInfo(&in, &header); - if(header.type == ID_UVANIMDICT){ - UVAnimDictionary *dict = UVAnimDictionary::streamRead(&in); - currentUVAnimDictionary = dict; - readChunkHeaderInfo(&in, &header); - } - assert(header.type == ID_CLUMP); - c = Clump::streamRead(&in); - assert(c != NULL); - } - - if(rw::version == 0){ - rw::version = header.version; - rw::build = header.build; - } - -// rw::Image::setSearchPath("./;/home/aap/gamedata/ps2/gtavc/MODELS/gta3_archive/txd_extracted/"); - -/* -// rw::Image *tga = rw::readTGA("b.tga"); - rw::Image *tga = rw::readTGA("player.tga"); - assert(tga != NULL); - rw::writeTGA(tga, "out.tga"); -*/ - -// for(rw::int32 i = 0; i < c->numAtomics; i++) -// rw::Gl::Instance(c->atomicList[i]); - - if(0){ - uint8 *data = new rw::uint8[1024*1024]; - rw::StreamMemory out; - out.open(data, 0, 1024*1024); - - c->streamWrite(&out); - - FILE *cf = fopen(argv[2], "wb"); - assert(cf != NULL); - fwrite(data, out.getLength(), 1, cf); - fclose(cf); - out.close(); - delete[] data; - }else{ - rw::StreamFile out; - if(argc > 2) - out.open(argv[2], "wb"); - else - out.open("out.dff", "wb"); - c->streamWrite(&out); - out.close(); - } - - delete c; - - return 0; - -} diff --git a/tools/dffwrite/dffwrite.vcxproj b/tools/dffwrite/dffwrite.vcxproj deleted file mode 100644 index 3238f10..0000000 --- a/tools/dffwrite/dffwrite.vcxproj +++ /dev/null @@ -1,212 +0,0 @@ - - - - - Debug - null - Win32 - - - Debug - null - x64 - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {85F56A7D-6EA2-4B9B-806A-87AF6C577FDF} - dffwrite - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - - - - - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration)\ - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration)\ - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration)\ - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration)\ - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration)\ - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration)\ - - - - Level3 - Disabled - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - true - librw.lib;%(AdditionalDependencies) - - - - - Level3 - Disabled - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - true - librw.lib;%(AdditionalDependencies) - - - - - Level3 - Disabled - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - MultiThreadedDebug - - - true - librw.lib;%(AdditionalDependencies) - - - copy /y "$(TargetPath)" "C:\Users\aap\bin\" - - - - - Level3 - Disabled - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - MultiThreadedDebug - - - true - librw.lib;%(AdditionalDependencies) - - - copy /y "$(TargetPath)" "C:\Users\aap\bin\" - - - - - Level3 - MaxSpeed - true - true - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - true - true - true - librw.lib;%(AdditionalDependencies) - - - - - Level3 - MaxSpeed - true - true - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - true - true - true - librw.lib;%(AdditionalDependencies) - - - - - - - - - \ No newline at end of file diff --git a/tools/insttest/Makefile b/tools/insttest/Makefile deleted file mode 100644 index e48cb77..0000000 --- a/tools/insttest/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# null, opengl -BUILD=null - -# e.g. null -> -DRW_NULL -BUILDDEF:=$(shell echo $(BUILD) | tr a-z A-Z | sed 's/^/-DRW_/') -SRC := insttest.cpp -OUT := insttest -INC := -I/usr/local/include -I../.. -CFLAGS=-Wall -Wextra -g $(BUILDDEF) -Wno-parentheses -Wno-write-strings #-Wconversion -LIB=../../librw-$(BUILD).a - -$(OUT): $(SRC) $(LIB) - $(CXX) $(CFLAGS) $(INC) $(SRC) $(LIB) -o $(OUT) - -clean: - rm -f $(OUT) diff --git a/tools/insttest/insttest.cpp b/tools/insttest/insttest.cpp deleted file mode 100644 index 7ec17ed..0000000 --- a/tools/insttest/insttest.cpp +++ /dev/null @@ -1,265 +0,0 @@ -#include -#include -#include -#include - -#include -#include -#include - -using namespace std; -using namespace rw; - -static struct { - char *str; - uint32 val; -} platforms[] = { - { "mobile", PLATFORM_OGL }, - { "ps2", PLATFORM_PS2 }, - { "xbox", PLATFORM_XBOX }, - { "d3d8", PLATFORM_D3D8 }, - { "d3d9", PLATFORM_D3D9 }, - { NULL, 0 } -}; - -char *argv0; - -void -usage(void) -{ - fprintf(stderr, "usage: %s [-u] [-i] [-s] [-v version] [-o platform] in.dff [out.dff]\n", argv0); - fprintf(stderr, "\t-u uninstance\n"); - fprintf(stderr, "\t-i instance\n"); - fprintf(stderr, "\t-v RW version, e.g. 33004 for 3.3.0.4\n"); - fprintf(stderr, "\t-o output platform. ps2, xbox, mobile, d3d8, d3d9\n"); - exit(1); -} - -void -dumpUVAnim(Animation *anim) -{ - UVAnimCustomData *cust = (UVAnimCustomData*)anim->customData; - printf(" %s", cust->name); - for(int i = 0; i < 8; i++) - printf(" %d", cust->nodeToUVChannel[i]); - printf("\n %d %x\n", anim->numFrames, anim->interpInfo->id); - UVAnimKeyFrame *kf = (UVAnimKeyFrame*)anim->keyframes; - for(int i = 0; i < anim->numFrames; i++){ - printf(" %f\n", kf->time); - printf(" %f %f %f %f %f %f\n", kf->uv[0], kf->uv[1], kf->uv[2], kf->uv[3], kf->uv[4], kf->uv[5]); - kf++; - } -} - -void -dumpFrameHier(Frame *frame, int ind = 0) -{ - for(int i = 0; i < ind; i++) - printf(" "); - char *name = gta::getNodeName(frame); - HAnimData *hanim = HAnimData::get(frame); - printf("*%s %d %d %s\n", name[0] ? name : "---", frame->objectList.count(), hanim->id, hanim->hierarchy ? "HIERARCHY" : ""); - if(hanim->hierarchy){ - HAnimHierarchy *h = hanim->hierarchy; - for(int i = 0; i < h->numNodes; i++){ - name = h->nodeInfo[i].frame ? gta::getNodeName(h->nodeInfo[i].frame) : ""; - printf("\t\t%d %d\t%p %s\n", h->nodeInfo[i].id, h->nodeInfo[i].flags, h->nodeInfo[i].frame, name); - - { - h->nodeInfo[i].frame->updateLTM(); - float *mat = h->nodeInfo[i].frame->ltm; - printf("[ [ %8.4f, %8.4f, %8.4f, %8.4f ]\n" - " [ %8.4f, %8.4f, %8.4f, %8.4f ]\n" - " [ %8.4f, %8.4f, %8.4f, %8.4f ]\n" - " [ %8.4f, %8.4f, %8.4f, %8.4f ] ]\n", - mat[0], mat[4], mat[8], mat[12], - mat[1], mat[5], mat[9], mat[13], - mat[2], mat[6], mat[10], mat[14], - mat[3], mat[7], mat[11], mat[15]); - } - } - } - for(Frame *child = frame->child; - child; child = child->next) - dumpFrameHier(child, ind+1); -} - -int -main(int argc, char *argv[]) -{ - gta::attachPlugins(); - - rw::version = 0; -// rw::version = 0x34003; -// rw::version = 0x33002; -// rw::platform = rw::PLATFORM_PS2; -// rw::platform = rw::PLATFORM_OGL; -// rw::platform = rw::PLATFORM_XBOX; - rw::platform = rw::PLATFORM_D3D8; -// rw::platform = rw::PLATFORM_D3D9; - - int uninstance = 0; - int instance = 0; - int outplatform = rw::PLATFORM_D3D8; - - char *s; - ARGBEGIN{ - case 'u': - uninstance++; - break; - case 'i': - instance++; - break; - case 'v': - sscanf(EARGF(usage()), "%x", &rw::version); - break; - case 'o': - s = EARGF(usage()); - for(int i = 0; platforms[i].str; i++){ - if(strcmp(platforms[i].str, s) == 0){ - outplatform = platforms[i].val; - goto found; - } - } - printf("unknown platform %s\n", s); - outplatform = PLATFORM_D3D8; - found: - break; - default: - usage(); - }ARGEND; - - if(uninstance && instance){ - fprintf(stderr, "cannot both instance and uninstance, choose one!\n"); - return 1; - } - - if(argc < 1) - usage(); - - Clump *c; - //uint32 len; - //uint8 *data = getFileContents(argv[0], &len); - //assert(data != NULL); - //StreamMemory in; - //in.open(data, len); - StreamFile in; - in.open(argv[0], "rb"); - currentUVAnimDictionary = NULL; - currentTexDictionary = TexDictionary::create(); - ChunkHeaderInfo header; - readChunkHeaderInfo(&in, &header); - if(header.type == ID_UVANIMDICT){ - UVAnimDictionary *dict = UVAnimDictionary::streamRead(&in); - currentUVAnimDictionary = dict; - readChunkHeaderInfo(&in, &header); - } - if(header.type != ID_CLUMP){ - in.close(); - return 0; - } - debugFile = argv[0]; - c = Clump::streamRead(&in); - assert(c != NULL); - in.close(); - -// printf("%s\n", argv[arg]); - -/* - for(int32 i = 0; i < c->numAtomics; i++){ - Atomic *a = c->atomicList[i]; - Pipeline *ap = a->pipeline; - Geometry *g = a->geometry; - for(int32 j = 0; j < g->numMaterials; j++){ - Pipeline *mp = g->materialList[j]->pipeline; - if(ap && mp) - printf("%s %x %x\n", argv[arg], ap->pluginData, mp->pluginData); - } - } -*/ - //FORLIST(lnk, c->lights){ - // Light *l = Light::fromClump(lnk); - // printf("%p %p\n", l, lnk); - // printf("%d %f %f %f\n", l->getType(), l->color.red, l->color.green, l->color.blue); - //} - - HAnimHierarchy *hier = HAnimHierarchy::find(c->getFrame()); - if(hier) - hier->attach(); - dumpFrameHier(c->getFrame()); - - //if(currentUVAnimDictionary){ - // FORLIST(lnk, currentUVAnimDictionary->animations){ - // UVAnimDictEntry *de = UVAnimDictEntry::fromDict(lnk); - // Animation *anim = de->anim; - // dumpUVAnim(anim); - // } - //} - - int32 platform = findPlatform(c); - if(platform){ - rw::platform = platform; - switchPipes(c, rw::platform); - } - - if(uninstance) - FORLIST(lnk, c->atomics){ - Atomic *a = Atomic::fromClump(lnk); - ObjPipeline *p = a->getPipeline(); - p->uninstance(a); - if(outplatform != PLATFORM_PS2) - ps2::unconvertADC(a->geometry); - } - - rw::platform = outplatform; - switchPipes(c, rw::platform); - - if(instance) - FORLIST(lnk, c->atomics){ - Atomic *a = Atomic::fromClump(lnk); - ObjPipeline *p = a->getPipeline(); - p->instance(a); - if(outplatform != PLATFORM_PS2) - ps2::convertADC(a->geometry); - } - - if(rw::version == 0){ - rw::version = header.version; - rw::build = header.build; - } - - StreamFile out; - if(argc > 1) - assert(out.open(argv[1], "wb")); - else - assert(out.open("out.dff", "wb")); - if(currentUVAnimDictionary) - currentUVAnimDictionary->streamWrite(&out); - c->streamWrite(&out); - out.close(); - -// data = new rw::uint8[1024*1024]; -// rw::StreamMemory out; -// out.open(data, 0, 1024*1024); -// if(currentUVAnimDictionary) -// currentUVAnimDictionary->streamWrite(&out); -// c->streamWrite(&out); -// -// FILE *cf; -// if(argc > 1) -// cf = fopen(argv[1], "wb"); -// else -// cf = fopen("out.dff", "wb"); -// assert(cf != NULL); -// fwrite(data, out.getLength(), 1, cf); -// fclose(cf); -// out.close(); -// delete[] data; - - c->destroy(); - if(currentUVAnimDictionary) - currentUVAnimDictionary->destroy(); - currentTexDictionary->destroy(); - - return 0; -} diff --git a/tools/insttest/insttest.vcxproj b/tools/insttest/insttest.vcxproj deleted file mode 100644 index 2f7fa4a..0000000 --- a/tools/insttest/insttest.vcxproj +++ /dev/null @@ -1,215 +0,0 @@ - - - - - Debug - null - Win32 - - - Debug - null - x64 - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {2592ED29-F258-4949-AB45-7B873BF697F7} - insttest - - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - - - - - - - - - - - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration) - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration) - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration) - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(SolutionDir)$(Platform)\$(Configuration);$(LibraryPath) - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(SolutionDir)$(Configuration) - - - $(VC_IncludePath);$(WindowsSDK_IncludePath);$(SolutionDir) - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(SolutionDir)$(Platform)\$(Configuration) - - - - Level3 - Disabled - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - true - librw.lib;%(AdditionalDependencies) - - - - - Level3 - Disabled - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - true - librw.lib;%(AdditionalDependencies) - - - - - Level3 - Disabled - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - MultiThreadedDebug - - - true - librw.lib;%(AdditionalDependencies) - - - copy /y "$(TargetPath)" "C:\Users\aap\bin\" - - - - - Level3 - Disabled - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - MultiThreadedDebugDLL - - - true - librw.lib;%(AdditionalDependencies) - - - copy /y "$(TargetPath)" "C:\Users\aap\bin\" - - - - - Level3 - MaxSpeed - true - true - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - true - true - true - librw.lib;%(AdditionalDependencies) - - - - - Level3 - MaxSpeed - true - true - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - true - true - true - librw.lib;%(AdditionalDependencies) - - - copy /y "$(TargetPath)" "C:\Users\aap\bin\" - - - - - - - - - \ No newline at end of file diff --git a/tools/rsltest/Makefile b/tools/rsltest/Makefile deleted file mode 100644 index ad55777..0000000 --- a/tools/rsltest/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# null, opengl -BUILD=null - -# e.g. null -> -DRW_NULL -BUILDDEF:=$(shell echo $(BUILD) | tr a-z A-Z | sed 's/^/-DRW_/') -SRC := rsl.cpp rsltest.cpp -OUT := rsltest -INC := -I/usr/local/include -I../.. -CFLAGS=-Wall -Wextra -g $(BUILDDEF) -Wno-parentheses -Wno-write-strings #-Wconversion -LIB=../../librw-$(BUILD).a - -$(OUT): $(SRC) $(LIB) - $(CXX) $(CFLAGS) $(INC) $(SRC) $(LIB) -o $(OUT) - -clean: - rm -f $(OUT) diff --git a/tools/rsltest/rsl.cpp b/tools/rsltest/rsl.cpp deleted file mode 100644 index 098b727..0000000 --- a/tools/rsltest/rsl.cpp +++ /dev/null @@ -1,701 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -using namespace std; -using namespace rw; -#include "rsl.h" - -static void matfxRead(Stream *stream, RslMaterial *mat); -static void hanimRead(Stream *stream, RslFrame *f); - -void -RslMatrixSetIdentity(RslMatrix *matrix) -{ - memset(matrix, 0, sizeof(RslMatrix)); - matrix->right.x = 1.0f; - matrix->up.y = 1.0f; - matrix->at.z = 1.0f; -} - -void -rslObjectHasFrameSetFrame(RslObjectHasFrame *object, RslFrame *f) -{ - if(object->object.parent) - rslLinkListRemoveLLLink(&object->lFrame); - rslObjectSetParent(object, f); - if(f){ - rslLinkListAddLLLink(&f->objectList, &object->lFrame); - f->root->object.privateFlags |= 1; - f->object.privateFlags |= 2; - } -} - -RslFrame* -RslFrameCreate(void) -{ - RslFrame *f = new RslFrame; - rslObjectInitialize(&f->object, 0, 0); - rslLinkListInitialize(&f->objectList); - RslMatrixSetIdentity(&f->modelling); - RslMatrixSetIdentity(&f->ltm); - f->child = NULL; - f->next = NULL; - f->root = f; - - f->nodeId = -1; - f->hier = NULL; - - f->name = NULL; - - f->hierId = 0; - return f; -} - -RslFrame* -RslFrameAddChild(RslFrame *parent, RslFrame *child) -{ - RslFrame *p = (RslFrame*)child->object.parent; - assert(p == NULL); - child->next = parent->child; - parent->child = child; - child->object.parent = parent; - child->root = parent->root; - child->root->object.privateFlags |= 1; - child->object.privateFlags |= 2; - return parent; -} - -int32 -RslFrameCount(RslFrame *f) -{ - int32 n = 1; - for(RslFrame *c = f->child; c; c = c->next) - n += RslFrameCount(c); - return n; -} - -RslFrame* -RslFrameForAllChildren(RslFrame *frame, RslFrameCallBack callBack, void *data) -{ - for(RslFrame *child = frame->child; - child; - child = child->next) - if(callBack(child, data) == NULL) - break; - return frame; -} - -struct StreamFrame -{ - RslV3d right, up, at, pos; - int32 parent; - int32 flags; -}; - -void -rslFrameListStreamRead(Stream *stream, rslFrameList *framelist) -{ - uint32 length; - StreamFrame strfrm; - RslFrame *f; - - assert(findChunk(stream, ID_STRUCT, NULL, NULL)); - stream->read(&framelist->numFrames, 4); - framelist->frames = new RslFrame*[framelist->numFrames]; - for(int32 i = 0; i < framelist->numFrames; i++){ - stream->read(&strfrm, sizeof(strfrm)); - f = RslFrameCreate(); - f->modelling.right = strfrm.right; - f->modelling.up = strfrm.up; - f->modelling.at = strfrm.at; - f->modelling.pos = strfrm.pos; - framelist->frames[i] = f; - if(strfrm.parent >= 0) - RslFrameAddChild(framelist->frames[strfrm.parent], f); - } - ChunkHeaderInfo header; - for(int32 i = 0; i < framelist->numFrames; i++){ - f = framelist->frames[i]; - assert(findChunk(stream, ID_EXTENSION, &length, NULL)); - while(length){ - readChunkHeaderInfo(stream, &header); - if(header.type == ID_HANIMPLUGIN){ - hanimRead(stream, f); - }else if(header.type == gta::ID_NODENAME){ - f->name = new char[header.length+1]; - memset(f->name, 0, header.length+1); - stream->read(f->name, header.length); - f->name[header.length] = '\0'; - }else{ - stream->seek(header.length); - } - length -= 12 + header.length; - } - } -} - -static RslFrame** -rslFrameListFill(RslFrame *f, RslFrame **flist) -{ - *flist++ = f; - if(f->next) - flist = rslFrameListFill(f->next, flist); - if(f->child) - flist = rslFrameListFill(f->child, flist); - return flist; -} - -void -rslFrameListInitialize(rslFrameList *frameList, RslFrame *root) -{ - frameList->numFrames = RslFrameCount(root); - frameList->frames = new RslFrame*[frameList->numFrames]; - rslFrameListFill(root, frameList->frames); -} - -RslHAnimHierarchy* -RslHAnimHierarchyCreate(int32 numNodes, uint32 *nodeFlags, int32 *nodeIDs, int32 flags, int32 maxKeySize) -{ - RslHAnimHierarchy *hier = new RslHAnimHierarchy; - memset(hier, 0, sizeof(RslHAnimHierarchy)); - if(maxKeySize < 0x24) - maxKeySize = 0x24; - hier->flags = flags; - hier->numNodes = numNodes; - hier->parentFrame = 0; - hier->maxKeyFrameSize = maxKeySize; - hier->currentKeyFrameSize = 0x24; - - int32 msz = numNodes*0x40 + 0x3f; - uint8 *p = new uint8[msz]; - memset(p, 0, msz); - hier->pMatrixArrayUnaligned = p; - uintptr ip = (uintptr)p; - ip &= ~0x3f; - hier->pMatrixArray = (float32*)ip; - - hier->pNodeInfo = new RslHAnimNodeInfo[numNodes]; - for(int32 i = 0; i < numNodes; i++){ - hier->pNodeInfo[i].id = nodeIDs[i]; - hier->pNodeInfo[i].index = i; - hier->pNodeInfo[i].flags = nodeFlags[i]; - hier->pNodeInfo[i].frame = NULL; - } - hier->parentHierarchy = hier; - return hier; -} - -static void -hanimRead(Stream *stream, RslFrame *f) -{ - int32 version; - int32 id; - int32 numNodes; - int32 flags; - int32 maxKeySize; - uint32 *nodeFlags; - int32 *nodeIDs; - - version = stream->readI32(); - assert(version == 0x100); - id = stream->readI32(); - f->nodeId = id; - numNodes = stream->readI32(); - if(numNodes == 0) - return; - - flags = stream->readI32(); - maxKeySize = stream->readI32(); - nodeFlags = new uint32[numNodes]; - nodeIDs = new int32[numNodes]; - memset(nodeFlags, 0, numNodes*4); - memset(nodeIDs, 0, numNodes*4); - for(int32 i = 0; i < numNodes; i++){ - nodeIDs[i] = stream->readI32(); - stream->readI32(); - nodeFlags[i] = stream->readI32(); - } - f->hier = RslHAnimHierarchyCreate(numNodes, nodeFlags, - nodeIDs, flags, maxKeySize); - delete[] nodeFlags; - delete[] nodeIDs; -} - - -RslAtomic* -RslAtomicCreate(void) -{ - RslAtomic *a = new RslAtomic; - memset(a, 0, sizeof(RslAtomic)); - rslObjectInitialize(&a->object, 1, 0); - a->object.object.flags = 5; - a->object.object.privateFlags |= 1; - rslObjectHasFrameSetFrame(&a->object, NULL); - return a; -} - -RslAtomic* -RslAtomicSetFrame(RslAtomic *atomic, RslFrame *frame) -{ - rslObjectHasFrameSetFrame(&atomic->object, frame); - return atomic; -} - -RslAtomic* -RslAtomicStreamRead(Stream *stream, rslFrameList *framelist) -{ - uint32 length; - int32 buf[4]; - RslAtomic *a; - assert(findChunk(stream, ID_STRUCT, NULL, NULL)); - stream->read(buf, 16); - a = RslAtomicCreate(); - a->object.object.flags = buf[2]; - assert(findChunk(stream, ID_GEOMETRY, NULL, NULL)); - - RslPS2ResEntryHeader res, *rp; - stream->read(&res, sizeof(RslPS2ResEntryHeader)); - RslGeometry *g = RslGeometryCreatePS2(res.size & 0xFFFFF); - rp = (RslPS2ResEntryHeader*)(g+1); - *rp++ = res; - stream->read(rp, (res.size&0xFFFFF)-sizeof(RslPS2ResEntryHeader)); - - rslMaterialListStreamRead(stream, &g->matList); - a->geometry = g; - RslAtomicSetFrame(a, framelist->frames[buf[0]]); - - // This is not how it's done in LCS, they got extensions wrong :( - // Geometry - ChunkHeaderInfo header; - assert(findChunk(stream, ID_EXTENSION, &length, NULL)); - while(length){ - readChunkHeaderInfo(stream, &header); - if(header.type == ID_SKIN){ - g->skin = RslSkinStreamRead(stream, g); - }else - stream->seek(header.length); - length -= 12 + header.length; - } - - // Atomic - assert(findChunk(stream, ID_EXTENSION, &length, NULL)); - while(length){ - readChunkHeaderInfo(stream, &header); - stream->seek(header.length); - length -= 12 + header.length; - } - return a; -} - -RslSkin* -RslSkinStreamRead(Stream *stream, RslGeometry *g) -{ - uint32 info; - RslSkin *skin = new RslSkin; - memset(skin, 0, sizeof(RslSkin)); - info = stream->readU32(); - // LCS is different here, doesn't matter - info &= 0xFF; - skin->numBones = info; - skin->numUsedBones = info; - skin->invMatrices = new float[skin->numBones*16]; - stream->read(skin->invMatrices, skin->numBones*16*4); - // TODO: allocate...if we'd really care - (void)g; - return skin; -} - - - -RslClump* -RslClumpCreate(void) -{ - RslClump *clump = new RslClump; - rslObjectInitialize(&clump->object, 2, 0); - rslLinkListInitialize(&clump->atomicList); - return clump; -} - -RslClump* -RslClumpStreamRead(Stream *stream) -{ - uint32 version, length; - int32 buf[3]; - int32 numAtomics; - rslFrameList framelist; - RslClump *clump; - - assert(findChunk(stream, ID_STRUCT, NULL, &version)); - if(version > 0x33000){ - stream->read(buf, 12); - numAtomics = buf[0]; - }else - stream->read(&numAtomics, 4); - - clump = RslClumpCreate(); - assert(findChunk(stream, ID_FRAMELIST, NULL, NULL)); - rslFrameListStreamRead(stream, &framelist); - clump->object.parent = framelist.frames[0]; - - for(int32 i = 0; i < numAtomics; i++){ - assert(findChunk(stream, ID_ATOMIC, NULL, &version)); - RslAtomic *a = RslAtomicStreamRead(stream, &framelist); - RslClumpAddAtomic(clump, a); - } - - ChunkHeaderInfo header; - assert(findChunk(stream, ID_EXTENSION, &length, NULL)); - while(length){ - readChunkHeaderInfo(stream, &header); - stream->seek(header.length); - length -= 12 + header.length; - } - delete[] framelist.frames; - return clump; -} - -RslClump* -RslClumpAddAtomic(RslClump *clump, RslAtomic *a) -{ - rslLinkListAddLLLink(&clump->atomicList, &a->inClumpLink); - a->clump = clump; - return clump; -} - -RslClump* -RslClumpForAllAtomics(RslClump *clump, RslAtomicCallBack callback, void *pData) -{ - RslAtomic *a; - RslLLLink *link; - for(link = rslLLLinkGetNext(&clump->atomicList.link); - link != rslLinkListGetTerminator(&clump->atomicList); - link = link->next){ - a = rslLLLinkGetData(link, RslAtomic, inClumpLink); - if(callback(a, pData) == NULL) - break; - } - return clump; -} - -int32 -RslClumpGetNumAtomics(RslClump *clump) -{ - int32 n = 0; - RslLLLink *link; - for(link = rslLLLinkGetNext(&clump->atomicList.link); - link != rslLinkListGetTerminator(&clump->atomicList); - link = link->next) - n++; - return n; -} - -RslGeometry* -RslGeometryCreatePS2(uint32 sz) -{ - sz += sizeof(RslGeometry); - RslGeometry *g = (RslGeometry*)new uint8[sz]; - memset(g, 0, sz); - rslObjectInitialize(&g->object, 8, 0); - g->refCount = 1; - return g; -} - -RslGeometry* -RslGeometryForAllMaterials(RslGeometry *geometry, RslMaterialCallBack fpCallBack, void *pData) -{ - for(int32 i = 0; i < geometry->matList.numMaterials; i++) - if(fpCallBack(geometry->matList.materials[i], pData) == NULL) - break; - return geometry; -} - -struct RslMaterialChunkInfo -{ - int32 flags; - RGBA color; // used - int32 unused; - bool32 textured; // used - SurfaceProperties surfaceProps; -}; - -RslMaterial* -RslMaterialCreate(void) -{ - RslMaterial *mat = new RslMaterial; - mat->texture = NULL; - mat->color.red = 255; - mat->color.green = 255; - mat->color.blue = 255; - mat->color.alpha = 255; - mat->refCount = 1; - mat->matfx = NULL; - return mat; -} - -RslMaterial* -RslMaterialStreamRead(Stream *stream) -{ - uint32 length; - RslMaterialChunkInfo chunk; - assert(findChunk(stream, ID_STRUCT, NULL, NULL)); - stream->read(&chunk, sizeof(chunk)); - RslMaterial *mat = RslMaterialCreate(); - mat->color = chunk.color; - if(chunk.textured) - mat->texture = RslTextureStreamRead(stream); - - ChunkHeaderInfo header; - assert(findChunk(stream, ID_EXTENSION, &length, NULL)); - while(length){ - readChunkHeaderInfo(stream, &header); - if(header.type == ID_MATFX) - matfxRead(stream, mat); - else - stream->seek(header.length); - length -= 12 + header.length; - } - return mat; -} - -void -RslMatFXMaterialSetEffects(RslMaterial *mat, int32 effect) -{ - if(effect != MatFX::NOTHING){ - if(mat->matfx == NULL){ - mat->matfx = new RslMatFX; - memset(mat->matfx, 0, sizeof(RslMatFX)); - } - mat->matfx->effectType = effect; - }else{ - RslMatFX *matfx = mat->matfx; - if(matfx->env.texture) - RslTextureDestroy(matfx->env.texture); - delete matfx; - mat->matfx = NULL; - } -} - -static void -matfxRead(Stream *stream, RslMaterial *mat) -{ - int32 effect = stream->readI32(); - RslMatFXMaterialSetEffects(mat, effect); - if(effect == MatFX::BUMPMAP){ - stream->seek(12); - return; - } - RslMatFX *mfx = mat->matfx; - int32 type = stream->readI32(); - float32 coef; - int32 fbalpha; - switch(type){ - case MatFX::ENVMAP: - coef = stream->readF32(); - fbalpha = stream->readI32(); - (void)fbalpha; - mfx->env.frame = NULL; - mfx->env.texture = RslTextureStreamRead(stream); - mfx->env.intensity = coef; - break; - case MatFX::BUMPMAP: - coef = stream->readF32(); - break; - } -} - -void -rpMaterialListAppendMaterial(RslMaterialList *matlist, RslMaterial *mat) -{ - if(matlist->space <= matlist->numMaterials){ - RslMaterial **mats = matlist->materials; - matlist->materials = new RslMaterial*[matlist->space+16]; - if(matlist->space) - memcpy(matlist->materials, mats, matlist->space*sizeof(RslMaterial*)); - matlist->space += 16; - delete[] mats; - } - matlist->materials[matlist->numMaterials++] = mat; -} - -void -rslMaterialListStreamRead(Stream *stream, RslMaterialList *matlist) -{ - int32 numMaterials; - RslMaterial *mat; - assert(findChunk(stream, ID_MATLIST, NULL, NULL)); - assert(findChunk(stream, ID_STRUCT, NULL, NULL)); - numMaterials = stream->readI32(); - int32 *refs = new int32[numMaterials]; - stream->read(refs, 4*numMaterials); - for(int32 i = 0; i < numMaterials; i++){ - assert(refs[i] < 0); - assert(findChunk(stream, ID_MATERIAL, NULL, NULL)); - mat = RslMaterialStreamRead(stream); - rpMaterialListAppendMaterial(matlist, mat); - } - delete[] refs; -} - -RslTexDictionary* -RslTexDictionaryCreate(void) -{ - RslTexDictionary *dict = new RslTexDictionary; - memset(dict, 0, sizeof(RslTexDictionary)); - rslObjectInitialize(&dict->object, 6, 0); - rslLinkListInitialize(&dict->texturesInDict); - return dict; -} - -RslTexture* -RslTexDictionaryAddTexture(RslTexDictionary *dict, RslTexture *tex) -{ - if(tex->dict) - rslLinkListRemoveLLLink(&tex->lInDictionary); - tex->dict = dict; - rslLinkListAddLLLink(&dict->texturesInDict, &tex->lInDictionary); - return tex; -} - -RslTexDictionary* -RslTexDictionaryForAllTextures(RslTexDictionary *dict, RslTextureCallBack fpCallBack, void *pData) -{ - RslTexture *t; - RslLLLink *link; - for(link = rslLLLinkGetNext(&dict->texturesInDict.link); - link != rslLinkListGetTerminator(&dict->texturesInDict); - link = link->next){ - t = rslLLLinkGetData(link, RslTexture, lInDictionary); - if(fpCallBack(t, pData) == NULL) - break; - } - return dict; -} - -// TODO! -void -RslTextureDestroy(RslTexture *texture) -{ - delete texture; -} - -RslTexture* -RslTextureCreate(RslRaster *raster) -{ - RslTexture *tex = new RslTexture; - memset(tex, 0, sizeof(RslTexture)); - tex->raster = raster; - return tex; -} - -RslTexture* -RslTextureStreamRead(Stream *stream) -{ - uint32 length; - RslTexture *tex = RslTextureCreate(NULL); - assert(findChunk(stream, ID_TEXTURE, NULL, NULL)); - assert(findChunk(stream, ID_STRUCT, NULL, NULL)); - stream->readI32(); // filter addressing - assert(findChunk(stream, ID_STRING, &length, NULL)); - stream->read(tex->name, length); - assert(findChunk(stream, ID_STRING, &length, NULL)); - stream->read(tex->mask, length); - - ChunkHeaderInfo header; - assert(findChunk(stream, ID_EXTENSION, &length, NULL)); - while(length){ - readChunkHeaderInfo(stream, &header); - stream->seek(header.length); - length -= 12 + header.length; - } - return tex; -} - -static uint32 -guessSwizzling(uint32 w, uint32 h, uint32 d, uint32 mipmaps) -{ - uint32 swiz = 0; - for(uint32 i = 0; i < mipmaps; i++){ - switch(d){ - case 4: - if(w >= 32 && h >= 16) - swiz |= 1<= 16 && h >= 4) - swiz |= 1<flags = 0; - r->flags |= logw&0x3F; - r->flags |= (logh&0x3F)<<6; - r->flags |= d << 12; - r->flags |= mipmaps << 20; - uint32 swiz = guessSwizzling(w, h, d, mipmaps); - r->flags |= swiz << 24; - return (RslRaster*)r; -} - -RslTexture* -RslReadNativeTexturePS2(Stream *stream) -{ - RslPs2StreamRaster rasterInfo; - uint32 len; - uint32 buf[2]; - RslTexture *tex = RslTextureCreate(NULL); - assert(findChunk(stream, ID_STRUCT, NULL, NULL)); - stream->read(buf, sizeof(buf)); - assert(buf[0] == 0x00505350); /* "PSP\0" */ - assert(findChunk(stream, ID_STRING, &len, NULL)); - stream->read(tex->name, len); - assert(findChunk(stream, ID_STRING, &len, NULL)); - stream->read(tex->mask, len); - assert(findChunk(stream, ID_STRUCT, NULL, NULL)); - assert(findChunk(stream, ID_STRUCT, &len, NULL)); - stream->read(&rasterInfo, sizeof(rasterInfo)); - assert(findChunk(stream, ID_STRUCT, &len, NULL)); - tex->raster = RslCreateRasterPS2(rasterInfo.width, - rasterInfo.height, rasterInfo.depth, rasterInfo.mipmaps); - tex->raster->ps2.data = new uint8[len]; - stream->read(tex->raster->ps2.data, len); - assert(findChunk(stream, ID_EXTENSION, &len, NULL)); - stream->seek(len); - return tex; -} - -RslTexDictionary* -RslTexDictionaryStreamRead(Stream *stream) -{ - assert(findChunk(stream, ID_STRUCT, NULL, NULL)); - int32 numTex = stream->readI32(); - RslTexDictionary *txd = RslTexDictionaryCreate(); - for(int32 i = 0; i < numTex; i++){ - assert(findChunk(stream, ID_TEXTURENATIVE, NULL, NULL)); - RslTexture *tex = RslReadNativeTexturePS2(stream); - RslTexDictionaryAddTexture(txd, tex); - } - return txd; -} diff --git a/tools/rsltest/rsl.h b/tools/rsltest/rsl.h deleted file mode 100644 index e524f13..0000000 --- a/tools/rsltest/rsl.h +++ /dev/null @@ -1,481 +0,0 @@ -enum { - TEX_IDENT = 0x00746578, - MDL_IDENT = 0x006D646C, - WRLD_IDENT = 0x57524C44 -}; - -struct RslStream { - uint32 ident; - bool32 isMulti; - uint32 fileSize; - uint32 dataSize; - uint8 ***reloc; - uint32 relocSize; - uint8 **hashTab; // ?? - uint16 hashTabSize; - uint16 numAtomics; - - uint8 *data; - void relocate(void); -}; - -struct RslObject; -struct RslObjectHasFrame; -struct RslClump; -struct RslAtomic; -struct RslFrame; -struct RslNativeGeometry; -struct RslNativeMesh; -struct RslGeometry; -struct RslSkin; -struct RslMaterial; -struct RslHAnimHierarchy; -struct RslHAnimNode; -struct RslPS2ResEntryHeader; -struct RslPS2InstanceData; -struct RslTexDictionary; -struct RslTexture; - -typedef RslFrame *(*RslFrameCallBack)(RslFrame *frame, void *data); -typedef RslClump *(*RslClumpCallBack)(RslClump *clump, void *data); -typedef RslAtomic *(*RslAtomicCallBack)(RslAtomic *atomic, void *data); -typedef RslMaterial *(*RslMaterialCallBack)(RslMaterial *material, void *data); -typedef RslTexture *(*RslTextureCallBack)(RslTexture *texture, void *pData); - -struct RslV3d -{ - float32 x, y, z; -}; - -struct RslMatrix -{ - RslV3d right; - uint32 flags; - RslV3d up; - uint32 pad1; - RslV3d at; - uint32 pad2; - RslV3d pos; - uint32 pad3; -}; - -void RslMatrixSetIdentity(RslMatrix *matrix); - -struct RslLLLink -{ - RslLLLink *next; - RslLLLink *prev; -}; - -#define rslLLLinkGetData(linkvar,type,entry) \ - ((type*)(((uint8*)(linkvar))-offsetof(type,entry))) -#define rslLLLinkGetNext(linkvar) \ - ((linkvar)->next) -#define rslLLLinkGetPrevious(linkvar) \ - ((linkvar)->prev) -#define rslLLLinkInitialize(linkvar) \ - ((linkvar)->prev = (RslLLLink*)NULL, \ - (linkvar)->next = (RslLLLink*)NULL) -#define rslLLLinkAttached(linkvar) \ - ((linkvar)->next) - -struct RslLinkList -{ - RslLLLink link; -}; - -#define rslLinkListInitialize(list) \ - ((list)->link.next = ((RslLLLink*)(list)), \ - (list)->link.prev = ((RslLLLink*)(list))) -#define rslLinkListEmpty(list) \ - (((list)->link.next) == (&(list)->link)) -#define rslLinkListAddLLLink(list, linkvar) \ - ((linkvar)->next = (list)->link.next, \ - (linkvar)->prev = (&(list)->link), \ - ((list)->link.next)->prev = (linkvar), \ - (list)->link.next = (linkvar) ) -#define rslLinkListRemoveLLLink(linkvar) \ - (((linkvar)->prev)->next = (linkvar)->next, \ - ((linkvar)->next)->prev = (linkvar)->prev) -#define rslLinkListGetFirstLLLink(list) \ - ((list)->link.next) -#define rslLinkListGetLastLLLink(list) \ - ((list)->link.prev) -#define rslLinkListGetTerminator(list) \ - (&((list)->link)) - - -struct RslObject { - uint8 type; - uint8 subType; - uint8 flags; - uint8 privateFlags; - void *parent; -}; - -#define rslObjectInitialize(o, t, s) \ -{ \ - ((RslObject*)(o))->type = (uint8)(t); \ - ((RslObject*)(o))->subType = (uint8)(s); \ - ((RslObject*)(o))->flags = 0; \ - ((RslObject*)(o))->privateFlags = 0; \ - ((RslObject*)(o))->parent = NULL; \ -} - -#define rslObjectGetParent(object) (((RslObject*)(object))->parent) -#define rslObjectSetParent(c,p) (((RslObject*)(c))->parent) = (void*)(p) - -struct RslObjectHasFrame { - RslObject object; - RslLLLink lFrame; - void (*sync)(); -}; - -void rslObjectHasFrameSetFrame(RslObjectHasFrame *object, RslFrame *f); - -struct RslRasterPS2 { - uint8 *data; - uint32 flags; -}; - -struct RslRasterPSP { - uint32 unk1; - uint8 *data; - uint16 flags1; - uint8 width; // log of width - uint8 height; // log of height - uint32 flags2; -}; - -struct RslPs2StreamRaster { - uint32 width; - uint32 height; - uint32 depth; - uint32 mipmaps; - uint32 unused; -}; - -union RslRaster { - RslRasterPS2 ps2; - RslRasterPSP psp; -}; - -RslRaster *RslCreateRasterPS2(uint32 w, uint32 h, uint32 d, uint32 mipmaps); - -struct RslTexDictionary { - RslObject object; - RslLinkList texturesInDict; - RslLLLink lInInstance; -}; - -RslTexDictionary *RslTexDictionaryStreamRead(Stream *stream); -RslTexDictionary *RslTexDictionaryCreate(void); -RslTexture *RslTexDictionaryAddTexture(RslTexDictionary *dict, RslTexture *tex); -RslTexDictionary *RslTexDictionaryForAllTextures(RslTexDictionary *dict, RslTextureCallBack fpCallBack, void *pData); - -struct RslTexture { - RslRaster *raster; - RslTexDictionary *dict; - RslLLLink lInDictionary; - char name[32]; - char mask[32]; -}; - -RslTexture *RslTextureCreate(RslRaster *raster); -void RslTextureDestroy(RslTexture *texture); -RslTexture *RslTextureStreamRead(Stream *stream); -RslTexture *RslReadNativeTexturePS2(Stream *stream); - -struct RslFrame { - RslObject object; - RslLinkList objectList; - - RslMatrix modelling; - RslMatrix ltm; - RslFrame *child; - RslFrame *next; - RslFrame *root; - - // RwHAnimFrameExtension - int32 nodeId; - RslHAnimHierarchy *hier; - // R* Node name - char *name; - // R* Visibility - int32 hierId; -}; - -RslFrame *RslFrameCreate(void); -RslFrame *RslFrameAddChild(RslFrame *parent, RslFrame *child); -int32 RslFrameCount(RslFrame *f); -RslFrame *RslFrameForAllChildren(RslFrame *frame, RslFrameCallBack callBack, void *data); - -struct rslFrameList -{ - RslFrame **frames; - int32 numFrames; -}; - -void rslFrameListStreamRead(Stream *stream, rslFrameList *framelist); -void rslFrameListInitialize(rslFrameList *frameList, RslFrame *root); - -struct RslClump { - RslObject object; - RslLinkList atomicList; -}; - -#define RslClumpGetFrame(_clump) \ - ((RslFrame*)rslObjectGetParent(_clump)) - -#define RslClumpSetFrame(_clump, _frame) \ - (rslObjectSetParent(_clump, _frame), \ - (_clump)) - -RslClump *RslClumpCreate(void); -RslClump *RslClumpStreamRead(Stream *stream); -RslClump *RslClumpAddAtomic(RslClump *clump, RslAtomic *a); -int32 RslClumpGetNumAtomics(RslClump *clump); -RslClump *RslClumpForAllAtomics(RslClump *clump, RslAtomicCallBack callback, void *pData); - -struct RslAtomic { - RslObjectHasFrame object; - RslGeometry *geometry; - RslClump *clump; - RslLLLink inClumpLink; - - // what's this? rpWorldObj? - uint32 unk1; - uint16 unk2; - uint16 unk3; - // RpSkin - RslHAnimHierarchy *hier; - // what about visibility? matfx? - int32 pad; // 0xAAAAAAAA -}; - -#define RslAtomicGetFrame(_atomic) \ - ((RslFrame*)rslObjectGetParent(_atomic)) - -RslAtomic *RslAtomicCreate(void); -RslAtomic *RslAtomicSetFrame(RslAtomic *atomic, RslFrame *frame); -RslAtomic *RslAtomicStreamRead(Stream *stream, rslFrameList *framelist); - -struct RslMaterialList { - RslMaterial **materials; - int32 numMaterials; - int32 space; -}; - -void rslMaterialListStreamRead(Stream *stream, RslMaterialList *matlist); - -struct RslGeometry { - RslObject object; - int16 refCount; - int16 pad1; - - RslMaterialList matList; - - RslSkin *skin; - uint32 pad2; // 0xAAAAAAAA -}; - -RslGeometry *RslGeometryCreatePS2(uint32 sz); -RslGeometry *RslGeometryForAllMaterials(RslGeometry *geometry, RslMaterialCallBack fpCallBack, void *pData); - -struct RslMatFXEnv { - RslFrame *frame; - union { - char *texname; - RslTexture *texture; - }; - float32 intensity; -}; - -struct RslMatFX { - union { - RslMatFXEnv env; - }; - int32 effectType; -}; - -struct RslMaterial { - union { - char *texname; - RslTexture *texture; - }; - RGBA color; - uint32 refCount; - RslMatFX *matfx; -}; - -RslMaterial *RslMaterialCreate(void); -RslMaterial *RslMaterialStreamRead(Stream *stream); - -struct RslHAnimNodeInfo { - int8 id; - int8 index; - int8 flags; - RslFrame *frame; -}; - -struct RslHAnimHierarchy { - int32 flags; - int32 numNodes; - void *pCurrentAnim; - float32 currentTime; - void *pNextFrame; - void (*pAnimCallBack)(); - void *pAnimCallBackData; - float32 animCallBackTime; - void (*pAnimLoopCallBack)(); - void *pAnimLoopCallBackData; - float32 *pMatrixArray; - void *pMatrixArrayUnaligned; - RslHAnimNodeInfo *pNodeInfo; - RslFrame *parentFrame; - int32 maxKeyFrameSize; - int32 currentKeyFrameSize; - void (*keyFrameToMatrixCB)(); - void (*keyFrameBlendCB)(); - void (*keyFrameInterpolateCB)(); - void (*keyFrameAddCB)(); - RslHAnimHierarchy *parentHierarchy; - int32 offsetInParent; - int32 rootParentOffset; -}; - -struct RslSkin { - uint32 numBones; - uint32 numUsedBones; // == numBones - uint8 *usedBones; // NULL - float32 *invMatrices; - int32 numWeights; // 0 - uint8 *indices; // NULL - float32 *weights; // NULL - uint32 unk1; // 0 - uint32 unk2; // 0 - uint32 unk3; // 0 - uint32 unk4; // 0 - uint32 unk5; // 0 - void *data; // NULL -}; - -RslSkin *RslSkinStreamRead(Stream *stream, RslGeometry *g); - -struct RslPS2ResEntryHeader { - float32 bound[4]; - uint32 size; // and numMeshes - int32 flags; - uint32 unk1; - uint32 unk2; - uint32 unk3; - uint32 unk4; - float32 scale[3]; - float32 pos[3]; -}; - -struct RslPS2InstanceData { - float32 bound[4]; - float32 uvScale[2]; - int32 unknown; - uint32 dmaPacket; - uint16 numTriangles; - int16 matID; - int16 min[3]; // bounding box - int16 max[3]; -}; - -struct RslStreamHeader { - uint32 ident; - uint32 unk; - uint32 fileEnd; // - uint32 dataEnd; // relative to beginning of header - uint32 reloc; // - uint32 relocSize; - uint32 root; // absolute - uint16 zero; - uint16 numAtomics; -}; - -struct RslWorldGeometry { - uint16 numMeshes; - uint16 size; - // array of numMeshes RslWorldMesh - // dma data -}; - -struct RslWorldMesh { - uint16 texID; // index into resource table - uint16 dmaSize; - uint16 uvScale[2]; // half precision float - uint16 unk1; - int16 min[3]; // bounding box - int16 max[3]; -}; - -struct Resource { - union { - RslRaster *raster; - RslWorldGeometry *geometry; - uint8 *raw; - }; - uint32 *dma; -}; - -struct OverlayResource { - int32 id; - union { - RslRaster *raster; - RslWorldGeometry *geometry; - uint8 *raw; - }; -}; - -struct Placement { - uint16 id; - uint16 resId; - int16 bound[4]; - int32 pad; - float matrix[16]; -}; - -struct Sector { - OverlayResource *resources; - uint16 numResources; - uint16 unk1; - Placement *sectionA; - Placement *sectionB; - Placement *sectionC; - Placement *sectionD; - Placement *sectionE; - Placement *sectionF; - Placement *sectionG; - Placement *sectionEnd; - uint16 unk2; - uint16 unk3; - uint32 unk4; -}; - -struct SectorEntry { - RslStreamHeader *sector; - uint32 num; -}; - -struct World { - Resource *resources; - SectorEntry sectors[47]; - uint32 numResources; - uint8 pad[0x180]; - - uint32 numX; - void *tabX; // size 0x4 - - uint32 numY; - void *tabY; // size 0x30 - - uint32 numZ; - void *tabZ; // size 0x6 - - uint32 numTextures; - RslStreamHeader *textures; // stream headers -}; diff --git a/tools/rsltest/rsltest.cpp b/tools/rsltest/rsltest.cpp deleted file mode 100644 index 5a34b09..0000000 --- a/tools/rsltest/rsltest.cpp +++ /dev/null @@ -1,1029 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include - -using namespace std; -using namespace rw; -#include "rsl.h" - -char *argv0; -int32 atmOffset; - -void -RslStream::relocate(void) -{ - uint32 off = (uint32)(uintptr)this->data; - off -= 0x20; - *(uint32*)&this->reloc += off; - *(uint32*)&this->hashTab += off; - - uint8 **rel = (uint8**)this->reloc; - for(uint32 i = 0; i < this->relocSize; i++){ - rel[i] += off; - *this->reloc[i] += off; - } -} - - - -RslFrame *dumpFrameCB(RslFrame *frame, void *data) -{ - printf(" frm: %x %s %x\n", frame->nodeId, frame->name, frame->hierId); - RslFrameForAllChildren(frame, dumpFrameCB, data); - return frame; -} - -RslMaterial *dumpMaterialCB(RslMaterial *material, void*) -{ - printf(" mat: %d %d %d %d %s %x\n", material->color.red, material->color.green, material->color.blue, material->color.alpha, - material->texname, material->refCount); - if(material->matfx){ - RslMatFX *fx = material->matfx; - printf(" matfx: %d", fx->effectType); - if(fx->effectType == 2) - printf("env[%s %f] ", fx->env.texname, fx->env.intensity); - printf("\n"); - } - return material; -} - -RslAtomic *dumpAtomicCB(RslAtomic *atomic, void*) -{ - printf(" atm: %x %x %x %p\n", atomic->unk1, atomic->unk2, atomic->unk3, atomic->hier); - RslGeometry *g = atomic->geometry; - RslGeometryForAllMaterials(g, dumpMaterialCB, NULL); - return atomic; -} - -int32 -mapID(int32 id) -{ - if(id == 255) return -1; - if(id > 0x80) id |= 0x1300; - return id; -} - -static RslFrame* -findFrame(RslFrame *f, int32 id) -{ - if(f == NULL) return NULL; - if((f->nodeId & 0xFF) == (id & 0xFF)) - return f; - RslFrame *ff = findFrame(f->next, id); - if(ff) return ff; - return findFrame(f->child, id); -} - -static RslFrame* -findChild(RslFrame *f) -{ - for(RslFrame *c = f->child; c; c = c->next) - if(c->nodeId < 0) - return c; - return NULL; -} - -int32 nextId; - -struct Node { - int32 id; - int32 parent; -}; - -Frame* -convertFrame(RslFrame *f) -{ - Frame *rwf = Frame::create(); - rwf->matrix[0] = f->modelling.right.x; - rwf->matrix[1] = f->modelling.right.y; - rwf->matrix[2] = f->modelling.right.z; - rwf->matrix[4] = f->modelling.up.x; - rwf->matrix[5] = f->modelling.up.y; - rwf->matrix[6] = f->modelling.up.z; - rwf->matrix[8] = f->modelling.at.x; - rwf->matrix[9] = f->modelling.at.y; - rwf->matrix[10] = f->modelling.at.z; - rwf->matrix[12] = f->modelling.pos.x; - rwf->matrix[13] = f->modelling.pos.y; - rwf->matrix[14] = f->modelling.pos.z; - - if(f->name) - strncpy(gta::getNodeName(rwf), f->name, 24); - - HAnimData *hanim = PLUGINOFFSET(HAnimData, rwf, hAnimOffset); - hanim->id = f->nodeId; - if(f->hier){ - int32 numNodes = f->hier->numNodes; - int32 *nodeFlags = new int32[numNodes]; - int32 *nodeIDs = new int32[numNodes]; - - nextId = 2000; - Node *nodehier = new Node[numNodes]; - int32 stack[100]; - int32 sp = 0; - stack[sp] = -1; - // Match up nodes with frames to fix and assign IDs - // NOTE: assignment can only work reliably when not more - // than one child node needs an ID - for(int32 i = 0; i < numNodes; i++){ - RslHAnimNodeInfo *ni = &f->hier->pNodeInfo[i]; - Node *n = &nodehier[i]; - n->parent = stack[sp]; - if(ni->flags & HAnimHierarchy::PUSH) - sp++; - stack[sp] = i; - RslFrame *ff = findFrame(f, (uint8)ni->id); - n->id = ff->nodeId; - if(n->id < 0){ - ff = findFrame(f, nodehier[n->parent].id); - ff = findChild(ff); - n->id = ff->nodeId = nextId++; - } - //printf("%d %s %d %d\n", i, ff->name, n->id, n->parent); - if(ni->flags & HAnimHierarchy::POP) - sp--; - - nodeFlags[i] = ni->flags; - nodeIDs[i] = n->id; - } - - HAnimHierarchy *hier = HAnimHierarchy::create(numNodes, nodeFlags, nodeIDs, f->hier->flags, f->hier->maxKeyFrameSize); - hanim->hierarchy = hier; - - delete[] nodeFlags; - delete[] nodeIDs; - delete[] nodehier; - } - return rwf; -} - -Texture* -convertTexture(RslTexture *t) -{ - Texture *tex = Texture::read(t->name, t->mask); - //tex->refCount++; // ?? - if(tex->refCount == 1) - tex->filterAddressing = (Texture::WRAP << 12) | (Texture::WRAP << 8) | Texture::LINEAR; - return tex; -} - -Material* -convertMaterial(RslMaterial *m) -{ - Material *rwm; - rwm = Material::create(); - - rwm->color = m->color; - if(m->texture) - rwm->texture = convertTexture(m->texture); - - if(m->matfx){ - MatFX *matfx = new MatFX; - matfx->setEffects(m->matfx->effectType); - matfx->setEnvCoefficient(m->matfx->env.intensity); - if(m->matfx->env.texture) - matfx->setEnvTexture(convertTexture(m->matfx->env.texture)); - *PLUGINOFFSET(MatFX*, rwm, matFXGlobals.materialOffset) = matfx; - } - return rwm; -} - -static uint32 -unpackSize(uint32 unpack) -{ - if((unpack&0x6F000000) == 0x6F000000) - return 2; - static uint32 size[] = { 32, 16, 8, 16 }; - return ((unpack>>26 & 3)+1)*size[unpack>>24 & 3]/8; -} - -static uint32* -skipUnpack(uint32 *p) -{ - int32 n = (p[0] >> 16) & 0xFF; - return p + (n*unpackSize(p[0])+3 >> 2) + 1; -} - -void -convertMesh(Geometry *rwg, RslGeometry *g, int32 ii) -{ - RslPS2ResEntryHeader *resHeader = (RslPS2ResEntryHeader*)(g+1); - RslPS2InstanceData *inst = (RslPS2InstanceData*)(resHeader+1); - int32 numInst = resHeader->size >> 20; - uint8 *p = (uint8*)(inst+numInst); - inst += ii; - p += inst->dmaPacket; - Mesh *m = &rwg->meshHeader->mesh[inst->matID]; - - ps2::SkinVertex v; - uint32 mask = 0x1001; // tex coords, vertices - if(rwg->geoflags & Geometry::NORMALS) - mask |= 0x10; - if(rwg->geoflags & Geometry::PRELIT) - mask |= 0x100; - Skin *skin = *PLUGINOFFSET(Skin*, rwg, skinGlobals.offset); - if(skin) - mask |= 0x10000; - - int16 *vuVerts = NULL; - int8 *vuNorms = NULL; - uint8 *vuTex = NULL; - uint16 *vuCols = NULL; - uint32 *vuSkin = NULL; - - uint32 *w = (uint32*)p; - uint32 *end = (uint32*)(p + ((w[0] & 0xFFFF) + 1)*0x10); - w += 4; - int32 nvert; - bool first = 1; - while(w < end){ - /* Get data pointers */ - - // GIFtag probably - assert(w[0] == 0x6C018000); // UNPACK - nvert = w[4] & 0x7FFF; - if(!first) nvert -=2; - w += 5; - - // positions - assert(w[0] == 0x20000000); // STMASK - w += 2; - assert(w[0] == 0x30000000); // STROW - w += 5; - assert((w[0] & 0xFF004000) == 0x79000000); - vuVerts = (int16*)(w+1); - if(!first) vuVerts += 2*3; - w = skipUnpack(w); - - // tex coords - assert(w[0] == 0x20000000); // STMASK - w += 2; - assert(w[0] == 0x30000000); // STROW - w += 5; - assert((w[0] & 0xFF004000) == 0x76004000); - vuTex = (uint8*)(w+1); - if(!first) vuTex += 2*2; - w = skipUnpack(w); - - if(rwg->geoflags & Geometry::NORMALS){ - assert((w[0] & 0xFF004000) == 0x6A000000); - vuNorms = (int8*)(w+1); - if(!first) vuNorms += 2*3; - w = skipUnpack(w); - } - - if(rwg->geoflags & Geometry::PRELIT){ - assert((w[0] & 0xFF004000) == 0x6F000000); - vuCols = (uint16*)(w+1); - if(!first) vuCols += 2; - w = skipUnpack(w); - } - - if(skin){ - assert((w[0] & 0xFF004000) == 0x6C000000); - vuSkin = w+1; - if(!first) vuSkin += 2*4; - w = skipUnpack(w); - } - - assert(w[0] == 0x14000006); // MSCAL - w++; - while(w[0] == 0) w++; - - /* Insert Data */ - for(int32 i = 0; i < nvert; i++){ - v.p[0] = vuVerts[0]/32768.0f*resHeader->scale[0] + resHeader->pos[0]; - v.p[1] = vuVerts[1]/32768.0f*resHeader->scale[1] + resHeader->pos[1]; - v.p[2] = vuVerts[2]/32768.0f*resHeader->scale[2] + resHeader->pos[2]; - v.t[0] = vuTex[0]/128.0f*inst->uvScale[0]; - v.t[1] = vuTex[1]/128.0f*inst->uvScale[1]; - if(mask & 0x10){ - v.n[0] = vuNorms[0]/127.0f; - v.n[1] = vuNorms[1]/127.0f; - v.n[2] = vuNorms[2]/127.0f; - } - if(mask & 0x100){ - v.c[0] = (vuCols[0] & 0x1f) * 255 / 0x1F; - v.c[1] = (vuCols[0]>>5 & 0x1f) * 255 / 0x1F; - v.c[2] = (vuCols[0]>>10 & 0x1f) * 255 / 0x1F; - v.c[3] = vuCols[0]&0x8000 ? 0xFF : 0; - } - if(mask & 0x10000){ - for(int j = 0; j < 4; j++){ - ((uint32*)v.w)[j] = vuSkin[j] & ~0x3FF; - v.i[j] = vuSkin[j] >> 2; - //if(v.i[j]) v.i[j]--; - if(v.w[j] == 0.0f) v.i[j] = 0; - } - } - - int32 idx = ps2::findVertexSkin(rwg, NULL, mask, &v); - if(idx < 0) - idx = rwg->numVertices++; - /* Insert mesh joining indices when we get the index of the first vertex - * in the first VU chunk of a non-first RslMesh. */ - if(i == 0 && first && ii != 0 && inst[-1].matID == inst->matID){ - m->indices[m->numIndices] = m->indices[m->numIndices-1]; - m->numIndices++; - m->indices[m->numIndices++] = idx; - if(inst[-1].numTriangles % 2) - m->indices[m->numIndices++] = idx; - } - m->indices[m->numIndices++] = idx; - ps2::insertVertexSkin(rwg, idx, mask, &v); - - vuVerts += 3; - vuTex += 2; - vuNorms += 3; - vuCols++; - vuSkin += 4; - } - first = 0; - } -} - -Atomic* -convertAtomic(RslAtomic *atomic) -{ - Atomic *rwa = Atomic::create(); - RslGeometry *g = atomic->geometry; - Geometry *rwg = Geometry::create(0, 0, 0); - rwa->geometry = rwg; - - *PLUGINOFFSET(RslAtomic*, rwa, atmOffset) = atomic; - - rwg->numMaterials = g->matList.numMaterials; - rwg->materialList = new Material*[rwg->numMaterials]; - for(int32 i = 0; i < rwg->numMaterials; i++) - rwg->materialList[i] = convertMaterial(g->matList.materials[i]); - - rwg->meshHeader = new MeshHeader; - rwg->meshHeader->flags = 1; - rwg->meshHeader->numMeshes = rwg->numMaterials; - rwg->meshHeader->mesh = new Mesh[rwg->meshHeader->numMeshes]; - rwg->meshHeader->totalIndices = 0; - Mesh *meshes = rwg->meshHeader->mesh; - for(uint32 i = 0; i < rwg->meshHeader->numMeshes; i++) - meshes[i].numIndices = 0; - - RslPS2ResEntryHeader *resHeader = (RslPS2ResEntryHeader*)(g+1); - RslPS2InstanceData *inst = (RslPS2InstanceData*)(resHeader+1); - int32 numInst = resHeader->size >> 20; - - int32 lastId = -1; - for(int32 i = 0; i < numInst; i++){ - Mesh *m = &meshes[inst[i].matID]; - rwg->numVertices += inst[i].numTriangles+2; - m->numIndices += inst[i].numTriangles+2; - // Extra indices since we're merging tristrip - // meshes with the same material. - // Be careful with face winding. - if(lastId == inst[i].matID) - m->numIndices += inst[i-1].numTriangles % 2 ? 3 : 2; - lastId = inst[i].matID; - } - for(uint32 i = 0; i < rwg->meshHeader->numMeshes; i++){ - rwg->meshHeader->mesh[i].material = rwg->materialList[i]; - rwg->meshHeader->totalIndices += meshes[i].numIndices; - } - rwg->geoflags = Geometry::TRISTRIP | - Geometry::POSITIONS | /* 0x01 ? */ - Geometry::TEXTURED | /* 0x04 ? */ - Geometry::LIGHT; - if(rwg->hasColoredMaterial()) - rwg->geoflags |= Geometry::MODULATE; - if(resHeader->flags & 0x2) - rwg->geoflags |= Geometry::NORMALS; - if(resHeader->flags & 0x8) - rwg->geoflags |= Geometry::PRELIT; - rwg->numTexCoordSets = 1; - - rwg->allocateData(); - rwg->meshHeader->allocateIndices(); - - Skin *skin = NULL; - if(resHeader->flags & 0x10) - assert(g->skin); - if(g->skin){ - skin = new Skin; - *PLUGINOFFSET(Skin*, rwg, skinGlobals.offset) = skin; - skin->init(g->skin->numBones, g->skin->numBones, rwg->numVertices); - memcpy(skin->inverseMatrices, g->skin->invMatrices, skin->numBones*64); - } - - for(uint32 i = 0; i < rwg->meshHeader->numMeshes; i++) - meshes[i].numIndices = 0; - rwg->meshHeader->totalIndices = rwg->numVertices = 0; - for(int32 i = 0; i < numInst; i++) - convertMesh(rwg, g, i); - for(uint32 i = 0; i < rwg->meshHeader->numMeshes; i++) - rwg->meshHeader->totalIndices += meshes[i].numIndices; - if(skin){ - skin->findNumWeights(rwg->numVertices); - skin->findUsedBones(rwg->numVertices); - } - rwg->calculateBoundingSphere(); - rwg->generateTriangles(); - return rwa; -} - -RslAtomic* -collectAtomics(RslAtomic *atomic, void *data) -{ - RslAtomic ***alist = (RslAtomic***)data; - *(*alist)++ = atomic; - return atomic; -} - -Clump* -convertClump(RslClump *c) -{ - Clump *rwc; - Frame *rwf; - Atomic *rwa; - rslFrameList frameList; - - rwc = Clump::create(); - rslFrameListInitialize(&frameList, (RslFrame*)c->object.parent); - Frame **rwframes = new Frame*[frameList.numFrames]; - for(int32 i = 0; i < frameList.numFrames; i++){ - rwf = convertFrame(frameList.frames[i]); - rwframes[i] = rwf; - void *par = frameList.frames[i]->object.parent; - int32 parent = findPointer(par, (void**)frameList.frames, frameList.numFrames); - if(parent >= 0) - rwframes[parent]->addChild(rwf); - } - rwc->object.parent = rwframes[0]; - - int32 numAtomics = RslClumpGetNumAtomics(c); - RslAtomic **alist = new RslAtomic*[numAtomics]; - RslAtomic **ap = &alist[0]; - RslClumpForAllAtomics(c, collectAtomics, &ap); - for(int32 i = 0; i < numAtomics; i++){ - rwa = convertAtomic(alist[i]); - int32 fi = findPointer(alist[i]->object.object.parent, (void**)frameList.frames, frameList.numFrames); - rwa->setFrame(rwframes[fi]); - rwc->addAtomic(rwa); - } - - delete[] alist; - delete[] rwframes; - delete[] frameList.frames; - return rwc; -} - -RslAtomic* -makeTextures(RslAtomic *atomic, void*) -{ - RslGeometry *g = atomic->geometry; - RslMaterial *m; - for(int32 i = 0; i < g->matList.numMaterials; i++){ - m = g->matList.materials[i]; - if(m->texname){ - RslTexture *tex = RslTextureCreate(NULL); - strncpy(tex->name, m->texname, 32); - strncpy(tex->mask, m->texname, 32); - m->texture = tex; - } - if(m->matfx && m->matfx->effectType == MatFX::ENVMAP && - m->matfx->env.texname){ - RslTexture *tex = RslTextureCreate(NULL); - strncpy(tex->name, m->matfx->env.texname, 32); - strncpy(tex->mask, m->matfx->env.texname, 32); - m->matfx->env.texture = tex; - } - } - return atomic; -} - -void -moveAtomics(Frame *f) -{ - static char *names[] = { "", "hi_ok", "hi_dam" }; - if(f == NULL) return; - int n = f->objectList.count(); - if(n > 1){ - char *oldname = gta::getNodeName(f); - ObjectWithFrame **objs = new ObjectWithFrame*[n]; - int i = 0; - FORLIST(lnk, f->objectList){ - ObjectWithFrame *obj = ObjectWithFrame::fromFrame(lnk); - assert(obj->type == Atomic::ID); - objs[i] = obj; - obj->setFrame(NULL); - i++; - } - for(i = 0; i < n; i++){ - Frame *ff = Frame::create(); - RslAtomic *rsla = *PLUGINOFFSET(RslAtomic*, objs[i], atmOffset); - char *name = gta::getNodeName(ff); - strncpy(name, oldname, 24); - char *end = strrchr(name, '_'); - if(end){ - *(++end) = '\0'; - strcat(end, names[rsla->unk3&3]); - } - f->addChild(ff); - objs[i]->setFrame(ff); - } - delete[] objs; - } - moveAtomics(f->next); - moveAtomics(f->child); -} - - - -uint8* -getPalettePS2(RslRaster *raster) -{ - uint32 f = raster->ps2.flags; - uint32 w = 1 << (f & 0x3F); - uint32 h = 1 << (f>>6 & 0x3F); - uint32 d = f>>12 & 0xFF; - uint32 mip = f>>20 & 0xF; - uint8 *data = raster->ps2.data; - if(d > 8) - return NULL; - while(mip--){ - data += w*h*d/8; - w /= 2; - h /= 2; - } - return data; -} - -uint8* -getTexelPS2(RslRaster *raster, int32 n) -{ - uint32 f = raster->ps2.flags; - uint32 w = 1 << (f & 0x3F); - uint32 h = 1 << (f>>6 & 0x3F); - uint32 d = f>>12 & 0xFF; - uint8 *data = raster->ps2.data; - for(int32 i = 0; i < n; i++){ - data += w*h*d/8; - w /= 2; - h /= 2; - } - return data; -} - -void -convertCLUT(uint8 *texels, uint32 w, uint32 h) -{ - static uint8 map[4] = { 0x00, 0x10, 0x08, 0x18 }; - for (uint32 i = 0; i < w*h; i++) - texels[i] = (texels[i] & ~0x18) | map[(texels[i] & 0x18) >> 3]; -} - -void -unswizzle8(uint8 *dst, uint8 *src, uint32 w, uint32 h) -{ - for (uint32 y = 0; y < h; y++) - for (uint32 x = 0; x < w; x++) { - int32 block_loc = (y&(~0xF))*w + (x&(~0xF))*2; - uint32 swap_sel = (((y+2)>>2)&0x1)*4; - int32 ypos = (((y&(~3))>>1) + (y&1))&0x7; - int32 column_loc = ypos*w*2 + ((x+swap_sel)&0x7)*4; - int32 byte_sum = ((y>>1)&1) + ((x>>2)&2); - uint32 swizzled = block_loc + column_loc + byte_sum; - dst[y*w+x] = src[swizzled]; - } -} - -void -unswizzle16(uint16 *dst, uint16 *src, int32 w, int32 h) -{ - for(int y = 0; y < h; y++) - for(int x = 0; x < w; x++){ - int32 pageX = x & (~0x3f); - int32 pageY = y & (~0x3f); - int32 pages_horz = (w+63)/64; - int32 pages_vert = (h+63)/64; - int32 page_number = (pageY/64)*pages_horz + (pageX/64); - int32 page32Y = (page_number/pages_vert)*32; - int32 page32X = (page_number%pages_vert)*64; - int32 page_location = (page32Y*h + page32X)*2; - int32 locX = x & 0x3f; - int32 locY = y & 0x3f; - int32 block_location = (locX&(~0xf))*h + (locY&(~0x7))*2; - int32 column_location = ((y&0x7)*h + (x&0x7))*2; - int32 short_num = (x>>3)&1; // 0,1 - uint32 swizzled = page_location + block_location + - column_location + short_num; - dst[y*w+x] = src[swizzled]; - } -} - -bool32 unswizzle = 1; - -void -convertTo32(uint8 *out, uint8 *pal, uint8 *tex, - uint32 w, uint32 h, uint32 d, bool32 swiz) -{ - uint32 x; - if(d == 32){ - //uint32 *dat = new uint32[w*h]; - //if(swiz && unswizzle) - // unswizzle8_hack(dat, (uint32*)tex, w, h); - //else - // memcpy(dat, tex, w*h*4); - //tex = (uint8*)dat; - for(uint32 i = 0; i < w*h; i++){ - out[i*4+0] = tex[i*4+0]; - out[i*4+1] = tex[i*4+1]; - out[i*4+2] = tex[i*4+2]; - out[i*4+3] = tex[i*4+3]*255/128; - } - //delete[] dat; - } - if(d == 16) return; // TODO - if(d == 8){ - uint8 *dat = new uint8[w*h]; - if(swiz && unswizzle) - unswizzle8(dat, tex, w, h); - else - memcpy(dat, tex, w*h); - tex = dat; - convertCLUT(tex, w, h); - for(uint32 i = 0; i < h; i++) - for(uint32 j = 0; j < w; j++){ - x = *tex++; - *out++ = pal[x*4+0]; - *out++ = pal[x*4+1]; - *out++ = pal[x*4+2]; - *out++ = pal[x*4+3]*255/128; - } - delete[] dat; - } - if(d == 4){ - uint8 *dat = new uint8[w*h]; - for(uint32 i = 0; i < w*h/2; i++){ - dat[i*2+0] = tex[i] & 0xF; - dat[i*2+1] = tex[i] >> 4; - } - if(swiz && unswizzle){ - uint8 *tmp = new uint8[w*h]; - unswizzle8(tmp, dat, w, h); - delete[] dat; - dat = tmp; - } - tex = dat; - for(uint32 i = 0; i < h; i++) - for(uint32 j = 0; j < w; j++){ - x = *tex++; - *out++ = pal[x*4+0]; - *out++ = pal[x*4+1]; - *out++ = pal[x*4+2]; - *out++ = pal[x*4+3]*255/128; - } - delete[] dat; - } -} - -RslTexture *dumpTextureCB(RslTexture *texture, void*) -{ - uint32 f = texture->raster->ps2.flags; - uint32 w = 1 << (f & 0x3F); - uint32 h = 1 << (f>>6 & 0x3F); - uint32 d = f>>12 & 0xFF; - uint32 mip = f>>20 & 0xF; - uint32 swizmask = f>>24; - uint8 *palette = getPalettePS2(texture->raster); - uint8 *texels = getTexelPS2(texture->raster, 0); - printf(" %x %x %x %x %x %s\n", w, h, d, mip, swizmask, texture->name); - Image *img = Image::create(w, h, 32); - img->allocate(); - convertTo32(img->pixels, palette, texels, w, h, d, swizmask&1); - char *name = new char[strlen(texture->name)+5]; - strcpy(name, texture->name); - strcat(name, ".tga"); - writeTGA(img, name); - img->destroy(); - delete[] name; - return texture; -} - -RslTexture* -convertTexturePS2(RslTexture *texture, void *pData) -{ - TexDictionary *rwtxd = (TexDictionary*)pData; - Texture *rwtex = Texture::create(NULL); - RslRasterPS2 *ras = &texture->raster->ps2; - - strncpy(rwtex->name, texture->name, 32); - strncpy(rwtex->mask, texture->mask, 32); - rwtex->filterAddressing = 0x1102; - - uint32 f = ras->flags; - uint32 w = 1 << (f & 0x3F); - uint32 h = 1 << (f>>6 & 0x3F); - uint32 d = f>>12 & 0xFF; - //uint32 mip = f>>20 & 0xF; - uint32 swizmask = f>>24; - uint8 *palette = getPalettePS2(texture->raster); - uint8 *texels = getTexelPS2(texture->raster, 0); - - int32 hasAlpha = 0; - uint8 *convtex = NULL; - if(d == 4){ - convtex = new uint8[w*h]; - for(uint32 i = 0; i < w*h/2; i++){ - int32 a = texels[i] & 0xF; - int32 b = texels[i] >> 4; - if(palette[a*4+3] != 0x80) - hasAlpha = 1; - if(palette[b*4+3] != 0x80) - hasAlpha = 1; - convtex[i*2+0] = a; - convtex[i*2+1] = b; - } - if(swizmask & 1 && unswizzle){ - uint8 *tmp = new uint8[w*h]; - unswizzle8(tmp, convtex, w, h); - delete[] convtex; - convtex = tmp; - } - }else if(d == 8){ - convtex = new uint8[w*h]; - if(swizmask & 1 && unswizzle) - unswizzle8(convtex, texels, w, h); - else - memcpy(convtex, texels, w*h); - convertCLUT(convtex, w, h); - for(uint32 i = 0; i < w*h; i++) - if(palette[convtex[i]*4+3] != 0x80){ - hasAlpha = 1; - break; - } - } - - int32 format = 0; - switch(d){ - case 4: - case 8: - format |= Raster::PAL8; - goto alpha32; - - case 32: - for(uint32 i = 0; i < w*h; i++) - if(texels[i*4+3] != 0x80){ - hasAlpha = 1; - break; - } - alpha32: - if(hasAlpha) - format |= Raster::C8888; - else - format |= Raster::C888; - break; - default: - fprintf(stderr, "unsupported depth %d\n", d); - return NULL; - } - Raster *rwras = Raster::create(w, h, d == 4 ? 8 : d, format | 4, PLATFORM_D3D8); - d3d::D3dRaster *d3dras = PLUGINOFFSET(d3d::D3dRaster, rwras, d3d::nativeRasterOffset); - - int32 pallen = d == 4 ? 16 : - d == 8 ? 256 : 0; - if(pallen){ - uint8 *p = new uint8[256*4]; - for(int32 i = 0; i < pallen; i++){ - p[i*4+0] = palette[i*4+0]; - p[i*4+1] = palette[i*4+1]; - p[i*4+2] = palette[i*4+2]; - p[i*4+3] = palette[i*4+3]*255/128; - } - memcpy(d3dras->palette, p, 256*4); - delete[] p; - } - - uint8 *data = rwras->lock(0); - if(d == 4 || d == 8) - memcpy(data, convtex, w*h); - else if(d == 32){ - // texture is fucked, but pretend it isn't - for(uint32 i = 0; i < w*h; i++){ - data[i*4+2] = texels[i*4+0]; - data[i*4+1] = texels[i*4+1]; - data[i*4+0] = texels[i*4+2]; - data[i*4+3] = texels[i*4+3]*255/128; - } - }else - memcpy(data, texels, w*h*d/8); - rwras->unlock(0); - rwtex->raster = rwras; - delete[] convtex; - - rwtxd->add(rwtex); - return texture; -} - -TexDictionary* -convertTXD(RslTexDictionary *txd) -{ - TexDictionary *rwtxd = TexDictionary::create(); - RslTexDictionaryForAllTextures(txd, convertTexturePS2, rwtxd); - return rwtxd; -} - -void -usage(void) -{ - fprintf(stderr, "%s [-v version] [-x] [-s] input [output.{txd|dff}]\n", argv0); - fprintf(stderr, "\t-v RW version, e.g. 33004 for 3.3.0.4\n"); - fprintf(stderr, "\t-x extract textures to tga\n"); - fprintf(stderr, "\t-s don't unswizzle textures\n"); - fprintf(stderr, "\t-a fix Atomics placement inside hierarchy (mdl files)\n"); - exit(1); -} - -int -main(int argc, char *argv[]) -{ - gta::attachPlugins(); - atmOffset = Atomic::registerPlugin(sizeof(void*), 0x1000000, NULL, NULL, NULL); - rw::version = 0x34003; - rw::platform = PLATFORM_D3D8; - - assert(sizeof(void*) == 4); - int extract = 0; - int fixAtomics = 0; - - ARGBEGIN{ - case 'v': - sscanf(EARGF(usage()), "%x", &rw::version); - break; - case 's': - unswizzle = 0; - break; - case 'x': - extract++; - break; - case 'a': - fixAtomics++; - break; - default: - usage(); - }ARGEND; - - if(argc < 1) - usage(); - - World *world = NULL; - Sector *sector = NULL; - RslClump *clump = NULL; - RslAtomic *atomic = NULL; - RslTexDictionary *txd = NULL; - - - StreamFile stream; - assert(stream.open(argv[0], "rb")); - - uint32 ident = stream.readU32(); - stream.seek(0, 0); - - if(ident == ID_TEXDICTIONARY){ - findChunk(&stream, ID_TEXDICTIONARY, NULL, NULL); - txd = RslTexDictionaryStreamRead(&stream); - stream.close(); - assert(txd); - goto writeTxd; - } - if(ident == ID_CLUMP){ - findChunk(&stream, ID_CLUMP, NULL, NULL); - clump = RslClumpStreamRead(&stream); - stream.close(); - assert(clump); - goto writeDff; - } - - RslStream *rslstr; - rslstr = new RslStream; - stream.read(rslstr, 0x20); - rslstr->data = new uint8[rslstr->fileSize-0x20]; - stream.read(rslstr->data, rslstr->fileSize-0x20); - stream.close(); - rslstr->relocate(); - - bool32 largefile; - largefile = rslstr->dataSize > 0x1000000; - - if(rslstr->ident == WRLD_IDENT && largefile){ // hack - world = (World*)rslstr->data; - - int len = strlen(argv[0])+1; - char filename[1024]; - strncpy(filename, argv[0], len); - filename[len-3] = 'i'; - filename[len-2] = 'm'; - filename[len-1] = 'g'; - filename[len] = '\0'; - assert(stream.open(filename, "rb")); - filename[len-4] = '\\'; - filename[len-3] = '\0'; - - char name[1024]; - uint8 *data; - StreamFile outf; - RslStreamHeader *h; - uint32 i = 0; - for(h = world->sectors->sector; h->ident == WRLD_IDENT; h++){ - sprintf(name, "world%04d.wrld", i++); - strcat(filename, name); - assert(outf.open(filename, "wb")); - data = new uint8[h->fileEnd]; - memcpy(data, h, 0x20); - stream.seek(h->root, 0); - stream.read(data+0x20, h->fileEnd-0x20); - outf.write(data, h->fileEnd); - outf.close(); - filename[len-3] = '\0'; - } - // radar textures - h = world->textures; - for(i = 0; i < world->numTextures; i++){ - sprintf(name, "txd%04d.chk", i); - strcat(filename, name); - assert(outf.open(filename, "wb")); - data = new uint8[h->fileEnd]; - memcpy(data, h, 0x20); - stream.seek(h->root, 0); - stream.read(data+0x20, h->fileEnd-0x20); - outf.write(data, h->fileEnd); - outf.close(); - filename[len-3] = '\0'; - h++; - } - stream.close(); - }else if(rslstr->ident == WRLD_IDENT){ // sector - sector = (Sector*)rslstr->data; - fprintf(stderr, "%d\n",sector->unk1); - //printf("resources\n"); - //for(uint32 i = 0; i < sector->numResources; i++){ - // OverlayResource *r = §or->resources[i]; - // printf(" %d %p\n", r->id, r->raw); - //} - //printf("placement\n"); - if(sector->unk1 == 0) - return 0; - Placement *p; - //for(p = sector->sectionA; p < sector->sectionEnd; p++){ - // printf(" %d, %d, %f %f %f\n", p->id &0x7FFF, p->resId, p->matrix[12], p->matrix[13], p->matrix[14]); - //} - for(p = sector->sectionA; p < sector->sectionEnd; p++) - printf("%f %f %f\n", p->matrix[12], p->matrix[13], p->matrix[14]); - }else if(rslstr->ident == MDL_IDENT){ - uint8 *p; - p = *rslstr->hashTab; - p -= 0x24; - atomic = (RslAtomic*)p; - clump = atomic->clump; - Clump *rwc; - if(clump){ - RslClumpForAllAtomics(clump, makeTextures, NULL); - //RslClumpForAllAtomics(clump, dumpAtomicCB, NULL); - //RslFrameForAllChildren(RslClumpGetFrame(clump), dumpFrameCB, NULL); - }else{ - makeTextures(atomic, NULL); - clump = RslClumpCreate(); - RslAtomicSetFrame(atomic, RslFrameCreate()); - RslClumpSetFrame(clump, RslAtomicGetFrame(atomic)); - RslClumpAddAtomic(clump, atomic); - //dumpAtomicCB(a, NULL); - //RslFrameForAllChildren(RslAtomicGetFrame(atomic), dumpFrameCB, NULL); - } - writeDff: - rwc = convertClump(clump); - if(fixAtomics) - moveAtomics(rwc->getFrame()); - if(argc > 1) - assert(stream.open(argv[1], "wb")); - else - assert(stream.open("out.dff", "wb")); - rwc->streamWrite(&stream); - stream.close(); - }else if(rslstr->ident == TEX_IDENT){ - txd = (RslTexDictionary*)rslstr->data; - writeTxd: - if(extract) - RslTexDictionaryForAllTextures(txd, dumpTextureCB, NULL); - TexDictionary *rwtxd = convertTXD(txd); - if(argc > 1) - assert(stream.open(argv[1], "wb")); - else - assert(stream.open("out.txd", "wb")); - rwtxd->streamWrite(&stream); - stream.close(); - } - - return 0; -} diff --git a/tools/rsltest/rsltest.vcxproj b/tools/rsltest/rsltest.vcxproj deleted file mode 100644 index 0526364..0000000 --- a/tools/rsltest/rsltest.vcxproj +++ /dev/null @@ -1,92 +0,0 @@ - - - - - Debug - null - Win32 - - - Release - Win32 - - - - {27ECE916-900F-49B2-8E9F-95E6B347E161} - rsltest - - - - Application - true - v120 - MultiByte - - - Application - false - v120 - true - MultiByte - - - - - - - - - - - - - $(SolutionDir);$(IncludePath) - $(SolutionDir)$(Configuration);$(LibraryPath) - - - $(SolutionDir)$(Configuration);$(LibraryPath) - $(SolutionDir);$(IncludePath) - - - - Level3 - Disabled - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - MultiThreadedDebug - - - true - librw.lib;%(AdditionalDependencies) - - - copy /y "$(TargetPath)" "C:\Users\aap\bin\" - - - - - Level3 - MaxSpeed - true - true - true - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - MultiThreadedDebug - - - true - true - true - librw.lib;%(AdditionalDependencies) - - - - - - - - - - - - - \ No newline at end of file diff --git a/tools/txdwrite/txdwrite.cpp b/tools/txdwrite/txdwrite.cpp deleted file mode 100644 index 24443af..0000000 --- a/tools/txdwrite/txdwrite.cpp +++ /dev/null @@ -1,164 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include -#include - -char *argv0; - -using namespace std; -using namespace rw; - -struct { - char *str; - uint32 val; -} platforms[] = { - { "ps2", PLATFORM_PS2 }, - { "xbox", PLATFORM_XBOX }, - { "d3d8", PLATFORM_D3D8 }, - { "d3d9", PLATFORM_D3D9 }, - { NULL, 0 } -}; - -Raster* -xboxToD3d8(Raster *raster) -{ - using namespace xbox; - - Raster *newras; - if(raster->platform != PLATFORM_XBOX) - return raster; - XboxRaster *ras = PLUGINOFFSET(XboxRaster, raster, nativeRasterOffset); - - int32 numLevels = raster->getNumLevels(); - - int32 format = raster->format; -// format &= ~Raster::MIPMAP; - if(ras->format){ - newras = Raster::create(raster->width, raster->height, raster->depth, - format | raster->type | 0x80, PLATFORM_D3D8); - int32 dxt = 0; - switch(ras->format){ - case D3DFMT_DXT1: - dxt = 1; - break; - case D3DFMT_DXT3: - dxt = 3; - break; - case D3DFMT_DXT5: - dxt = 5; - break; - } - d3d::allocateDXT(newras, dxt, numLevels, ras->hasAlpha); - }else{ - printf("swizzled!\n"); - newras = Raster::create(raster->width, raster->height, raster->depth, - format | raster->type, PLATFORM_D3D8); - } - - if(raster->format & Raster::PAL4) - d3d::setPalette(newras, ras->palette, 32); - else if(raster->format & Raster::PAL8) - d3d::setPalette(newras, ras->palette, 256); - - uint8 *data; - for(int32 i = 0; i < numLevels; i++){ - if(i >= newras->getNumLevels()) - break; - data = raster->lock(i); - d3d::setTexels(newras, data, i); - raster->unlock(i); - } - - delete raster; - return newras; -} - -void -usage(void) -{ - fprintf(stderr, "usage: %s [-v version] [-o platform] in.txd [out.txd]\n", argv0); - fprintf(stderr, "\t-v RW version, e.g. 33004 for 3.3.0.4\n"); - fprintf(stderr, "\t-o output platform. ps2, xbox, mobile, d3d8, d3d9\n"); - exit(1); -} - -int -main(int argc, char *argv[]) -{ - gta::attachPlugins(); - - rw::version = 0; - rw::platform = rw::PLATFORM_PS2; -// rw::platform = rw::PLATFORM_OGL; -// rw::platform = rw::PLATFORM_XBOX; -// rw::platform = rw::PLATFORM_D3D8; -// rw::platform = rw::PLATFORM_D3D9; - int outplatform = rw::PLATFORM_XBOX; - - char *s; - ARGBEGIN{ - case 'v': - sscanf(EARGF(usage()), "%x", &rw::version); - break; - case 'o': - s = EARGF(usage()); - for(int i = 0; platforms[i].str; i++){ - if(strcmp(platforms[i].str, s) == 0){ - outplatform = platforms[i].val; - goto found; - } - } - printf("unknown platform %s\n", s); - outplatform = PLATFORM_D3D8; - found: - break; - default: - usage(); - }ARGEND; - - if(argc < 1) - usage(); - - rw::StreamFile in; - if(in.open(argv[0], "rb") == NULL){ - printf("couldn't open file %s\n", argv[1]); - return 1; - } - ChunkHeaderInfo header; - readChunkHeaderInfo(&in, &header); - assert(header.type == ID_TEXDICTIONARY); - rw::TexDictionary *txd; - txd = rw::TexDictionary::streamRead(&in); - assert(txd); - in.close(); - rw::currentTexDictionary = txd; - - if(rw::version == 0){ - rw::version = header.version; - rw::build = header.build; - } - - if(outplatform == PLATFORM_D3D8) - FORLIST(lnk, txd->textures){ - Texture *tex = Texture::fromDict(lnk); - tex->raster = xboxToD3d8(tex->raster); - } -// for(Texture *tex = txd->first; tex; tex = tex->next) -// tex->filterAddressing = (tex->filterAddressing&~0xF) | 0x2; - rw::platform = outplatform; - - rw::StreamFile out; - if(argc > 1) - out.open(argv[1], "wb"); - else - out.open("out.txd", "wb"); - txd->streamWrite(&out); - out.close(); - - return 0; -}