📄 3dsfileloader.cc
字号:
//// File: 3dsFileLoader.h// Created by: <Andrea Ingegneri>//#include <iostream>#include <string>#include <fstream>using namespace std;#include "3dsFileFormat.h"#include "3dsFileLoader.h"void C3dsFileLoader::UserObjName(string Name){ cout << "Object Name: " << Name << endl;}void C3dsFileLoader::User3dVert(float x, float y, float z){ cout << "X: " << x << " Y: " << y << " Z:" << z << endl;}void C3dsFileLoader::User3dFace(unsigned short A, unsigned short B, unsigned short C, unsigned short Flags){ cout << "A: " << A << " B: " << B << " C:" << C << endl; cout << " Flags: " << Flags << endl;}void C3dsFileLoader::UserCamera(float px, float py, float pz, float tx, float ty, float tz, float Bank, float Lens){ cout << "Position: X:" << px << "Y: " << py << "Z: " << pz << endl; cout << "Target: X:" << tx << "Y: " << ty << "Z: " << tz << endl; cout << "Bank: " << Bank << endl; cout << "Lens: " << Lens << endl;}void C3dsFileLoader::UserFaceMaterial(string Name, int Number){ cout << "Name: " << Name << endl; cout << "Face Number: " << Number << endl;}void C3dsFileLoader::UserMapVertex(float U, float V){ cout << "U: " << U << " V: " << V << endl;}void C3dsFileLoader::UserTransformMatrix(const Transform3dsMatrix &Transform, const Translate3dsMatrix &Translate){ cout << "Transformation Matrix:" << endl; cout << Transform._11 << " " << Transform._12 << " " << Transform._13 << " " << endl; cout << Transform._21 << " " << Transform._22 << " " << Transform._23 << " " << endl; cout << Transform._31 << " " << Transform._32 << " " << Transform._33 << " " << endl; cout << "Translation Matrix:" << endl; cout << Translate._11 << " " << Translate._12 << " " << Translate._13 << " " << endl;}void C3dsFileLoader::UserLight(float x, float y, float z){ cout << "X: " << x << " Y: " << y << " Z: " << z << endl;}void C3dsFileLoader::UserSpotLight(float x, float y, float z, float HotSpot, float FallOff){ cout << "X: " << x << " Y: " << y << " Z: <" << z << endl; cout << "HotSpot: " << HotSpot << endl; cout << "FallOff: " << FallOff << endl;}void C3dsFileLoader::UserMatName(const string Name){ cout << "Material Name: " << Name << endl;}void C3dsFileLoader::UserMapFile(const string FileName){ cout << "Texture FileName: " << FileName << endl;}void C3dsFileLoader::UserFrames(long Start, long End){ cout << "Start: " << Start << " End: " << End << endl;}void C3dsFileLoader::UserTrackObjectName(string Name, int Key1, int Key2, int Key3){ cout << "Track Object Name: " << Name << endl; cout << "First Key: " << Key1 << endl; cout << "Second Key: " << Key2 << endl; cout << "Third Key: " << Key3 << endl;}void C3dsFileLoader::UserTrackPos(int Frame, long Flags, float x, float y, float z){ cout << "Frame Number: " << Frame << endl; cout << "Flags: " << Flags << endl; cout << "Position - X: " << x << " Y: " << y << " Z: " << z << endl;}void C3dsFileLoader::UserTrackRot(int Frame, long Flags, float DegX, float DegY, float DegZ){ cout << "Frame Number: " << Frame << endl; cout << "Flags: " << Flags << endl; cout << "Rotation - X: " << DegX << " Y: " << DegY << " Z: " << DegZ << endl;}void C3dsFileLoader::UserTrackScale(int Frame, long Flags, float ScaleX, float ScaleY, float ScaleZ){ cout << "Frame Number: " << Frame << endl; cout << "Flags: " << Flags << endl; cout << "Scaling - X: " << ScaleX << " Y: " << ScaleY << " Z: " << ScaleZ << endl;}void C3dsFileLoader::UserObjNumber(int ObjNumber){ cout << "Object Number: " << ObjNumber << endl;}void C3dsFileLoader::UserChunkObj(){}void C3dsFileLoader::UserEndOfFile(){ cout << "EndOfFile" << endl;}void C3dsFileLoader::UserOneUnit(float Unit){ cout << "One Unit is: " << Unit << endl;}void C3dsFileLoader::UserViewPortLayout(ViewPortLayout &Layout){ cout << "Style: " << Layout.style << endl; cout << "Active: " << Layout.active << endl; cout << "Unknow1: " << Layout.unknow1 << endl; cout << "Swap: " << Layout.swap<< endl; cout << "Unknow2: " << Layout.unknow2 << endl; cout << "Swap Prior: " << Layout.swap_prior << endl; cout << "Swap View: " << Layout.swap_view << endl;}void C3dsFileLoader::UserViewPortSize(int PosX, int PosY, int Width, int Height){ cout << "Position X: " << PosX << endl; cout << "Position Y: " << PosY << endl; cout << "Width: " << PosY << endl; cout << "Height: " << PosY << endl;}void C3dsFileLoader::UserViewPortData(ViewPortData &Data){ cout << "Flags: " << Data.flags << endl; cout << "Axis Lockout: " << Data.axis_lockout << endl; cout << "Window Position - X: " << Data.win_x << " Y: " << Data.win_y << endl; cout << "Window Size - Width: " << Data.win_w << " Height: " << Data.win_h << endl; cout << "Window View: " << Data.win_view << endl; cout << "Zoom factor: " << Data.zoom << endl; cout << "World Origin - X: " << Data.worldcenter_x << " Y: " << Data.worldcenter_y << " Z: " << Data.worldcenter_z << endl; cout << "Horizontal Angle: " << Data.horiz_ang << endl; cout << "Vertical Angle: " << Data.vert_ang << endl; cout << "Camera Name: " << Data.camera_name << endl; }void C3dsFileLoader::UserViewUser(float x, float y, float z, float Width, float XYangle, float YZangle, float BackAngle){ cout << "Point - X: " << x << " Y: " << y << " Z: " << z << endl; cout << "Width: " << Width << endl; cout << "Horizontal view Angle from OXY Plane: " << XYangle << endl; cout << "Vertical view Angle from OYZ Plane: " << YZangle << endl; cout << "BankAngle of View Rotation: " << BackAngle << endl;}void C3dsFileLoader::UserViewCamera(string CameraName){ cout << "Default Camera Name: " << CameraName << endl;}void C3dsFileLoader::movePC(long forward){ PC += forward; mInputFile.seekg(PC);}void C3dsFileLoader::ReadRGBF(){ float c[3]; if (!ReadBlock((char *) c, sizeof(c))) return;}void C3dsFileLoader::ReadRGBB(){ unsigned char c[3]; if(!ReadBlock((char *) c, sizeof(c))) return;}void C3dsFileLoader::ReadObjBlock(){ char ObjName[255]; ReadASCIIZ(ObjName); UserObjName(string(ObjName));}void C3dsFileLoader::ReadCamera(){ float c[8]; if (!ReadBlock( (char *) c, sizeof(c))) return; UserCamera(c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);}void C3dsFileLoader::ReadFaceMat(){ short n, nf; char MaterialName[255]; ReadASCIIZ(MaterialName); if (!ReadBlock((char *) &n, sizeof(n))) return; while (n-- > 0) { // Material number assigned to any face // Numero di material assegnato ad ogni faccia if (!ReadBlock((char*) &nf, sizeof(nf))) return; UserFaceMaterial(string(MaterialName), (int) nf); }}void C3dsFileLoader::ReadFrames(){ long c[2]; if (!ReadBlock((char*) c, sizeof(c))) return; UserFrames(c[0], c[1]);}void C3dsFileLoader::ReadLight(){ float c[3]; if (!ReadBlock( (char*) c, sizeof(c))) return; UserLight(c[0], c[1], c[2]);}void C3dsFileLoader::ReadMapFile(){ char fileName[255]; ReadASCIIZ(fileName); UserMapFile(string(fileName));}void C3dsFileLoader::ReadMapList(){ short nv; float c[2]; if (!ReadBlock((char *) &nv, sizeof(nv))) return; while (nv-- > 0) { if (!ReadBlock((char *) c, sizeof(c))) return; UserMapVertex(c[0], c[1]); }}void C3dsFileLoader::ReadMatName(){ char matName[255]; ReadASCIIZ(matName); UserMatName(string(matName));}void C3dsFileLoader::ReadObjNumber(){ signed short n; if (!ReadBlock((char *) &n, sizeof(n))) return; UserObjNumber((int) n);}void C3dsFileLoader::ReadSpotLight(){ float c[5]; if (!ReadBlock( (char*) c, sizeof(c))) return; UserSpotLight(c[0], c[1], c[2], c[3], c[4]);}void C3dsFileLoader::ReadTrackObjName(){ unsigned short w[3]; char trackName[255]; // Read ASCIIZ name ReadASCIIZ(trackName); if (!ReadBlock((char*) w, sizeof(w))) return; UserTrackObjectName(string(trackName), w[0], w[1], w[2]);}void C3dsFileLoader::ReadTrackPos(){ short n, nf; float pos[3]; long flags; mInputFile.seekg(10, ios::cur); PC += 10; if(!ReadBlock( (char*) &n, sizeof(n))) return; mInputFile.seekg(2, ios::cur); PC += 2; while (n-- > 0) { int i; float dat; if (!ReadBlock( (char *) &nf, sizeof(nf))) return; if (!ReadBlock((char *) &flags, sizeof(flags))) return; for (i = 0; i < 32; i++) if (flags & (1 << i)) if (!ReadBlock( (char *) &dat, sizeof(dat))) return; if (!ReadBlock( (char *) pos, sizeof(pos))) return; UserTrackPos(nf, flags, pos[0], pos[1], pos[2]); }}void C3dsFileLoader::ReadTrackRot(){ unsigned short n, nf; float pos[4]; long flags; mInputFile.seekg(10, ios::cur); PC += 10; if(!ReadBlock((char *) &n, sizeof(n))) return; mInputFile.seekg(2, ios::cur); PC += 2; while (n-- > 0) { int i; float dat; if (!ReadBlock( (char*) &nf, sizeof(nf))) return; if (!ReadBlock( (char*) &flags, sizeof(flags))) return; for (i = 0; i < 32; i++) if (flags & (1 << i)) if (!ReadBlock((char*) &dat, sizeof(dat))) return; if (!ReadBlock((char *) pos, sizeof(pos))) return; UserTrackRot(nf, flags, pos[0], pos[1], pos[2]); }}void C3dsFileLoader::ReadTrackScale(){ unsigned short n, nf; float pos[3]; long flags; mInputFile.seekg(10, ios::cur); PC += 10; if(!ReadBlock((char *) &n, sizeof(n))) return; mInputFile.seekg(2, ios::cur); PC += 2; while (n-- > 0) { int i; float dat; if (!ReadBlock((char*) &nf, sizeof(nf))) return; if (!ReadBlock((char*) &flags, sizeof(flags))) return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -