mirror of
https://github.com/AntonioND/nitro-engine.git
synced 2025-06-19 00:55:38 -04:00
Fix style of md2_2_bin
Run `dos2unix` and `indent -linux` on the files and some other minor fixes.
This commit is contained in:
parent
bd0ce8d9a0
commit
8fe1bfce3c
2
Tools/Windows/md2_to_bin/.gitignore
vendored
Normal file
2
Tools/Windows/md2_to_bin/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.o
|
||||
md2_2_bin
|
@ -2,12 +2,14 @@
|
||||
//
|
||||
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
||||
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "dlmaker.h"
|
||||
#include "nds.h"
|
||||
|
||||
unsigned int DLSize[1024];
|
||||
unsigned int * DLPointer[1024];
|
||||
unsigned int *DLPointer[1024];
|
||||
int DLcount = 0;
|
||||
|
||||
unsigned char command[4];
|
||||
@ -18,78 +20,82 @@ int params;
|
||||
|
||||
void NewDL(void)
|
||||
{
|
||||
command[0] = command[1] = command[2] = command[3] = 0;
|
||||
param[0] = param[1] = param[2] = param[3] = 0;
|
||||
param[4] = param[5] = param[6] = param[7] = 0;
|
||||
commands = 0; params = 0;
|
||||
command[0] = command[1] = command[2] = command[3] = 0;
|
||||
param[0] = param[1] = param[2] = param[3] = 0;
|
||||
param[4] = param[5] = param[6] = param[7] = 0;
|
||||
commands = 0;
|
||||
params = 0;
|
||||
|
||||
DLPointer[DLcount] = (unsigned int*)malloc(DEFAULT_DL_SIZE);
|
||||
DLSize[DLcount] = 1;
|
||||
DLPointer[DLcount] = (unsigned int *)malloc(DEFAULT_DL_SIZE);
|
||||
DLSize[DLcount] = 1;
|
||||
}
|
||||
|
||||
void NewCommandDL(int id)
|
||||
{
|
||||
command[commands] = id;
|
||||
commands++;
|
||||
command[commands] = id;
|
||||
commands++;
|
||||
|
||||
if(commands == 4) //Save data to display list
|
||||
{
|
||||
if (commands == 4) {
|
||||
// Save data to display list
|
||||
commands = 0;
|
||||
unsigned int temp;
|
||||
temp = COMMAND_PACK(command[0],command[1],command[2],command[3]);
|
||||
temp =
|
||||
COMMAND_PACK(command[0], command[1], command[2],
|
||||
command[3]);
|
||||
command[0] = command[1] = command[2] = command[3] = 0;
|
||||
unsigned int * pointer = &((DLPointer[DLcount])[DLSize[DLcount]]);
|
||||
*pointer = temp; //Save commands
|
||||
DLSize[DLcount] ++;
|
||||
if(param > 0)
|
||||
{
|
||||
unsigned int *pointer =
|
||||
&((DLPointer[DLcount])[DLSize[DLcount]]);
|
||||
// Save commands
|
||||
*pointer = temp;
|
||||
DLSize[DLcount]++;
|
||||
if (param > 0) {
|
||||
pointer = &((DLPointer[DLcount])[DLSize[DLcount]]);
|
||||
int a;
|
||||
for(a = 0; a < params; a ++)
|
||||
{
|
||||
pointer[a] = param[a]; //Save commands
|
||||
DLSize[DLcount] ++;
|
||||
for (a = 0; a < params; a++) {
|
||||
// Save commands
|
||||
pointer[a] = param[a];
|
||||
DLSize[DLcount]++;
|
||||
}
|
||||
}
|
||||
param[0] = param[1] = param[2] = param[3] = 0;
|
||||
param[4] = param[5] = param[6] = param[7] = 0;
|
||||
params = 0;
|
||||
|
||||
if(DLSize[DLcount] >= DEFAULT_DL_SIZE)
|
||||
{
|
||||
if (DLSize[DLcount] >= DEFAULT_DL_SIZE) {
|
||||
printf("\n\nDisplay list buffer overflow.\n\n");
|
||||
while(1); //TODO: Exit in a better way.
|
||||
// TODO: Exit in a better way.
|
||||
while (1) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NewParamDL(unsigned int param_)
|
||||
{
|
||||
param[params] = param_;
|
||||
params++;
|
||||
param[params] = param_;
|
||||
params++;
|
||||
}
|
||||
|
||||
void FinishDL(void)
|
||||
{
|
||||
if(commands > 0) //Add NOP commands to fill packed commands
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
if (commands > 0) {
|
||||
// Add NOP commands to fill packed commands
|
||||
while (1) {
|
||||
NewCommandDL(ID_NOP);
|
||||
if(commands == 0) break;
|
||||
if (commands == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
*DLPointer[DLcount] = DLSize[DLcount] - 1; //DL real size in 4 bytes packs
|
||||
DLcount++;
|
||||
// DL real size in 4 bytes packs
|
||||
*DLPointer[DLcount] = DLSize[DLcount] - 1;
|
||||
DLcount++;
|
||||
}
|
||||
|
||||
int GetDLSize(int num)
|
||||
{
|
||||
return DLSize[num];
|
||||
return DLSize[num];
|
||||
}
|
||||
|
||||
unsigned int * GetDLPointer(int num)
|
||||
unsigned int *GetDLPointer(int num)
|
||||
{
|
||||
return DLPointer[num];
|
||||
return DLPointer[num];
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,10 @@
|
||||
//
|
||||
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
||||
|
||||
#ifndef _DLMAKER_H_
|
||||
#define _DLMAKER_H_
|
||||
#ifndef DLMAKER_H__
|
||||
#define DLMAKER_H__
|
||||
|
||||
#define DEFAULT_DL_SIZE (512*1024)
|
||||
#define DEFAULT_DL_SIZE (512 * 1024)
|
||||
|
||||
void NewDL(void);
|
||||
void NewCommandDL(int id);
|
||||
@ -13,6 +13,6 @@ void NewParamDL(unsigned int param_);
|
||||
void FinishDL(void);
|
||||
|
||||
int GetDLSize(int num);
|
||||
unsigned int * GetDLPointer(int num);
|
||||
unsigned int *GetDLPointer(int num);
|
||||
|
||||
#endif
|
||||
#endif // DLMAKER_H__
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include "nds.h"
|
||||
#include "dlmaker.h"
|
||||
@ -21,90 +20,128 @@
|
||||
|
||||
typedef float vec3_t[3];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int ident; int version;
|
||||
typedef struct {
|
||||
int ident;
|
||||
int version;
|
||||
|
||||
int skinwidth; int skinheight;
|
||||
int skinwidth;
|
||||
int skinheight;
|
||||
int framesize;
|
||||
int num_skins; int num_vertices; int num_st; int num_tris; int num_glcmds; int num_frames;
|
||||
int offset_skins; int offset_st; int offset_tris; int offset_frames; int offset_glcmds;
|
||||
int num_skins;
|
||||
int num_vertices;
|
||||
int num_st;
|
||||
int num_tris;
|
||||
int num_glcmds;
|
||||
int num_frames;
|
||||
int offset_skins;
|
||||
int offset_st;
|
||||
int offset_tris;
|
||||
int offset_frames;
|
||||
int offset_glcmds;
|
||||
int offset_end;
|
||||
} md2_header_t;
|
||||
|
||||
typedef struct { short s; short t; } md2_texCoord_t;
|
||||
|
||||
typedef struct { unsigned short vertex[3]; unsigned short st[3]; } md2_triangle_t;
|
||||
|
||||
typedef struct { unsigned char v[3]; unsigned char normalIndex; } md2_vertex_t;
|
||||
typedef struct {
|
||||
short s;
|
||||
short t;
|
||||
} md2_texCoord_t;
|
||||
|
||||
typedef struct {
|
||||
vec3_t scale; vec3_t translate;
|
||||
unsigned short vertex[3];
|
||||
unsigned short st[3];
|
||||
} md2_triangle_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned char v[3];
|
||||
unsigned char normalIndex;
|
||||
} md2_vertex_t;
|
||||
|
||||
typedef struct {
|
||||
vec3_t scale;
|
||||
vec3_t translate;
|
||||
char name[16];
|
||||
md2_vertex_t *verts;
|
||||
} md2_frame_t;
|
||||
|
||||
typedef struct { float s; float t; int index; } md2_glcmd_t;
|
||||
typedef struct {
|
||||
float s;
|
||||
float t;
|
||||
int index;
|
||||
} md2_glcmd_t;
|
||||
|
||||
float anorms[162][3] = {
|
||||
#include "anorms.h"
|
||||
};
|
||||
|
||||
|
||||
void PrintUse(void)
|
||||
{
|
||||
printf("\n\nInstructions:\n\n");
|
||||
printf(" MD2_2_BIN [input.md2] [output.bin] ([float scale])\n");
|
||||
printf(" ([float translate x] [float translate x] [float translate x])\n\n");
|
||||
printf("\n\n");
|
||||
printf("Instructions:\n");
|
||||
printf(" md2_2_bin [input.md2] [output.bin] <[float scale]>\n");
|
||||
printf(" <[float translate x] [float translate x] [float translate x]>\n\n");
|
||||
}
|
||||
|
||||
int floattovtx10(float n)
|
||||
{
|
||||
int value = ((v10)((n) * (1 << 6))) & 0x3FF;
|
||||
if(n < 0) value |= (1 << 10);
|
||||
else value &= 0x1FF;
|
||||
return value;
|
||||
int value = ((v10) ((n) * (1 << 6))) & 0x3FF;
|
||||
if (n < 0)
|
||||
value |= (1 << 10);
|
||||
else
|
||||
value &= 0x1FF;
|
||||
return value;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int IsValidSize(int size)
|
||||
{
|
||||
printf("\n\n ########################################\n");
|
||||
printf(" #/ \\#\n");
|
||||
printf(" # -- -- MD2 2 BIN -- -- #\n");
|
||||
printf(" #\\ v2.0 /#\n");
|
||||
return (size == 8 || size == 16 || size == 32 || size == 64 ||
|
||||
size == 128 || size == 256 || size == 512 || size == 1024);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
printf("\n\n");
|
||||
printf(" ########################################\n");
|
||||
printf(" # #\n");
|
||||
printf(" # -- -- MD2 2 BIN -- -- #\n");
|
||||
printf(" # v2.0 #\n");
|
||||
printf(" ########################################\n");
|
||||
printf("\n");
|
||||
printf("Copyright (c) 2008-2011, 2019 Antonio Nino Diaz\n");
|
||||
printf("All rights reserved.\n\n");
|
||||
|
||||
printf("\nCopyright (C) 2008 Antonio Ni%co D%caz\nAll rights reserved.\n\n", 164, 161);
|
||||
// Default values
|
||||
float global_scale = 1;
|
||||
float global_translation[3] = { 0, 0, 0 };
|
||||
|
||||
printf(" -- -- -- -- -- -- -- -- -- --\n");
|
||||
|
||||
float general_scale = 1; //DEFAULT VALUES
|
||||
float general_trans[3] = {0, 0, 0};
|
||||
|
||||
switch(argc)
|
||||
{
|
||||
switch (argc) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2: //Not enough
|
||||
case 2:
|
||||
// Not enough arguments
|
||||
PrintUse();
|
||||
return -1;
|
||||
case 3: //Use default modifications
|
||||
case 3:
|
||||
// Use default modifications
|
||||
break;
|
||||
case 4: //Use default translation and custom scale
|
||||
general_scale = atof(argv[3]);
|
||||
case 4:
|
||||
// Use default translation and custom scale
|
||||
global_scale = atof(argv[3]);
|
||||
break;
|
||||
case 5:
|
||||
case 6: //Custom translation, not enough
|
||||
case 6:
|
||||
// Custom translation, not enough
|
||||
printf("You must set 3 coordinates for translation, not less.");
|
||||
PrintUse();
|
||||
return -1;
|
||||
case 7: //Custom translation + scale
|
||||
general_scale = atof(argv[3]);
|
||||
general_trans[0] = atof(argv[4]);
|
||||
general_trans[1] = atof(argv[5]);
|
||||
general_trans[2] = atof(argv[6]);
|
||||
case 7:
|
||||
// Custom translation + scale
|
||||
global_scale = atof(argv[3]);
|
||||
global_translation[0] = atof(argv[4]);
|
||||
global_translation[1] = atof(argv[5]);
|
||||
global_translation[2] = atof(argv[6]);
|
||||
break;
|
||||
default: //The rest...
|
||||
default:
|
||||
// Too many arguments
|
||||
PrintUse();
|
||||
return -1;
|
||||
}
|
||||
@ -112,191 +149,217 @@ int main(int argc, char* argv[])
|
||||
char inputfilepath[MAX_PATHLEN];
|
||||
char outputfilepath[MAX_PATHLEN];
|
||||
|
||||
strcpy(inputfilepath,argv[1]);
|
||||
strcpy(outputfilepath,argv[2]);
|
||||
strcpy(inputfilepath, argv[1]);
|
||||
strcpy(outputfilepath, argv[2]);
|
||||
|
||||
if(general_scale == 0)
|
||||
{
|
||||
if (global_scale == 0) {
|
||||
printf("\nScale can't be 0!!");
|
||||
PrintUse();
|
||||
return -1;
|
||||
}
|
||||
|
||||
char * md2data;
|
||||
char *md2data;
|
||||
|
||||
printf("\nScale: %f\n",general_scale);
|
||||
printf("Translate: %f, %f, %f\n",general_trans[0],general_trans[1],general_trans[2]);
|
||||
printf("\n");
|
||||
printf("Scale: %f\n", global_scale);
|
||||
printf("Translate: %f, %f, %f\n", global_translation[0],
|
||||
global_translation[1], global_translation[2]);
|
||||
|
||||
printf("\nLoading MD2 model...\n");
|
||||
printf("\n");
|
||||
printf("Loading MD2 model...\n");
|
||||
|
||||
FILE * datafile = fopen (inputfilepath, "r");
|
||||
if(datafile != NULL)
|
||||
{
|
||||
fseek (datafile , 0 , SEEK_END);
|
||||
long int tamano = ftell (datafile);
|
||||
rewind (datafile);
|
||||
md2data = (char*) malloc (sizeof(char)*tamano);
|
||||
fread (md2data,1,tamano,datafile);
|
||||
fclose (datafile);
|
||||
FILE *datafile = fopen(inputfilepath, "r");
|
||||
if (datafile != NULL) {
|
||||
fseek(datafile, 0, SEEK_END);
|
||||
long int size_ = ftell(datafile);
|
||||
rewind(datafile);
|
||||
md2data = (char *)malloc(sizeof(char) * size_);
|
||||
fread(md2data, 1, size_, datafile);
|
||||
fclose(datafile);
|
||||
} else {
|
||||
fclose(datafile);
|
||||
printf("\n\nCouldn't open %s!!\n\n", inputfilepath);
|
||||
PrintUse();
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{ fclose (datafile); printf("\n\nCouldn't open %s!!\n\n", inputfilepath);
|
||||
PrintUse(); return -1; }
|
||||
|
||||
md2_header_t * header = (md2_header_t*)md2data;
|
||||
|
||||
if ((header->ident != 844121161) || (header->version != 8))
|
||||
{ printf("\n\nWrong file type or version!!\n\n"); return -1; }
|
||||
md2_header_t *header = (md2_header_t *) md2data;
|
||||
|
||||
if ((header->ident != 844121161) || (header->version != 8)) {
|
||||
printf("\n\nWrong file type or version!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int t_w = header->skinwidth, t_h = header->skinheight;
|
||||
|
||||
if(t_w > 1024 || t_h > 1024) { printf("\n\nTexture too big!!\n\n"); return -1; }
|
||||
|
||||
if(!(t_w==8||t_w==16||t_w==32||t_w==64||t_w==128||t_w==256||t_w==512||t_w==1024) ||
|
||||
!(t_h==8||t_h==16||t_h==32||t_h==64||t_h==128||t_h==256||t_h==512||t_h==1024))
|
||||
{
|
||||
printf("\nWrong texture size. Must be power of 2.\n");
|
||||
printf("\nAlthough the model uses an invalid texture size, it will be converted.\n");
|
||||
printf("\nResize the texture to nearest valid size.\n\n");
|
||||
//return -1;
|
||||
if (t_w > 1024 || t_h > 1024) {
|
||||
printf("\n\nTexture too big!!\n\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
while(1)
|
||||
{ if(t_w==8||t_w==16||t_w==32||t_w==64||t_w==128||t_w==256||t_w==512||t_w==1024) break;
|
||||
t_w ++; }
|
||||
while(1)
|
||||
{ if(t_h==8||t_h==16||t_h==32||t_h==64||t_h==128||t_h==256||t_h==512||t_h==1024) break;
|
||||
t_h ++; }
|
||||
if (!IsValidSize(t_w) || !IsValidSize(t_h)) {
|
||||
printf("\nWrong texture size. It must be a power of 2.\n");
|
||||
printf("\nAlthough the model uses an invalid texture size, it will be converted.\n");
|
||||
printf("\nResize the texture to nearest valid size.\n\n");
|
||||
}
|
||||
|
||||
while (!IsValidSize(t_w)) {
|
||||
t_w++;
|
||||
}
|
||||
while (!IsValidSize(t_h)) {
|
||||
t_h++;
|
||||
}
|
||||
|
||||
int num_tris = header->num_tris;
|
||||
|
||||
md2_frame_t * frame = NULL;
|
||||
md2_texCoord_t * texcoord = (md2_texCoord_t*)((uintptr_t)header->offset_st + (uintptr_t)header);
|
||||
md2_triangle_t * triangle = (md2_triangle_t*)((uintptr_t)header->offset_tris + (uintptr_t)header);
|
||||
md2_frame_t *frame = NULL;
|
||||
md2_texCoord_t *texcoord =
|
||||
(md2_texCoord_t *) ((uintptr_t) header->offset_st +
|
||||
(uintptr_t) header);
|
||||
md2_triangle_t *triangle =
|
||||
(md2_triangle_t *) ((uintptr_t) header->offset_tris +
|
||||
(uintptr_t) header);
|
||||
|
||||
md2_vertex_t * vtx; //Current vertex
|
||||
// Current vertex
|
||||
md2_vertex_t *vtx;
|
||||
|
||||
printf("\nMD2 texture size: %dx%d", t_w,t_h);
|
||||
printf("\nMD2 texture size: %dx%d", t_w, t_h);
|
||||
|
||||
printf("\nCreating display list...\n");
|
||||
|
||||
float bigvalue = 0;
|
||||
|
||||
//Everything ready, let's "draw" the display list
|
||||
frame = (md2_frame_t*)((uintptr_t)header->offset_frames + (uintptr_t)header);
|
||||
// Everything ready, let's "draw" the display list
|
||||
frame =
|
||||
(md2_frame_t *) ((uintptr_t) header->offset_frames +
|
||||
(uintptr_t) header);
|
||||
|
||||
NewDL();
|
||||
NewParamDL(0); // 0 = GL_TRIANGLES
|
||||
|
||||
// Send GL_TRIANGLES command
|
||||
NewParamDL(0);
|
||||
NewCommandDL(ID_BEGIN);
|
||||
|
||||
int olds_ = -1, oldt_ = -1; //Used to avoid useless command repeating
|
||||
// Keep track of the last command to avoid useless repetition
|
||||
int olds_ = -1, oldt_ = -1;
|
||||
int oldnormindex = -1;
|
||||
|
||||
int vtxcount = 0;
|
||||
|
||||
int t = 0, v = 0;
|
||||
for(t = 0; t < num_tris; t ++) for(v = 0; v < 3; v++)
|
||||
{
|
||||
vtx = (md2_vertex_t*) ( (uintptr_t) (&(frame->verts)) );
|
||||
for (t = 0; t < num_tris; t++)
|
||||
for (v = 0; v < 3; v++) {
|
||||
vtx = (md2_vertex_t *) ((uintptr_t) (&(frame->verts)));
|
||||
vtx = &vtx[triangle[t].vertex[v]];
|
||||
|
||||
//Texture
|
||||
// Texture coordinates
|
||||
short s_ = texcoord[triangle[t].st[v]].s;
|
||||
short t_ = texcoord[triangle[t].st[v]].t;
|
||||
if(olds_ != s_ || oldt_ != t_)
|
||||
{
|
||||
if (olds_ != s_ || oldt_ != t_) {
|
||||
olds_ = s_;
|
||||
oldt_ = t_;
|
||||
|
||||
//This is used to change UVs if using a texture size unsupported by DS
|
||||
s_ = (int)((float)(s_ * t_w) / (float)header->skinwidth);
|
||||
t_ = (int)((float)(t_ * t_h) / (float)header->skinheight);
|
||||
NewParamDL(TEXTURE_PACK(s_<<4,t_<<4)); // (t_h-t_)<<4));
|
||||
// This is used to scale UVs if using a texture
|
||||
// size unsupported by DS
|
||||
s_ = (int)((float)(s_ * t_w) /
|
||||
(float)header->skinwidth);
|
||||
t_ = (int)((float)(t_ * t_h) /
|
||||
(float)header->skinheight);
|
||||
NewParamDL(TEXTURE_PACK(s_ << 4, t_ << 4)); // (t_h-t_)<<4));
|
||||
NewCommandDL(ID_TEX_COORD);
|
||||
}
|
||||
|
||||
//Normal
|
||||
// Normal
|
||||
float norm[3];
|
||||
if(oldnormindex != vtx->normalIndex)
|
||||
{
|
||||
if (oldnormindex != vtx->normalIndex) {
|
||||
oldnormindex = vtx->normalIndex;
|
||||
int b;
|
||||
for(b = 0; b < 3; b++) norm[b] = anorms[vtx->normalIndex][b];
|
||||
NewParamDL(NORMAL_PACK(floattov10(norm[0]), floattov10(norm[1]), floattov10(norm[2])));
|
||||
for (b = 0; b < 3; b++)
|
||||
norm[b] = anorms[vtx->normalIndex][b];
|
||||
NewParamDL(NORMAL_PACK
|
||||
(floattov10(norm[0]),
|
||||
floattov10(norm[1]),
|
||||
floattov10(norm[2])));
|
||||
NewCommandDL(ID_NORMAL);
|
||||
}
|
||||
//Vertex
|
||||
// Vertex
|
||||
float _v[3];
|
||||
int a = 0;
|
||||
int vtx10 = false;
|
||||
for(a = 0; a < 3; a++)
|
||||
{
|
||||
vtxcount ++;
|
||||
_v[a] = ((float)frame->scale[a] * (float)(vtx->v[a])) + (float)frame->translate[a];
|
||||
_v[a] += general_trans[a];
|
||||
_v[a] *= general_scale;
|
||||
//7.9997 for VTX_16, 7.98 for VTX_10
|
||||
if((absf(_v[a]) > (float)7.9997) && ( absf(bigvalue) < absf(_v[a])))
|
||||
for (a = 0; a < 3; a++) {
|
||||
vtxcount++;
|
||||
_v[a] =
|
||||
((float)frame->scale[a] *
|
||||
(float)(vtx->v[a])) +
|
||||
(float)frame->translate[a];
|
||||
_v[a] += global_translation[a];
|
||||
_v[a] *= global_scale;
|
||||
// 7.9997 for VTX_16, 7.98 for VTX_10
|
||||
if ((absf(_v[a]) > (float)7.9997)
|
||||
&& (absf(bigvalue) < absf(_v[a])))
|
||||
bigvalue = _v[a];
|
||||
//Test if OK to use VTX_10
|
||||
if(absf(_v[a]) < (float)7.98)
|
||||
{
|
||||
// Test to see if it is more accurate to use
|
||||
// VTX_10 or VTX_16
|
||||
if (absf(_v[a]) < (float)7.98) {
|
||||
float aux = (float)1 / (float)64;
|
||||
float tempvtx = _v[a] / aux;
|
||||
tempvtx = absf(tempvtx - (float)(int)tempvtx);
|
||||
aux = (float)0.2; //You can try changing it, but 0.2 is OK
|
||||
if(tempvtx < aux || tempvtx > ((float)1 - aux)) vtx10 = true;
|
||||
tempvtx =
|
||||
absf(tempvtx - (float)(int)tempvtx);
|
||||
// Arbitrary threshold
|
||||
aux = (float)0.2;
|
||||
if (tempvtx < aux
|
||||
|| tempvtx > ((float)1 - aux))
|
||||
vtx10 = true;
|
||||
}
|
||||
}
|
||||
if(vtx10)
|
||||
{
|
||||
NewParamDL(VERTEX_10_PACK(floattovtx10(_v[0]),floattovtx10(_v[2]),
|
||||
if (vtx10) {
|
||||
NewParamDL(VERTEX_10_PACK
|
||||
(floattovtx10(_v[0]),
|
||||
floattovtx10(_v[2]),
|
||||
floattovtx10(_v[1])));
|
||||
NewCommandDL(ID_VERTEX10);
|
||||
}
|
||||
else
|
||||
{
|
||||
NewParamDL((floattov16(_v[2]) << 16) | (floattov16(_v[0]) & 0xFFFF));
|
||||
} else {
|
||||
NewParamDL((floattov16(_v[2]) << 16) |
|
||||
(floattov16(_v[0]) & 0xFFFF));
|
||||
NewParamDL((floattov16(_v[1]) & 0xFFFF));
|
||||
NewCommandDL(ID_VERTEX16);
|
||||
}
|
||||
}
|
||||
FinishDL();
|
||||
|
||||
if(absf(bigvalue) > 0)
|
||||
{
|
||||
if (absf(bigvalue) > 0) {
|
||||
printf("\nModel too big for DS! Scale it down.\n");
|
||||
printf("\nDS max. allowed value: +/-7,9997\nModel max. detected value: %f\n\n",bigvalue);
|
||||
printf
|
||||
("\nDS max. allowed value: +/-7,9997\nModel max. detected value: %f\n\n",
|
||||
bigvalue);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(vtxcount > 6144)
|
||||
{
|
||||
if (vtxcount > 6144) {
|
||||
printf("\nModel has too many vertices!\n");
|
||||
printf("\nDS can only render 6144 vertices per frame.\nYour model has %d vertices.\n",vtxcount);
|
||||
//return -1;
|
||||
printf
|
||||
("\nDS can only render 6144 vertices per frame.\nYour model has %d vertices.\n",
|
||||
vtxcount);
|
||||
}
|
||||
|
||||
printf("\nCreating BIN file...\n");
|
||||
|
||||
//Now, let's save them into a BIN file.
|
||||
FILE * file = fopen(outputfilepath,"wb+");
|
||||
if(file == NULL)
|
||||
{
|
||||
printf("\nCouldn't create %s file!",outputfilepath);
|
||||
// Now, let's save them into a BIN file.
|
||||
FILE *file = fopen(outputfilepath, "wb+");
|
||||
if (file == NULL) {
|
||||
printf("\nCouldn't create %s file!", outputfilepath);
|
||||
return -1;
|
||||
}
|
||||
fwrite((int*)GetDLPointer(0),GetDLSize(0) * sizeof(unsigned int),1,file);
|
||||
fwrite((int *)GetDLPointer(0), GetDLSize(0) * sizeof(unsigned int), 1,
|
||||
file);
|
||||
fclose(file);
|
||||
|
||||
FILE * test = fopen(outputfilepath,"rb");
|
||||
fseek (test , 0 , SEEK_END);
|
||||
long int size = ftell (test);
|
||||
FILE *test = fopen(outputfilepath, "rb");
|
||||
fseek(test, 0, SEEK_END);
|
||||
long int size = ftell(test);
|
||||
fclose(test);
|
||||
printf("\nBIN file size: %zd bytes", size);
|
||||
printf("\nBIN file size: %zd bytes\n", size);
|
||||
|
||||
printf("\n\nReady!\n\n");
|
||||
printf("\nReady!\n\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
//
|
||||
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
||||
|
||||
#ifndef _NDS_H_
|
||||
#define _NDS_H_
|
||||
#ifndef NDS_H__
|
||||
#define NDS_H__
|
||||
|
||||
//From libnds/gbatek
|
||||
|
||||
@ -15,9 +15,11 @@ typedef short int vtx10;
|
||||
|
||||
static inline short int floattov10(float n)
|
||||
{
|
||||
if(n > 0.998) return 0x1FF;
|
||||
if(n < -0.998) return 0x3FF;
|
||||
return (short int)(n*(1<<9));
|
||||
if (n > 0.998)
|
||||
return 0x1FF;
|
||||
if (n < -0.998)
|
||||
return 0x3FF;
|
||||
return (short int)(n * (1 << 9));
|
||||
}
|
||||
|
||||
#define floattof32(n) ((int)((n) * (1 << 12)))
|
||||
@ -26,7 +28,7 @@ static inline short int floattov10(float n)
|
||||
#define NORMAL_PACK(x,y,z) (((x) & 0x3FF) | (((y) & 0x3FF) << 10) | ((z) << 20))
|
||||
#define TEXTURE_PACK(u,v) (((u) & 0xFFFF) | ((v) << 16))
|
||||
|
||||
#define COMMAND_PACK(c1,c2,c3,c4) (((c4) << 24) | ((c3) << 16) | ((c2) << 8) | (c1))
|
||||
#define COMMAND_PACK(c1, c2, c3, c4) (((c4) << 24) | ((c3) << 16) | ((c2) << 8) | (c1))
|
||||
|
||||
#define ID_NOP 0x00
|
||||
#define ID_VERTEX16 0x23
|
||||
@ -35,4 +37,4 @@ static inline short int floattov10(float n)
|
||||
#define ID_NORMAL 0x21
|
||||
#define ID_BEGIN 0x40
|
||||
|
||||
#endif
|
||||
#endif // NDS_H__
|
||||
|
Loading…
Reference in New Issue
Block a user