Updated the lib3ds plugin with the new 1.1 version of lib3ds.
This commit is contained in:
@@ -28,7 +28,7 @@ LIB = ../../../lib/osgPlugins/osgdb_3ds.so
|
||||
TARGET_LOADER_FILES = osgPlugins/osgdb_3ds.so
|
||||
|
||||
LIBS =
|
||||
C++FLAGS += -I. -I../../../include
|
||||
C++FLAGS += -I. -I../../../include
|
||||
LDFLAGS += -L../../../lib
|
||||
|
||||
include ../../../Make/makerules
|
||||
|
||||
@@ -62,7 +62,7 @@ ReaderWriter3DS::ReaderWriter3DS()
|
||||
osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
{
|
||||
|
||||
Lib3dsFile *f = lib3ds_open(fileName.c_str());
|
||||
Lib3dsFile *f = lib3ds_file_load(fileName.c_str());
|
||||
if (f==NULL) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
_directory = osgDB::getFilePath(fileName);
|
||||
@@ -151,7 +151,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& fil
|
||||
|
||||
}
|
||||
|
||||
lib3ds_close(f);
|
||||
lib3ds_file_free(f);
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
@@ -24,128 +24,120 @@
|
||||
#include <chunk.h>
|
||||
#include <readwrite.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \defgroup atmosphere Atmosphere Settings
|
||||
*
|
||||
* \author J.E. Hoffmann <je-h@gmx.net>
|
||||
*/
|
||||
|
||||
|
||||
static Lib3dsBool
|
||||
fog_read(Lib3dsFog *fog, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_FOG, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
fog->near_plane=lib3ds_float_read(f);
|
||||
fog->near_density=lib3ds_float_read(f);
|
||||
fog->far_plane=lib3ds_float_read(f);
|
||||
fog->far_density=lib3ds_float_read(f);
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0)
|
||||
{
|
||||
switch (chunk)
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_FOG, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
fog->near_plane=lib3ds_float_read(f);
|
||||
fog->near_density=lib3ds_float_read(f);
|
||||
fog->far_plane=lib3ds_float_read(f);
|
||||
fog->far_density=lib3ds_float_read(f);
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
|
||||
switch (chunk) {
|
||||
case LIB3DS_LIN_COLOR_F:
|
||||
{
|
||||
case LIB3DS_LIN_COLOR_F:
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
fog->col[i]=lib3ds_float_read(f);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIB3DS_COLOR_F:
|
||||
break;
|
||||
case LIB3DS_FOG_BGND:
|
||||
{
|
||||
fog->fog_background=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
fog->col[i]=lib3ds_float_read(f);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIB3DS_COLOR_F:
|
||||
break;
|
||||
case LIB3DS_FOG_BGND:
|
||||
{
|
||||
fog->fog_background=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
static Lib3dsBool
|
||||
layer_fog_read(Lib3dsLayerFog *fog, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
//Lib3dsBool have_lin=LIB3DS_FALSE;
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
Lib3dsBool have_lin=LIB3DS_FALSE;
|
||||
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_LAYER_FOG, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_LAYER_FOG, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
fog->near_y=lib3ds_float_read(f);
|
||||
fog->far_y=lib3ds_float_read(f);
|
||||
fog->density=lib3ds_float_read(f);
|
||||
fog->flags=lib3ds_dword_read(f);
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
|
||||
switch (chunk) {
|
||||
case LIB3DS_LIN_COLOR_F:
|
||||
lib3ds_rgb_read(fog->col,f);
|
||||
have_lin=LIB3DS_TRUE;
|
||||
break;
|
||||
case LIB3DS_COLOR_F:
|
||||
lib3ds_rgb_read(fog->col,f);
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
fog->near_y=lib3ds_float_read(f);
|
||||
fog->far_y=lib3ds_float_read(f);
|
||||
fog->density=lib3ds_float_read(f);
|
||||
fog->flags=lib3ds_dword_read(f);
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0)
|
||||
{
|
||||
switch (chunk)
|
||||
{
|
||||
case LIB3DS_LIN_COLOR_F:
|
||||
lib3ds_rgb_read(fog->col,f);
|
||||
//have_lin=LIB3DS_TRUE;
|
||||
break;
|
||||
case LIB3DS_COLOR_F:
|
||||
lib3ds_rgb_read(fog->col,f);
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
static Lib3dsBool
|
||||
distance_cue_read(Lib3dsDistanceCue *cue, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_DISTANCE_CUE, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
cue->near_plane=lib3ds_float_read(f);
|
||||
cue->near_dimming=lib3ds_float_read(f);
|
||||
cue->far_plane=lib3ds_float_read(f);
|
||||
cue->far_dimming=lib3ds_float_read(f);
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0)
|
||||
{
|
||||
switch (chunk)
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_DISTANCE_CUE, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
cue->near_plane=lib3ds_float_read(f);
|
||||
cue->near_dimming=lib3ds_float_read(f);
|
||||
cue->far_plane=lib3ds_float_read(f);
|
||||
cue->far_dimming=lib3ds_float_read(f);
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
|
||||
switch (chunk) {
|
||||
case LIB3DS_DCUE_BGND:
|
||||
{
|
||||
case LIB3DS_DCUE_BGND:
|
||||
{
|
||||
cue->cue_background=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
cue->cue_background=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -155,60 +147,55 @@ distance_cue_read(Lib3dsDistanceCue *cue, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_atmosphere_read(Lib3dsAtmosphere *atmosphere, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
Lib3dsChunk c;
|
||||
|
||||
if (!lib3ds_chunk_read(&c, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (!lib3ds_chunk_read(&c, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
|
||||
switch (c.chunk) {
|
||||
case LIB3DS_FOG:
|
||||
{
|
||||
lib3ds_chunk_read_reset(&c, f);
|
||||
if (!fog_read(&atmosphere->fog, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIB3DS_LAYER_FOG:
|
||||
{
|
||||
lib3ds_chunk_read_reset(&c, f);
|
||||
if (!layer_fog_read(&atmosphere->layer_fog, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DISTANCE_CUE:
|
||||
{
|
||||
lib3ds_chunk_read_reset(&c, f);
|
||||
if (!distance_cue_read(&atmosphere->dist_cue, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIB3DS_USE_FOG:
|
||||
{
|
||||
atmosphere->fog.use=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_USE_LAYER_FOG:
|
||||
{
|
||||
atmosphere->fog.use=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_USE_DISTANCE_CUE:
|
||||
{
|
||||
atmosphere->dist_cue.use=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c.chunk)
|
||||
{
|
||||
case LIB3DS_FOG:
|
||||
{
|
||||
lib3ds_chunk_read_reset(&c, f);
|
||||
if (!fog_read(&atmosphere->fog, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIB3DS_LAYER_FOG:
|
||||
{
|
||||
lib3ds_chunk_read_reset(&c, f);
|
||||
if (!layer_fog_read(&atmosphere->layer_fog, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DISTANCE_CUE:
|
||||
{
|
||||
lib3ds_chunk_read_reset(&c, f);
|
||||
if (!distance_cue_read(&atmosphere->dist_cue, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIB3DS_USE_FOG:
|
||||
{
|
||||
atmosphere->fog.use=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_USE_LAYER_FOG:
|
||||
{
|
||||
atmosphere->fog.use=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_USE_DISTANCE_CUE:
|
||||
{
|
||||
atmosphere->dist_cue.use=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return(LIB3DS_TRUE);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -218,100 +205,95 @@ lib3ds_atmosphere_read(Lib3dsAtmosphere *atmosphere, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, FILE *f)
|
||||
{
|
||||
{ /*---- LIB3DS_FOG ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_FOG;
|
||||
if (!lib3ds_chunk_write_start(&c,f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
lib3ds_float_write(atmosphere->fog.near_plane,f);
|
||||
lib3ds_float_write(atmosphere->fog.near_density,f);
|
||||
lib3ds_float_write(atmosphere->fog.far_plane,f);
|
||||
lib3ds_float_write(atmosphere->fog.far_density,f);
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_FOG_BGND;
|
||||
c.size=18;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_rgb_write(atmosphere->fog.col,f);
|
||||
}
|
||||
if (atmosphere->fog.fog_background)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_COLOR_F;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
}
|
||||
if (!lib3ds_chunk_write_end(&c,f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (atmosphere->fog.use) { /*---- LIB3DS_FOG ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_FOG;
|
||||
if (!lib3ds_chunk_write_start(&c,f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
{ /*---- LIB3DS_LAYER_FOG ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_LAYER_FOG;
|
||||
c.size=40;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_float_write(atmosphere->layer_fog.near_y,f);
|
||||
lib3ds_float_write(atmosphere->layer_fog.far_y,f);
|
||||
lib3ds_float_write(atmosphere->layer_fog.near_y,f);
|
||||
lib3ds_dword_write(atmosphere->layer_fog.flags,f);
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_COLOR_F;
|
||||
c.size=18;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_rgb_write(atmosphere->fog.col,f);
|
||||
}
|
||||
}
|
||||
{ /*---- LIB3DS_DISTANCE_CUE ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DISTANCE_CUE;
|
||||
if (!lib3ds_chunk_write_start(&c,f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
lib3ds_float_write(atmosphere->dist_cue.near_plane,f);
|
||||
lib3ds_float_write(atmosphere->dist_cue.near_dimming,f);
|
||||
lib3ds_float_write(atmosphere->dist_cue.far_plane,f);
|
||||
lib3ds_float_write(atmosphere->dist_cue.far_dimming,f);
|
||||
if (atmosphere->dist_cue.cue_background)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DCUE_BGND;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
}
|
||||
if (!lib3ds_chunk_write_end(&c,f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
if (atmosphere->fog.use) /*---- LIB3DS_USE_FOG ----*/
|
||||
lib3ds_float_write(atmosphere->fog.near_plane,f);
|
||||
lib3ds_float_write(atmosphere->fog.near_density,f);
|
||||
lib3ds_float_write(atmosphere->fog.far_plane,f);
|
||||
lib3ds_float_write(atmosphere->fog.far_density,f);
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_USE_FOG;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_COLOR_F;
|
||||
c.size=18;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_rgb_write(atmosphere->fog.col,f);
|
||||
}
|
||||
/*---- LIB3DS_USE_LAYER_FOG ----*/
|
||||
if (atmosphere->layer_fog.use)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_USE_LAYER_FOG;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
if (atmosphere->fog.fog_background) {
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_FOG_BGND;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
}
|
||||
if (atmosphere->dist_cue.use)/*---- LIB3DS_USE_DISTANCE_CUE ----*/
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_USE_V_GRADIENT;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
if (!lib3ds_chunk_write_end(&c,f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
return(LIB3DS_TRUE);
|
||||
if (atmosphere->layer_fog.use) { /*---- LIB3DS_LAYER_FOG ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_LAYER_FOG;
|
||||
c.size=40;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_float_write(atmosphere->layer_fog.near_y,f);
|
||||
lib3ds_float_write(atmosphere->layer_fog.far_y,f);
|
||||
lib3ds_float_write(atmosphere->layer_fog.near_y,f);
|
||||
lib3ds_dword_write(atmosphere->layer_fog.flags,f);
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_COLOR_F;
|
||||
c.size=18;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_rgb_write(atmosphere->fog.col,f);
|
||||
}
|
||||
}
|
||||
|
||||
if (atmosphere->dist_cue.use) { /*---- LIB3DS_DISTANCE_CUE ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DISTANCE_CUE;
|
||||
if (!lib3ds_chunk_write_start(&c,f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
lib3ds_float_write(atmosphere->dist_cue.near_plane,f);
|
||||
lib3ds_float_write(atmosphere->dist_cue.near_dimming,f);
|
||||
lib3ds_float_write(atmosphere->dist_cue.far_plane,f);
|
||||
lib3ds_float_write(atmosphere->dist_cue.far_dimming,f);
|
||||
if (atmosphere->dist_cue.cue_background) {
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DCUE_BGND;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
}
|
||||
if (!lib3ds_chunk_write_end(&c,f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
if (atmosphere->fog.use) { /*---- LIB3DS_USE_FOG ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_USE_FOG;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
}
|
||||
|
||||
if (atmosphere->layer_fog.use) { /*---- LIB3DS_USE_LAYER_FOG ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_USE_LAYER_FOG;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
}
|
||||
|
||||
if (atmosphere->dist_cue.use) { /*---- LIB3DS_USE_DISTANCE_CUE ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_USE_V_GRADIENT;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
}
|
||||
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -322,3 +304,4 @@ lib3ds_atmosphere_write(Lib3dsAtmosphere *atmosphere, FILE *f)
|
||||
\sa _Lib3dsAtmosphere
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
@@ -24,6 +24,8 @@
|
||||
#include <chunk.h>
|
||||
#include <readwrite.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \defgroup background Background Settings
|
||||
@@ -31,84 +33,79 @@
|
||||
* \author J.E. Hoffmann <je-h@gmx.net>
|
||||
*/
|
||||
|
||||
|
||||
static Lib3dsBool
|
||||
solid_bgnd_read(Lib3dsBackground *background, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
//Lib3dsBool have_lin=LIB3DS_FALSE;
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
Lib3dsBool have_lin=LIB3DS_FALSE;
|
||||
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_SOLID_BGND, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_SOLID_BGND, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
|
||||
switch (chunk) {
|
||||
case LIB3DS_LIN_COLOR_F:
|
||||
lib3ds_rgb_read(background->solid.col, f);
|
||||
have_lin=LIB3DS_TRUE;
|
||||
break;
|
||||
case LIB3DS_COLOR_F:
|
||||
lib3ds_rgb_read(background->solid.col, f);
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0)
|
||||
{
|
||||
switch (chunk)
|
||||
{
|
||||
case LIB3DS_LIN_COLOR_F:
|
||||
lib3ds_rgb_read(background->solid.col, f);
|
||||
//have_lin=LIB3DS_TRUE;
|
||||
break;
|
||||
case LIB3DS_COLOR_F:
|
||||
lib3ds_rgb_read(background->solid.col, f);
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
static Lib3dsBool
|
||||
v_gradient_read(Lib3dsBackground *background, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
int index[2];
|
||||
Lib3dsRgb col[2][3];
|
||||
int have_lin=0;
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
int index[2];
|
||||
Lib3dsRgb col[2][3];
|
||||
int have_lin=0;
|
||||
|
||||
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_V_GRADIENT, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
background->gradient.percent=lib3ds_float_read(f);
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_V_GRADIENT, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
background->gradient.percent=lib3ds_float_read(f);
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
|
||||
index[0]=index[1]=0;
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0)
|
||||
{
|
||||
switch (chunk)
|
||||
{
|
||||
case LIB3DS_COLOR_F:
|
||||
lib3ds_rgb_read(col[0][index[0]],f);
|
||||
index[0]++;
|
||||
break;
|
||||
case LIB3DS_LIN_COLOR_F:
|
||||
lib3ds_rgb_read(col[1][index[1]],f);
|
||||
index[1]++;
|
||||
have_lin=1;
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
index[0]=index[1]=0;
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
|
||||
switch (chunk) {
|
||||
case LIB3DS_COLOR_F:
|
||||
lib3ds_rgb_read(col[0][index[0]],f);
|
||||
index[0]++;
|
||||
break;
|
||||
case LIB3DS_LIN_COLOR_F:
|
||||
lib3ds_rgb_read(col[1][index[1]],f);
|
||||
index[1]++;
|
||||
have_lin=1;
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
background->gradient.top[i]=col[have_lin][0][i];
|
||||
background->gradient.middle[i]=col[have_lin][1][i];
|
||||
background->gradient.bottom[i]=col[have_lin][2][i];
|
||||
}
|
||||
}
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
background->gradient.top[i]=col[have_lin][0][i];
|
||||
background->gradient.middle[i]=col[have_lin][1][i];
|
||||
background->gradient.bottom[i]=col[have_lin][2][i];
|
||||
}
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -118,77 +115,85 @@ v_gradient_read(Lib3dsBackground *background, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_background_read(Lib3dsBackground *background, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
Lib3dsChunk c;
|
||||
|
||||
if (!lib3ds_chunk_read(&c, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
|
||||
switch (c.chunk)
|
||||
{
|
||||
case LIB3DS_BIT_MAP:
|
||||
if (!lib3ds_chunk_read(&c, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
|
||||
switch (c.chunk) {
|
||||
case LIB3DS_BIT_MAP:
|
||||
{
|
||||
if (!lib3ds_string_read(background->bitmap.name, 64, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIB3DS_SOLID_BGND:
|
||||
{
|
||||
if (!lib3ds_string_read(background->bitmap.name, 64, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
lib3ds_chunk_read_reset(&c, f);
|
||||
if (!solid_bgnd_read(background, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIB3DS_SOLID_BGND:
|
||||
case LIB3DS_V_GRADIENT:
|
||||
{
|
||||
lib3ds_chunk_read_reset(&c, f);
|
||||
if (!solid_bgnd_read(background, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
lib3ds_chunk_read_reset(&c, f);
|
||||
if (!v_gradient_read(background, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIB3DS_V_GRADIENT:
|
||||
case LIB3DS_USE_BIT_MAP:
|
||||
{
|
||||
lib3ds_chunk_read_reset(&c, f);
|
||||
if (!v_gradient_read(background, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
background->bitmap.use=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_USE_BIT_MAP:
|
||||
case LIB3DS_USE_SOLID_BGND:
|
||||
{
|
||||
background->bitmap.use=LIB3DS_TRUE;
|
||||
background->solid.use=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_USE_SOLID_BGND:
|
||||
case LIB3DS_USE_V_GRADIENT:
|
||||
{
|
||||
background->solid.use=LIB3DS_TRUE;
|
||||
background->gradient.use=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_USE_V_GRADIENT:
|
||||
{
|
||||
background->gradient.use=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
static Lib3dsBool
|
||||
colorf_write(Lib3dsRgba rgb, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
Lib3dsChunk c;
|
||||
|
||||
c.chunk=LIB3DS_COLOR_F;
|
||||
c.size=18;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_rgb_write(rgb,f);
|
||||
c.chunk=LIB3DS_COLOR_F;
|
||||
c.size=18;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_rgb_write(rgb,f);
|
||||
|
||||
c.chunk=LIB3DS_LIN_COLOR_F;
|
||||
c.size=18;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_rgb_write(rgb,f);
|
||||
return(LIB3DS_TRUE);
|
||||
c.chunk=LIB3DS_LIN_COLOR_F;
|
||||
c.size=18;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_rgb_write(rgb,f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
static Lib3dsBool
|
||||
colorf_defined(Lib3dsRgba rgb)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
if (fabs(rgb[i])>LIB3DS_EPSILON) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return(i<3);
|
||||
}
|
||||
|
||||
|
||||
@@ -198,53 +203,57 @@ colorf_write(Lib3dsRgba rgb, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_background_write(Lib3dsBackground *background, FILE *f)
|
||||
{
|
||||
{ /*---- LIB3DS_BIT_MAP ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_BIT_MAP;
|
||||
c.size=6+1+strlen(background->bitmap.name);
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_string_write(background->bitmap.name, f);
|
||||
}
|
||||
{ /*---- LIB3DS_SOLID_BGND ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_SOLID_BGND;
|
||||
c.size=42;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
colorf_write(background->solid.col,f);
|
||||
}
|
||||
{ /*---- LIB3DS_V_GRADIENT ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_V_GRADIENT;
|
||||
c.size=118;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_float_write(background->gradient.percent,f);
|
||||
colorf_write(background->gradient.top,f);
|
||||
colorf_write(background->gradient.middle,f);
|
||||
colorf_write(background->gradient.bottom,f);
|
||||
}
|
||||
if (background->bitmap.use) /*---- LIB3DS_USE_BIT_MAP ----*/
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_USE_BIT_MAP;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
}
|
||||
if (background->solid.use) /*---- LIB3DS_USE_SOLID_BGND ----*/
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_USE_SOLID_BGND;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
}
|
||||
if (background->gradient.use)/*---- LIB3DS_USE_V_GRADIENT ----*/
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_USE_V_GRADIENT;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
}
|
||||
if (strlen(background->bitmap.name)) { /*---- LIB3DS_BIT_MAP ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_BIT_MAP;
|
||||
c.size=6+1+strlen(background->bitmap.name);
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_string_write(background->bitmap.name, f);
|
||||
}
|
||||
|
||||
return(LIB3DS_TRUE);
|
||||
if (colorf_defined(background->solid.col)) { /*---- LIB3DS_SOLID_BGND ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_SOLID_BGND;
|
||||
c.size=42;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
colorf_write(background->solid.col,f);
|
||||
}
|
||||
|
||||
if (colorf_defined(background->gradient.top) ||
|
||||
colorf_defined(background->gradient.middle) ||
|
||||
colorf_defined(background->gradient.bottom)) { /*---- LIB3DS_V_GRADIENT ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_V_GRADIENT;
|
||||
c.size=118;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_float_write(background->gradient.percent,f);
|
||||
colorf_write(background->gradient.top,f);
|
||||
colorf_write(background->gradient.middle,f);
|
||||
colorf_write(background->gradient.bottom,f);
|
||||
}
|
||||
|
||||
if (background->bitmap.use) { /*---- LIB3DS_USE_BIT_MAP ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_USE_BIT_MAP;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
}
|
||||
|
||||
if (background->solid.use) { /*---- LIB3DS_USE_SOLID_BGND ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_USE_SOLID_BGND;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
}
|
||||
|
||||
if (background->gradient.use) { /*---- LIB3DS_USE_V_GRADIENT ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_USE_V_GRADIENT;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
}
|
||||
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
@@ -26,36 +26,48 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
//#include <config.h>
|
||||
#include <config.h>
|
||||
#ifdef WITH_DMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
* \defgroup camera Cameras
|
||||
*
|
||||
* \author J.E. Hoffmann <je-h@gmx.net>
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup camera
|
||||
*/
|
||||
Lib3dsCamera*
|
||||
lib3ds_camera_new(const char *name)
|
||||
{
|
||||
Lib3dsCamera *camera;
|
||||
Lib3dsCamera *camera;
|
||||
|
||||
ASSERT(name);
|
||||
ASSERT(strlen(name)<64);
|
||||
ASSERT(name);
|
||||
ASSERT(strlen(name)<64);
|
||||
|
||||
camera=(Lib3dsCamera*)calloc(sizeof(Lib3dsCamera), 1);
|
||||
if (!camera) {
|
||||
return(0);
|
||||
}
|
||||
strcpy(camera->name, name);
|
||||
camera->fov=45.0f;
|
||||
return(camera);
|
||||
}
|
||||
|
||||
camera=(Lib3dsCamera*)calloc(sizeof(Lib3dsCamera), 1);
|
||||
if (!camera)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
strcpy(camera->name, name);
|
||||
camera->fov=45.0f;
|
||||
return(camera);
|
||||
|
||||
/*!
|
||||
* \ingroup camera
|
||||
*/
|
||||
void
|
||||
lib3ds_camera_free(Lib3dsCamera *camera)
|
||||
{
|
||||
memset(camera, 0, sizeof(Lib3dsCamera));
|
||||
free(camera);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,10 +75,20 @@ lib3ds_camera_new(const char *name)
|
||||
* \ingroup camera
|
||||
*/
|
||||
void
|
||||
lib3ds_camera_free(Lib3dsCamera *camera)
|
||||
lib3ds_camera_dump(Lib3dsCamera *camera)
|
||||
{
|
||||
memset(camera, 0, sizeof(Lib3dsCamera));
|
||||
free(camera);
|
||||
ASSERT(camera);
|
||||
printf(" name: %s\n", camera->name);
|
||||
printf(" position: (%f, %f, %f)\n",
|
||||
camera->position[0], camera->position[1], camera->position[2]);
|
||||
printf(" target (%f, %f, %f)\n",
|
||||
camera->target[0], camera->target[1], camera->target[2]);
|
||||
printf(" roll: %f\n", camera->roll);
|
||||
printf(" fov: %f\n", camera->fov);
|
||||
printf(" see_cone: %s\n", camera->see_cone ? "yes" : "no");
|
||||
printf(" near_range: %f\n", camera->near_range);
|
||||
printf(" far_range: %f\n", camera->near_range);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -76,61 +98,54 @@ lib3ds_camera_free(Lib3dsCamera *camera)
|
||||
Lib3dsBool
|
||||
lib3ds_camera_read(Lib3dsCamera *camera, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_N_CAMERA, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_N_CAMERA, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
camera->position[i]=lib3ds_float_read(f);
|
||||
}
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
camera->position[i]=lib3ds_float_read(f);
|
||||
}
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
camera->target[i]=lib3ds_float_read(f);
|
||||
}
|
||||
for (i=0; i<3; ++i) {
|
||||
camera->target[i]=lib3ds_float_read(f);
|
||||
}
|
||||
camera->roll=lib3ds_float_read(f);
|
||||
{
|
||||
float s;
|
||||
s=lib3ds_float_read(f);
|
||||
if (fabs(s)<LIB3DS_EPSILON)
|
||||
{
|
||||
camera->fov=45.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
camera->fov=2400.0f/s;
|
||||
}
|
||||
}
|
||||
camera->roll=lib3ds_float_read(f);
|
||||
{
|
||||
float s;
|
||||
s=lib3ds_float_read(f);
|
||||
if (fabs(s)<LIB3DS_EPSILON) {
|
||||
camera->fov=45.0;
|
||||
}
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0)
|
||||
{
|
||||
switch (chunk)
|
||||
{
|
||||
case LIB3DS_CAM_SEE_CONE:
|
||||
{
|
||||
camera->see_cone=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_CAM_RANGES:
|
||||
{
|
||||
camera->near_range=lib3ds_float_read(f);
|
||||
camera->far_range=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
else {
|
||||
camera->fov=2400.0f/s;
|
||||
}
|
||||
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
|
||||
switch (chunk) {
|
||||
case LIB3DS_CAM_SEE_CONE:
|
||||
{
|
||||
camera->see_cone=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_CAM_RANGES:
|
||||
{
|
||||
camera->near_range=lib3ds_float_read(f);
|
||||
camera->far_range=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -140,47 +155,42 @@ lib3ds_camera_read(Lib3dsCamera *camera, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_camera_write(Lib3dsCamera *camera, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
|
||||
c.chunk=LIB3DS_N_CAMERA;
|
||||
if (!lib3ds_chunk_write_start(&c,f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
|
||||
lib3ds_vector_write(camera->position, f);
|
||||
lib3ds_vector_write(camera->target, f);
|
||||
lib3ds_float_write(camera->roll, f);
|
||||
if (fabs(camera->fov)<LIB3DS_EPSILON) {
|
||||
lib3ds_float_write(2400.0f/45.0f, f);
|
||||
}
|
||||
else {
|
||||
lib3ds_float_write(2400.0f/camera->fov, f);
|
||||
}
|
||||
|
||||
if (camera->see_cone) {
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_CAM_SEE_CONE;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
}
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_CAM_RANGES;
|
||||
c.size=14;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(camera->near_range, f);
|
||||
lib3ds_float_write(camera->far_range, f);
|
||||
}
|
||||
|
||||
c.chunk=LIB3DS_N_CAMERA;
|
||||
if (!lib3ds_chunk_write_start(&c,f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
|
||||
lib3ds_vector_write(camera->position, f);
|
||||
lib3ds_vector_write(camera->target, f);
|
||||
lib3ds_float_write(camera->roll, f);
|
||||
if (fabs(camera->fov)<LIB3DS_EPSILON)
|
||||
{
|
||||
lib3ds_float_write(2400.0f/45.0f, f);
|
||||
}
|
||||
else
|
||||
{
|
||||
lib3ds_float_write(2400.0f/camera->fov, f);
|
||||
}
|
||||
|
||||
if (camera->see_cone)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_CAM_SEE_CONE;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
}
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_CAM_RANGES;
|
||||
c.size=14;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(camera->near_range, f);
|
||||
lib3ds_float_write(camera->far_range, f);
|
||||
}
|
||||
|
||||
if (!lib3ds_chunk_write_end(&c,f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
if (!lib3ds_chunk_write_end(&c,f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ struct _Lib3dsCamera {
|
||||
|
||||
extern LIB3DSAPI Lib3dsCamera* lib3ds_camera_new(const char *name);
|
||||
extern LIB3DSAPI void lib3ds_camera_free(Lib3dsCamera *mesh);
|
||||
extern LIB3DSAPI void lib3ds_camera_dump(Lib3dsCamera *camera);
|
||||
extern LIB3DSAPI Lib3dsBool lib3ds_camera_read(Lib3dsCamera *camera, FILE *f);
|
||||
extern LIB3DSAPI Lib3dsBool lib3ds_camera_write(Lib3dsCamera *camera, FILE *f);
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
@@ -24,48 +24,50 @@
|
||||
#include <readwrite.h>
|
||||
#include <chunktable.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
/*#define LIB3DS_CHUNK_DEBUG*/
|
||||
/*#define LIB3DS_CHUNK_WARNING*/
|
||||
|
||||
|
||||
/*!
|
||||
* \defgroup chunk Chunk Handling
|
||||
*
|
||||
* \author J.E. Hoffmann <je-h@gmx.net>
|
||||
*/
|
||||
|
||||
|
||||
static Lib3dsBool enable_dump=LIB3DS_FALSE;
|
||||
static Lib3dsBool enable_unknown=LIB3DS_FALSE;
|
||||
static char lib3ds_chunk_level[128]="";
|
||||
|
||||
|
||||
static void
|
||||
/*c*/
|
||||
lib3ds_chunk_debug_enter(Lib3dsChunk* )
|
||||
lib3ds_chunk_debug_enter(Lib3dsChunk *c)
|
||||
{
|
||||
strcat(lib3ds_chunk_level, " ");
|
||||
strcat(lib3ds_chunk_level, " ");
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
/*c*/
|
||||
lib3ds_chunk_debug_leave(Lib3dsChunk* )
|
||||
lib3ds_chunk_debug_leave(Lib3dsChunk *c)
|
||||
{
|
||||
lib3ds_chunk_level[strlen(lib3ds_chunk_level)-2]=0;
|
||||
lib3ds_chunk_level[strlen(lib3ds_chunk_level)-2]=0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
lib3ds_chunk_debug_dump(Lib3dsChunk *c)
|
||||
{
|
||||
if (enable_dump)
|
||||
{
|
||||
printf("%s%s (0x%X) size=%lu\n",
|
||||
lib3ds_chunk_level,
|
||||
lib3ds_chunk_name(c->chunk),
|
||||
c->chunk,
|
||||
c->size
|
||||
);
|
||||
}
|
||||
if (enable_dump) {
|
||||
printf("%s%s (0x%X) size=%lu\n",
|
||||
lib3ds_chunk_level,
|
||||
lib3ds_chunk_name(c->chunk),
|
||||
c->chunk,
|
||||
c->size
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,8 +77,8 @@ lib3ds_chunk_debug_dump(Lib3dsChunk *c)
|
||||
void
|
||||
lib3ds_chunk_enable_dump(Lib3dsBool enable, Lib3dsBool unknown)
|
||||
{
|
||||
enable_dump=enable;
|
||||
enable_unknown=unknown;
|
||||
enable_dump=enable;
|
||||
enable_unknown=unknown;
|
||||
}
|
||||
|
||||
|
||||
@@ -93,19 +95,18 @@ lib3ds_chunk_enable_dump(Lib3dsBool enable, Lib3dsBool unknown)
|
||||
Lib3dsBool
|
||||
lib3ds_chunk_read(Lib3dsChunk *c, FILE *f)
|
||||
{
|
||||
ASSERT(c);
|
||||
ASSERT(f);
|
||||
c->cur=ftell(f);
|
||||
c->chunk=lib3ds_word_read(f);
|
||||
c->size=lib3ds_dword_read(f);
|
||||
c->end=c->cur+c->size;
|
||||
c->cur+=6;
|
||||
if (ferror(f) || (c->size<6))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
|
||||
ASSERT(c);
|
||||
ASSERT(f);
|
||||
c->cur=ftell(f);
|
||||
c->chunk=lib3ds_word_read(f);
|
||||
c->size=lib3ds_dword_read(f);
|
||||
c->end=c->cur+c->size;
|
||||
c->cur+=6;
|
||||
if (ferror(f) || (c->size<6)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -115,14 +116,13 @@ lib3ds_chunk_read(Lib3dsChunk *c, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_chunk_read_start(Lib3dsChunk *c, Lib3dsWord chunk, FILE *f)
|
||||
{
|
||||
ASSERT(c);
|
||||
ASSERT(f);
|
||||
if (!lib3ds_chunk_read(c, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
lib3ds_chunk_debug_enter(c);
|
||||
return((chunk==0) || (c->chunk==chunk));
|
||||
ASSERT(c);
|
||||
ASSERT(f);
|
||||
if (!lib3ds_chunk_read(c, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
lib3ds_chunk_debug_enter(c);
|
||||
return((chunk==0) || (c->chunk==chunk));
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ lib3ds_chunk_read_start(Lib3dsChunk *c, Lib3dsWord chunk, FILE *f)
|
||||
void
|
||||
lib3ds_chunk_read_tell(Lib3dsChunk *c, FILE *f)
|
||||
{
|
||||
c->cur=ftell(f);
|
||||
c->cur=ftell(f);
|
||||
}
|
||||
|
||||
|
||||
@@ -142,20 +142,19 @@ lib3ds_chunk_read_tell(Lib3dsChunk *c, FILE *f)
|
||||
Lib3dsWord
|
||||
lib3ds_chunk_read_next(Lib3dsChunk *c, FILE *f)
|
||||
{
|
||||
Lib3dsChunk d;
|
||||
Lib3dsChunk d;
|
||||
|
||||
if (c->cur>=c->end)
|
||||
{
|
||||
ASSERT(c->cur==c->end);
|
||||
return(0);
|
||||
}
|
||||
if (c->cur>=c->end) {
|
||||
ASSERT(c->cur==c->end);
|
||||
return(0);
|
||||
}
|
||||
|
||||
fseek(f, (long)c->cur, SEEK_SET);
|
||||
d.chunk=lib3ds_word_read(f);
|
||||
d.size=lib3ds_dword_read(f);
|
||||
lib3ds_chunk_debug_dump(&d);
|
||||
c->cur+=d.size;
|
||||
return(d.chunk);
|
||||
fseek(f, (long)c->cur, SEEK_SET);
|
||||
d.chunk=lib3ds_word_read(f);
|
||||
d.size=lib3ds_dword_read(f);
|
||||
lib3ds_chunk_debug_dump(&d);
|
||||
c->cur+=d.size;
|
||||
return(d.chunk);
|
||||
}
|
||||
|
||||
|
||||
@@ -163,10 +162,9 @@ lib3ds_chunk_read_next(Lib3dsChunk *c, FILE *f)
|
||||
* \ingroup chunk
|
||||
*/
|
||||
void
|
||||
/*c*/
|
||||
lib3ds_chunk_read_reset(Lib3dsChunk* , FILE *f)
|
||||
lib3ds_chunk_read_reset(Lib3dsChunk *c, FILE *f)
|
||||
{
|
||||
fseek(f, -6, SEEK_CUR);
|
||||
fseek(f, -6, SEEK_CUR);
|
||||
}
|
||||
|
||||
|
||||
@@ -176,8 +174,8 @@ lib3ds_chunk_read_reset(Lib3dsChunk* , FILE *f)
|
||||
void
|
||||
lib3ds_chunk_read_end(Lib3dsChunk *c, FILE *f)
|
||||
{
|
||||
lib3ds_chunk_debug_leave(c);
|
||||
fseek(f, c->end, SEEK_SET);
|
||||
lib3ds_chunk_debug_leave(c);
|
||||
fseek(f, c->end, SEEK_SET);
|
||||
}
|
||||
|
||||
|
||||
@@ -194,18 +192,16 @@ lib3ds_chunk_read_end(Lib3dsChunk *c, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_chunk_write(Lib3dsChunk *c, FILE *f)
|
||||
{
|
||||
ASSERT(c);
|
||||
if (!lib3ds_word_write(c->chunk, f))
|
||||
{
|
||||
LIB3DS_ERROR_LOG;
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (!lib3ds_dword_write(c->size, f))
|
||||
{
|
||||
LIB3DS_ERROR_LOG;
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
ASSERT(c);
|
||||
if (!lib3ds_word_write(c->chunk, f)) {
|
||||
LIB3DS_ERROR_LOG;
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (!lib3ds_dword_write(c->size, f)) {
|
||||
LIB3DS_ERROR_LOG;
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -215,18 +211,16 @@ lib3ds_chunk_write(Lib3dsChunk *c, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_chunk_write_start(Lib3dsChunk *c, FILE *f)
|
||||
{
|
||||
ASSERT(c);
|
||||
c->size=0;
|
||||
c->cur=ftell(f);
|
||||
if (!lib3ds_word_write(c->chunk, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (!lib3ds_dword_write(c->size, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
ASSERT(c);
|
||||
c->size=0;
|
||||
c->cur=ftell(f);
|
||||
if (!lib3ds_word_write(c->chunk, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (!lib3ds_dword_write(c->size, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -236,23 +230,21 @@ lib3ds_chunk_write_start(Lib3dsChunk *c, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_chunk_write_end(Lib3dsChunk *c, FILE *f)
|
||||
{
|
||||
ASSERT(c);
|
||||
c->size=ftell(f) - c->cur;
|
||||
fseek(f, c->cur+2, SEEK_SET);
|
||||
if (!lib3ds_dword_write(c->size, f))
|
||||
{
|
||||
LIB3DS_ERROR_LOG;
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
ASSERT(c);
|
||||
c->size=ftell(f) - c->cur;
|
||||
fseek(f, c->cur+2, SEEK_SET);
|
||||
if (!lib3ds_dword_write(c->size, f)) {
|
||||
LIB3DS_ERROR_LOG;
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
|
||||
c->cur+=c->size;
|
||||
fseek(f, c->cur, SEEK_SET);
|
||||
if (ferror(f))
|
||||
{
|
||||
LIB3DS_ERROR_LOG;
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
c->cur+=c->size;
|
||||
fseek(f, c->cur, SEEK_SET);
|
||||
if (ferror(f)) {
|
||||
LIB3DS_ERROR_LOG;
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -262,16 +254,14 @@ lib3ds_chunk_write_end(Lib3dsChunk *c, FILE *f)
|
||||
const char*
|
||||
lib3ds_chunk_name(Lib3dsWord chunk)
|
||||
{
|
||||
Lib3dsChunkTable *p;
|
||||
Lib3dsChunkTable *p;
|
||||
|
||||
for (p=lib3ds_chunk_table; p->name!=0; ++p)
|
||||
{
|
||||
if (p->chunk==chunk)
|
||||
{
|
||||
return(p->name);
|
||||
}
|
||||
for (p=lib3ds_chunk_table; p->name!=0; ++p) {
|
||||
if (p->chunk==chunk) {
|
||||
return(p->name);
|
||||
}
|
||||
return("***UNKNOWN***");
|
||||
}
|
||||
return("***UNKNOWN***");
|
||||
}
|
||||
|
||||
|
||||
@@ -281,12 +271,37 @@ lib3ds_chunk_name(Lib3dsWord chunk)
|
||||
void
|
||||
lib3ds_chunk_unknown(Lib3dsWord chunk)
|
||||
{
|
||||
if (enable_unknown)
|
||||
{
|
||||
printf("%s***WARNING*** Unknown Chunk: %s (0x%X)\n",
|
||||
lib3ds_chunk_level,
|
||||
lib3ds_chunk_name(chunk),
|
||||
chunk
|
||||
);
|
||||
}
|
||||
if (enable_unknown) {
|
||||
printf("%s***WARNING*** Unknown Chunk: %s (0x%X)\n",
|
||||
lib3ds_chunk_level,
|
||||
lib3ds_chunk_name(chunk),
|
||||
chunk
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup chunk
|
||||
*/
|
||||
void
|
||||
lib3ds_chunk_dump_info(const char *format, ...)
|
||||
{
|
||||
if (enable_dump) {
|
||||
char s[1024];
|
||||
va_list marker;
|
||||
|
||||
va_start(marker, format);
|
||||
vsprintf(s, format, marker);
|
||||
va_end(marker);
|
||||
|
||||
printf("%s%s\n", lib3ds_chunk_level, s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -278,6 +278,7 @@ extern LIB3DSAPI Lib3dsBool lib3ds_chunk_write_start(Lib3dsChunk *c, FILE *f);
|
||||
extern LIB3DSAPI Lib3dsBool lib3ds_chunk_write_end(Lib3dsChunk *c, FILE *f);
|
||||
extern LIB3DSAPI const char* lib3ds_chunk_name(Lib3dsWord chunk);
|
||||
extern LIB3DSAPI void lib3ds_chunk_unknown(Lib3dsWord chunk);
|
||||
extern LIB3DSAPI void lib3ds_chunk_dump_info(const char *format, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
@@ -22,47 +22,44 @@
|
||||
#define LIB3DS_EXPORT
|
||||
#include <ease.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \defgroup ease Ease
|
||||
*
|
||||
* \author J.E. Hoffmann <je-h@gmx.net>
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup ease
|
||||
*/
|
||||
Lib3dsFloat
|
||||
lib3ds_ease(Lib3dsFloat fp, Lib3dsFloat fc, Lib3dsFloat fn,
|
||||
Lib3dsFloat ease_from, Lib3dsFloat ease_to)
|
||||
Lib3dsFloat ease_from, Lib3dsFloat ease_to)
|
||||
{
|
||||
Lib3dsDouble s,step;
|
||||
Lib3dsDouble tofrom;
|
||||
Lib3dsDouble a;
|
||||
Lib3dsDouble s,step;
|
||||
Lib3dsDouble tofrom;
|
||||
Lib3dsDouble a;
|
||||
|
||||
s=step=(Lib3dsFloat)(fc-fp)/(fn-fp);
|
||||
tofrom=ease_to+ease_from;
|
||||
if (tofrom!=0.0)
|
||||
{
|
||||
if (tofrom>1.0)
|
||||
{
|
||||
ease_to=(Lib3dsFloat)(ease_to/tofrom);
|
||||
ease_from=(Lib3dsFloat)(ease_from/tofrom);
|
||||
}
|
||||
a=1.0/(2.0-(ease_to+ease_from));
|
||||
|
||||
if (step<ease_from) s=a/ease_from*step*step;
|
||||
else
|
||||
{
|
||||
if ((1.0-ease_to)<=step)
|
||||
{
|
||||
step=1.0-step;
|
||||
s=1.0-a/ease_to*step*step;
|
||||
}
|
||||
else
|
||||
{
|
||||
s=((2.0*step)-ease_from)*a;
|
||||
}
|
||||
}
|
||||
s=step=(Lib3dsFloat)(fc-fp)/(fn-fp);
|
||||
tofrom=ease_to+ease_from;
|
||||
if (tofrom!=0.0) {
|
||||
if (tofrom>1.0) {
|
||||
ease_to=(Lib3dsFloat)(ease_to/tofrom);
|
||||
ease_from=(Lib3dsFloat)(ease_from/tofrom);
|
||||
}
|
||||
return((Lib3dsFloat)s);
|
||||
a=1.0/(2.0-(ease_to+ease_from));
|
||||
|
||||
if (step<ease_from) s=a/ease_from*step*step;
|
||||
else {
|
||||
if ((1.0-ease_to)<=step) {
|
||||
step=1.0-step;
|
||||
s=1.0-a/ease_to*step*step;
|
||||
}
|
||||
else {
|
||||
s=((2.0*step)-ease_from)*a;
|
||||
}
|
||||
}
|
||||
}
|
||||
return((Lib3dsFloat)s);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -47,6 +47,7 @@ extern "C" {
|
||||
struct _Lib3dsFile {
|
||||
Lib3dsDword mesh_version;
|
||||
Lib3dsWord keyf_revision;
|
||||
char name[12+1];
|
||||
Lib3dsFloat master_scale;
|
||||
Lib3dsVector construction_plane;
|
||||
Lib3dsRgb ambient;
|
||||
@@ -66,40 +67,33 @@ struct _Lib3dsFile {
|
||||
Lib3dsNode *nodes;
|
||||
};
|
||||
|
||||
extern LIB3DSAPI Lib3dsFile* lib3ds_open(const char *filename);
|
||||
extern LIB3DSAPI void lib3ds_close(Lib3dsFile *file);
|
||||
|
||||
extern LIB3DSAPI Lib3dsFile* lib3ds_file_load(const char *filename);
|
||||
extern LIB3DSAPI Lib3dsBool lib3ds_file_save(Lib3dsFile *file, const char *filename);
|
||||
extern LIB3DSAPI Lib3dsFile* lib3ds_file_new();
|
||||
extern LIB3DSAPI void lib3ds_file_free(Lib3dsFile *file);
|
||||
extern LIB3DSAPI void lib3ds_file_eval(Lib3dsFile *file, Lib3dsFloat t);
|
||||
|
||||
extern LIB3DSAPI Lib3dsBool lib3ds_file_read(Lib3dsFile *file, FILE *f);
|
||||
extern LIB3DSAPI Lib3dsBool lib3ds_file_write(Lib3dsFile *file, FILE *f);
|
||||
|
||||
extern LIB3DSAPI void lib3ds_file_insert_material(Lib3dsFile *file, Lib3dsMaterial *material);
|
||||
extern LIB3DSAPI void lib3ds_file_remove_material(Lib3dsFile *file, Lib3dsMaterial *material);
|
||||
extern LIB3DSAPI Lib3dsMaterial* lib3ds_file_material_by_name(Lib3dsFile *file, const char *name);
|
||||
extern LIB3DSAPI void lib3ds_file_dump_materials(Lib3dsFile *file);
|
||||
|
||||
extern LIB3DSAPI void lib3ds_file_insert_mesh(Lib3dsFile *file, Lib3dsMesh *mesh);
|
||||
extern LIB3DSAPI void lib3ds_file_remove_mesh(Lib3dsFile *file, Lib3dsMesh *mesh);
|
||||
extern LIB3DSAPI Lib3dsMesh* lib3ds_file_mesh_by_name(Lib3dsFile *file, const char *name);
|
||||
extern LIB3DSAPI void lib3ds_file_dump_meshes(Lib3dsFile *file);
|
||||
extern LIB3DSAPI void lib3ds_file_dump_instances(Lib3dsFile *file);
|
||||
|
||||
extern LIB3DSAPI void lib3ds_file_insert_camera(Lib3dsFile *file, Lib3dsCamera *camera);
|
||||
extern LIB3DSAPI void lib3ds_file_remove_camera(Lib3dsFile *file, Lib3dsCamera *camera);
|
||||
extern LIB3DSAPI Lib3dsCamera* lib3ds_file_camera_by_name(Lib3dsFile *file, const char *name);
|
||||
extern LIB3DSAPI void lib3ds_file_dump_cameras(Lib3dsFile *file);
|
||||
|
||||
extern LIB3DSAPI void lib3ds_file_insert_light(Lib3dsFile *file, Lib3dsLight *light);
|
||||
extern LIB3DSAPI void lib3ds_file_remove_light(Lib3dsFile *file, Lib3dsLight *light);
|
||||
extern LIB3DSAPI Lib3dsLight* lib3ds_file_light_by_name(Lib3dsFile *file, const char *name);
|
||||
extern LIB3DSAPI void lib3ds_file_dump_lights(Lib3dsFile *file);
|
||||
|
||||
extern LIB3DSAPI Lib3dsNode* lib3ds_file_node_by_name(Lib3dsFile *file, const char* name,
|
||||
Lib3dsNodeTypes type);
|
||||
extern LIB3DSAPI Lib3dsNode* lib3ds_file_node_by_id(Lib3dsFile *file, Lib3dsWord id);
|
||||
extern LIB3DSAPI Lib3dsNode* lib3ds_file_node_by_id(Lib3dsFile *file, Lib3dsWord node_id);
|
||||
extern LIB3DSAPI void lib3ds_file_insert_node(Lib3dsFile *file, Lib3dsNode *node);
|
||||
extern LIB3DSAPI Lib3dsBool lib3ds_file_remove_node(Lib3dsFile *file, Lib3dsNode *node);
|
||||
extern LIB3DSAPI void lib3ds_file_dump_nodes(Lib3dsFile *file);
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
@@ -22,23 +22,26 @@
|
||||
#define LIB3DS_EXPORT
|
||||
#include <lib3ds_float.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \defgroup float Floating Point Mathematics
|
||||
*
|
||||
* \author J.E. Hoffmann <je-h@gmx.net>
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup float
|
||||
*/
|
||||
Lib3dsFloat
|
||||
lib3ds_float_cubic(Lib3dsFloat a, Lib3dsFloat p, Lib3dsFloat q, Lib3dsFloat b, Lib3dsFloat t)
|
||||
{
|
||||
Lib3dsDouble x,y,z,w;
|
||||
Lib3dsDouble x,y,z,w;
|
||||
|
||||
x=2*t*t*t - 3*t*t + 1;
|
||||
y=-2*t*t*t + 3*t*t;
|
||||
z=t*t*t - 2*t*t + t;
|
||||
w=t*t*t - t*t;
|
||||
return((Lib3dsFloat)(x*a + y*b + z*p + w*q));
|
||||
x=2*t*t*t - 3*t*t + 1;
|
||||
y=-2*t*t*t + 3*t*t;
|
||||
z=t*t*t - 2*t*t + t;
|
||||
w=t*t*t - t*t;
|
||||
return((Lib3dsFloat)(x*a + y*b + z*p + w*q));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
@@ -26,16 +26,26 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
//#include <config.h>
|
||||
#include <config.h>
|
||||
#ifdef WITH_DMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*!
|
||||
* \defgroup light Lights
|
||||
*
|
||||
* \author J.E. Hoffmann <je-h@gmx.net>
|
||||
*/
|
||||
/*!
|
||||
|
||||
\typedef Lib3dsLight
|
||||
\ingroup light
|
||||
\sa _Lib3dsLight
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup light
|
||||
@@ -43,18 +53,17 @@
|
||||
Lib3dsLight*
|
||||
lib3ds_light_new(const char *name)
|
||||
{
|
||||
Lib3dsLight *light;
|
||||
Lib3dsLight *light;
|
||||
|
||||
ASSERT(name);
|
||||
ASSERT(strlen(name)<64);
|
||||
|
||||
light=(Lib3dsLight*)calloc(sizeof(Lib3dsLight), 1);
|
||||
if (!light)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
strcpy(light->name, name);
|
||||
return(light);
|
||||
ASSERT(name);
|
||||
ASSERT(strlen(name)<64);
|
||||
|
||||
light=(Lib3dsLight*)calloc(sizeof(Lib3dsLight), 1);
|
||||
if (!light) {
|
||||
return(0);
|
||||
}
|
||||
strcpy(light->name, name);
|
||||
return(light);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,8 +73,134 @@ lib3ds_light_new(const char *name)
|
||||
void
|
||||
lib3ds_light_free(Lib3dsLight *light)
|
||||
{
|
||||
memset(light, 0, sizeof(Lib3dsLight));
|
||||
free(light);
|
||||
memset(light, 0, sizeof(Lib3dsLight));
|
||||
free(light);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup light
|
||||
*/
|
||||
void
|
||||
lib3ds_light_dump(Lib3dsLight *light)
|
||||
{
|
||||
ASSERT(light);
|
||||
printf(" name: %s\n", light->name);
|
||||
printf(" spot_light: %s\n", light->spot_light ? "yes" : "no");
|
||||
printf(" see_cone: %s\n", light->see_cone ? "yes" : "no");
|
||||
printf(" color: (%f, %f, %f)\n",
|
||||
light->color[0], light->color[1], light->color[2]);
|
||||
printf(" position (%f, %f, %f)\n",
|
||||
light->position[0], light->position[1], light->position[2]);
|
||||
printf(" spot (%f, %f, %f)\n",
|
||||
light->spot[0], light->spot[1], light->spot[2]);
|
||||
printf(" roll: %f\n", light->roll);
|
||||
printf(" off: %s\n", light->off ? "yes" : "no");
|
||||
printf(" outer_range: %f\n", light->outer_range);
|
||||
printf(" inner_range: %f\n", light->inner_range);
|
||||
printf(" multiplier: %f\n", light->multiplier);
|
||||
printf(" attenuation: %f\n", light->attenuation);
|
||||
printf(" rectangular_spot: %s\n", light->rectangular_spot ? "yes" : "no");
|
||||
printf(" shadowed: %s\n", light->shadowed ? "yes" : "no");
|
||||
printf(" shadow_bias: %f\n", light->shadow_bias);
|
||||
printf(" shadow_filter: %f\n", light->shadow_filter);
|
||||
printf(" shadow_size: %d\n", light->shadow_size);
|
||||
printf(" spot_aspect: %f\n", light->spot_aspect);
|
||||
printf(" use_projector: %s\n", light->use_projector ? "yes" : "no");
|
||||
printf(" projector: %s\n", light->projector);
|
||||
printf(" spot_overshoot: %d\n", light->spot_overshoot);
|
||||
printf(" ray_shadows: %s\n", light->ray_shadows ? "yes" : "no");
|
||||
printf(" ray_bias: %f\n", light->ray_bias);
|
||||
printf(" hot_spot: %f\n", light->hot_spot);
|
||||
printf(" fall_off: %f\n", light->fall_off);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup light
|
||||
*/
|
||||
static Lib3dsBool
|
||||
spotlight_read(Lib3dsLight *light, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
int i;
|
||||
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_DL_SPOTLIGHT, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
light->spot_light=LIB3DS_TRUE;
|
||||
for (i=0; i<3; ++i) {
|
||||
light->spot[i]=lib3ds_float_read(f);
|
||||
}
|
||||
light->hot_spot = lib3ds_float_read(f);
|
||||
light->fall_off = lib3ds_float_read(f);
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
|
||||
switch (chunk) {
|
||||
case LIB3DS_DL_SPOT_ROLL:
|
||||
{
|
||||
light->roll=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_SHADOWED:
|
||||
{
|
||||
light->shadowed=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_LOCAL_SHADOW2:
|
||||
{
|
||||
light->shadow_bias=lib3ds_float_read(f);
|
||||
light->shadow_filter=lib3ds_float_read(f);
|
||||
light->shadow_size=lib3ds_intw_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_SEE_CONE:
|
||||
{
|
||||
light->see_cone=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_SPOT_RECTANGULAR:
|
||||
{
|
||||
light->rectangular_spot=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_SPOT_ASPECT:
|
||||
{
|
||||
light->spot_aspect=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_SPOT_PROJECTOR:
|
||||
{
|
||||
light->use_projector=LIB3DS_TRUE;
|
||||
if (!lib3ds_string_read(light->projector, 64, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
case LIB3DS_DL_SPOT_OVERSHOOT:
|
||||
{
|
||||
light->spot_overshoot=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_RAY_BIAS:
|
||||
{
|
||||
light->ray_bias=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_RAYSHAD:
|
||||
{
|
||||
light->ray_shadows=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,139 +210,75 @@ lib3ds_light_free(Lib3dsLight *light)
|
||||
Lib3dsBool
|
||||
lib3ds_light_read(Lib3dsLight *light, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_N_DIRECT_LIGHT, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
if (!lib3ds_chunk_read_start(&c, LIB3DS_N_DIRECT_LIGHT, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
light->position[i]=lib3ds_float_read(f);
|
||||
}
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i)
|
||||
}
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
|
||||
switch (chunk) {
|
||||
case LIB3DS_COLOR_F:
|
||||
{
|
||||
light->position[i]=lib3ds_float_read(f);
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
light->color[i]=lib3ds_float_read(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0)
|
||||
{
|
||||
switch (chunk)
|
||||
break;
|
||||
case LIB3DS_DL_OFF:
|
||||
{
|
||||
case LIB3DS_COLOR_F:
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
light->color[i]=lib3ds_float_read(f);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_OFF:
|
||||
{
|
||||
light->off=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_OUTER_RANGE:
|
||||
{
|
||||
light->outer_range=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_INNER_RANGE:
|
||||
{
|
||||
light->inner_range=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_MULTIPLIER:
|
||||
{
|
||||
light->multiplier=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_EXCLUDE:
|
||||
{
|
||||
/* FIXME: */
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
case LIB3DS_DL_ATTENUATE:
|
||||
{
|
||||
light->attenuation=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_SPOTLIGHT:
|
||||
{
|
||||
int i;
|
||||
light->spot_light=LIB3DS_TRUE;
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
light->spot[i]=lib3ds_float_read(f);
|
||||
}
|
||||
light->hot_spot=lib3ds_float_read(f);
|
||||
light->fall_off=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_SPOT_ROLL:
|
||||
{
|
||||
light->roll=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_SHADOWED:
|
||||
{
|
||||
light->shadowed=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_LOCAL_SHADOW2:
|
||||
{
|
||||
light->shadow_bias=lib3ds_float_read(f);
|
||||
light->shadow_filter=lib3ds_float_read(f);
|
||||
light->shadow_size=lib3ds_intw_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_SEE_CONE:
|
||||
{
|
||||
light->see_cone=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_SPOT_RECTANGULAR:
|
||||
{
|
||||
light->rectangular_spot=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_SPOT_ASPECT:
|
||||
{
|
||||
light->spot_aspect=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_SPOT_PROJECTOR:
|
||||
{
|
||||
light->use_projector=LIB3DS_TRUE;
|
||||
if (!lib3ds_string_read(light->projector, 64, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
case LIB3DS_DL_SPOT_OVERSHOOT:
|
||||
{
|
||||
light->spot_overshoot=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_RAY_BIAS:
|
||||
{
|
||||
light->ray_bias=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_RAYSHAD:
|
||||
{
|
||||
light->ray_shadows=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
light->off=LIB3DS_TRUE;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_OUTER_RANGE:
|
||||
{
|
||||
light->outer_range=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_INNER_RANGE:
|
||||
{
|
||||
light->inner_range=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_MULTIPLIER:
|
||||
{
|
||||
light->multiplier=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_EXCLUDE:
|
||||
{
|
||||
/* FIXME: */
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
case LIB3DS_DL_ATTENUATE:
|
||||
{
|
||||
light->attenuation=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DL_SPOTLIGHT:
|
||||
{
|
||||
lib3ds_chunk_read_reset(&c, f);
|
||||
if (!spotlight_read(light, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -217,162 +288,142 @@ lib3ds_light_read(Lib3dsLight *light, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_light_write(Lib3dsLight *light, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
|
||||
c.chunk=LIB3DS_N_DIRECT_LIGHT;
|
||||
if (!lib3ds_chunk_write_start(&c,f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
lib3ds_vector_write(light->position, f);
|
||||
{ /*---- LIB3DS_COLOR_F ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_COLOR_F;
|
||||
c.size=18;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_rgb_write(light->color,f);
|
||||
}
|
||||
if (light->off) { /*---- LIB3DS_DL_OFF ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_OFF;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
}
|
||||
{ /*---- LIB3DS_DL_OUTER_RANGE ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_OUTER_RANGE;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(light->outer_range,f);
|
||||
}
|
||||
{ /*---- LIB3DS_DL_INNER_RANGE ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_INNER_RANGE;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(light->inner_range,f);
|
||||
}
|
||||
{ /*---- LIB3DS_DL_MULTIPLIER ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_MULTIPLIER;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(light->multiplier, f);
|
||||
}
|
||||
if (light->attenuation) { /*---- LIB3DS_DL_ATTENUATE ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_ATTENUATE;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
}
|
||||
|
||||
if (light->spot_light) {
|
||||
Lib3dsChunk c;
|
||||
|
||||
c.chunk=LIB3DS_N_DIRECT_LIGHT;
|
||||
if (!lib3ds_chunk_write_start(&c,f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
c.chunk=LIB3DS_DL_SPOTLIGHT;
|
||||
if (!lib3ds_chunk_write_start(&c,f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
lib3ds_vector_write(light->position, f);
|
||||
{ /*---- LIB3DS_COLOR_F ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_COLOR_F;
|
||||
c.size=18;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_rgb_write(light->color,f);
|
||||
lib3ds_vector_write(light->spot, f);
|
||||
lib3ds_float_write(light->hot_spot, f);
|
||||
lib3ds_float_write(light->fall_off, f);
|
||||
|
||||
{ /*---- LIB3DS_DL_SPOT_ROLL ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_SPOT_ROLL;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(light->roll,f);
|
||||
}
|
||||
if (light->off) /*---- LIB3DS_DL_OFF ----*/
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_OFF;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
if (light->shadowed) { /*---- LIB3DS_DL_SHADOWED ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_SHADOWED;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
}
|
||||
{ /*---- LIB3DS_DL_OUTER_RANGE ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_OUTER_RANGE;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(light->outer_range,f);
|
||||
if ((fabs(light->shadow_bias)>LIB3DS_EPSILON) ||
|
||||
(fabs(light->shadow_filter)>LIB3DS_EPSILON) ||
|
||||
(light->shadow_size!=0)) { /*---- LIB3DS_DL_LOCAL_SHADOW2 ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_LOCAL_SHADOW2;
|
||||
c.size=16;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(light->shadow_bias,f);
|
||||
lib3ds_float_write(light->shadow_filter,f);
|
||||
lib3ds_intw_write(light->shadow_size,f);
|
||||
}
|
||||
{ /*---- LIB3DS_DL_INNER_RANGE ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_INNER_RANGE;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(light->inner_range,f);
|
||||
if (light->see_cone) { /*---- LIB3DS_DL_SEE_CONE ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_SEE_CONE;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
}
|
||||
{ /*---- LIB3DS_DL_MULTIPLIER ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_MULTIPLIER;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(light->multiplier, f);
|
||||
if (light->rectangular_spot) { /*---- LIB3DS_DL_SPOT_RECTANGULAR ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_SPOT_RECTANGULAR;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
}
|
||||
if (light->attenuation) /*---- LIB3DS_DL_ATTENUATE ----*/
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_ATTENUATE;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
if (fabs(light->spot_aspect)>LIB3DS_EPSILON) { /*---- LIB3DS_DL_SPOT_ASPECT ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_SPOT_ASPECT;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(light->spot_aspect,f);
|
||||
}
|
||||
|
||||
if (light->spot_light)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
|
||||
c.chunk=LIB3DS_DL_SPOTLIGHT;
|
||||
if (!lib3ds_chunk_write_start(&c,f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
lib3ds_vector_write(light->spot, f);
|
||||
lib3ds_float_write(light->hot_spot, f);
|
||||
lib3ds_float_write(light->fall_off, f);
|
||||
|
||||
{ /*---- LIB3DS_DL_SPOT_ROLL ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_SPOT_ROLL;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(light->roll,f);
|
||||
}
|
||||
if (light->shadowed) /*---- LIB3DS_DL_SHADOWED ----*/
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_SHADOWED;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
}
|
||||
{ /*---- LIB3DS_DL_LOCAL_SHADOW2 ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_LOCAL_SHADOW2;
|
||||
c.size=16;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(light->shadow_bias,f);
|
||||
lib3ds_float_write(light->shadow_filter,f);
|
||||
lib3ds_intw_write(light->shadow_size,f);
|
||||
}
|
||||
if (light->see_cone) /*---- LIB3DS_DL_SEE_CONE ----*/
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_SEE_CONE;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
}
|
||||
/*---- LIB3DS_DL_SPOT_RECTANGULAR ----*/
|
||||
if (light->rectangular_spot)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_SPOT_RECTANGULAR;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
}
|
||||
{ /*---- LIB3DS_DL_SPOT_ASPECT ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_SPOT_ASPECT;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(light->spot_aspect,f);
|
||||
}
|
||||
if (light->use_projector)/*---- LIB3DS_DL_SPOT_PROJECTOR ----*/
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_SPOT_PROJECTOR;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_string_write(light->projector,f);
|
||||
}
|
||||
/*---- LIB3DS_DL_SPOT_OVERSHOOT ----*/
|
||||
if (light->spot_overshoot)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_SPOT_OVERSHOOT;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
}
|
||||
{ /*---- LIB3DS_DL_RAY_BIAS ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_RAY_BIAS;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(light->ray_bias,f);
|
||||
}
|
||||
if (light->ray_shadows) /*---- LIB3DS_DL_RAYSHAD ----*/
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_RAYSHAD;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
}
|
||||
if (!lib3ds_chunk_write_end(&c,f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (light->use_projector) { /*---- LIB3DS_DL_SPOT_PROJECTOR ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_SPOT_PROJECTOR;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_string_write(light->projector,f);
|
||||
}
|
||||
if (!lib3ds_chunk_write_end(&c,f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
if (light->spot_overshoot) { /*---- LIB3DS_DL_SPOT_OVERSHOOT ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_SPOT_OVERSHOOT;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
if (fabs(light->ray_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_DL_RAY_BIAS ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_RAY_BIAS;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
lib3ds_float_write(light->ray_bias,f);
|
||||
}
|
||||
if (light->ray_shadows) { /*---- LIB3DS_DL_RAYSHAD ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_DL_RAYSHAD;
|
||||
c.size=6;
|
||||
lib3ds_chunk_write(&c, f);
|
||||
}
|
||||
if (!lib3ds_chunk_write_end(&c,f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
if (!lib3ds_chunk_write_end(&c,f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
|
||||
\typedef Lib3dsLight
|
||||
\ingroup light
|
||||
\sa _Lib3dsLight
|
||||
|
||||
*/
|
||||
|
||||
@@ -67,6 +67,7 @@ struct _Lib3dsLight {
|
||||
|
||||
extern LIB3DSAPI Lib3dsLight* lib3ds_light_new(const char *name);
|
||||
extern LIB3DSAPI void lib3ds_light_free(Lib3dsLight *mesh);
|
||||
extern LIB3DSAPI void lib3ds_light_dump(Lib3dsLight *light);
|
||||
extern LIB3DSAPI Lib3dsBool lib3ds_light_read(Lib3dsLight *light, FILE *f);
|
||||
extern LIB3DSAPI Lib3dsBool lib3ds_light_write(Lib3dsLight *light, FILE *f);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,13 +4,13 @@
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
@@ -26,6 +26,7 @@
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \defgroup matrix Matrix Mathematics
|
||||
*
|
||||
@@ -36,18 +37,18 @@
|
||||
* \ingroup matrix
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup matrix
|
||||
*/
|
||||
void
|
||||
lib3ds_matrix_zero(Lib3dsMatrix m)
|
||||
{
|
||||
int i,j;
|
||||
int i,j;
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
for (j=0; j<4; j++) m[i][j]=0.0f;
|
||||
}
|
||||
for (i=0; i<4; i++) {
|
||||
for (j=0; j<4; j++) m[i][j]=0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,13 +58,12 @@ lib3ds_matrix_zero(Lib3dsMatrix m)
|
||||
void
|
||||
lib3ds_matrix_identity(Lib3dsMatrix m)
|
||||
{
|
||||
int i,j;
|
||||
int i,j;
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
for (j=0; j<4; j++) m[i][j]=0.0;
|
||||
}
|
||||
for (i=0; i<4; i++) m[i][i]=1.0;
|
||||
for (i=0; i<4; i++) {
|
||||
for (j=0; j<4; j++) m[i][j]=0.0;
|
||||
}
|
||||
for (i=0; i<4; i++) m[i][i]=1.0;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,43 +73,39 @@ lib3ds_matrix_identity(Lib3dsMatrix m)
|
||||
void
|
||||
lib3ds_matrix_copy(Lib3dsMatrix dest, Lib3dsMatrix src)
|
||||
{
|
||||
memcpy(dest, src, sizeof(Lib3dsMatrix));
|
||||
memcpy(dest, src, sizeof(Lib3dsMatrix));
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup matrix
|
||||
*/
|
||||
void
|
||||
void
|
||||
lib3ds_matrix_neg(Lib3dsMatrix m)
|
||||
{
|
||||
int i,j;
|
||||
int i,j;
|
||||
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
m[j][i]=-m[j][i];
|
||||
}
|
||||
for (j=0; j<4; j++) {
|
||||
for (i=0; i<4; i++) {
|
||||
m[j][i]=-m[j][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup matrix
|
||||
*/
|
||||
void
|
||||
void
|
||||
lib3ds_matrix_abs(Lib3dsMatrix m)
|
||||
{
|
||||
int i,j;
|
||||
int i,j;
|
||||
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
m[j][i]=(Lib3dsFloat)fabs(m[j][i]);
|
||||
}
|
||||
for (j=0; j<4; j++) {
|
||||
for (i=0; i<4; i++) {
|
||||
m[j][i]=(Lib3dsFloat)fabs(m[j][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,18 +115,16 @@ lib3ds_matrix_abs(Lib3dsMatrix m)
|
||||
void
|
||||
lib3ds_matrix_transpose(Lib3dsMatrix m)
|
||||
{
|
||||
int i,j;
|
||||
Lib3dsFloat swp;
|
||||
int i,j;
|
||||
Lib3dsFloat swp;
|
||||
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
for (i=j+1; i<4; i++)
|
||||
{
|
||||
swp=m[j][i];
|
||||
m[j][i]=m[i][j];
|
||||
m[i][j]=swp;
|
||||
}
|
||||
for (j=0; j<4; j++) {
|
||||
for (i=j+1; i<4; i++) {
|
||||
swp=m[j][i];
|
||||
m[j][i]=m[i][j];
|
||||
m[i][j]=swp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,15 +134,13 @@ lib3ds_matrix_transpose(Lib3dsMatrix m)
|
||||
void
|
||||
lib3ds_matrix_add(Lib3dsMatrix m, Lib3dsMatrix a, Lib3dsMatrix b)
|
||||
{
|
||||
int i,j;
|
||||
int i,j;
|
||||
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
m[j][i]=a[j][i]+b[j][i];
|
||||
}
|
||||
for (j=0; j<4; j++) {
|
||||
for (i=0; i<4; i++) {
|
||||
m[j][i]=a[j][i]+b[j][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -158,15 +150,13 @@ lib3ds_matrix_add(Lib3dsMatrix m, Lib3dsMatrix a, Lib3dsMatrix b)
|
||||
void
|
||||
lib3ds_matrix_sub(Lib3dsMatrix m, Lib3dsMatrix a, Lib3dsMatrix b)
|
||||
{
|
||||
int i,j;
|
||||
int i,j;
|
||||
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
m[j][i]=a[j][i]-b[j][i];
|
||||
}
|
||||
for (j=0; j<4; j++) {
|
||||
for (i=0; i<4; i++) {
|
||||
m[j][i]=a[j][i]-b[j][i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -176,18 +166,16 @@ lib3ds_matrix_sub(Lib3dsMatrix m, Lib3dsMatrix a, Lib3dsMatrix b)
|
||||
void
|
||||
lib3ds_matrix_mul(Lib3dsMatrix m, Lib3dsMatrix a, Lib3dsMatrix b)
|
||||
{
|
||||
int i,j,k;
|
||||
Lib3dsFloat ab;
|
||||
int i,j,k;
|
||||
Lib3dsFloat ab;
|
||||
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
ab=0.0f;
|
||||
for (k=0; k<4; k++) ab+=a[k][i]*b[j][k];
|
||||
m[j][i]=ab;
|
||||
}
|
||||
for (j=0; j<4; j++) {
|
||||
for (i=0; i<4; i++) {
|
||||
ab=0.0f;
|
||||
for (k=0; k<4; k++) ab+=a[k][i]*b[j][k];
|
||||
m[j][i]=ab;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -197,38 +185,36 @@ lib3ds_matrix_mul(Lib3dsMatrix m, Lib3dsMatrix a, Lib3dsMatrix b)
|
||||
void
|
||||
lib3ds_matrix_scalar(Lib3dsMatrix m, Lib3dsFloat k)
|
||||
{
|
||||
int i,j;
|
||||
int i,j;
|
||||
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
m[j][i]*=k;
|
||||
}
|
||||
for (j=0; j<4; j++) {
|
||||
for (i=0; i<4; i++) {
|
||||
m[j][i]*=k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static Lib3dsFloat
|
||||
det2x2(
|
||||
Lib3dsFloat a, Lib3dsFloat b,
|
||||
Lib3dsFloat c, Lib3dsFloat d)
|
||||
Lib3dsFloat a, Lib3dsFloat b,
|
||||
Lib3dsFloat c, Lib3dsFloat d)
|
||||
{
|
||||
return((a)*(d)-(b)*(c));
|
||||
return((a)*(d)-(b)*(c));
|
||||
}
|
||||
|
||||
|
||||
static Lib3dsFloat
|
||||
det3x3(
|
||||
Lib3dsFloat a1, Lib3dsFloat a2, Lib3dsFloat a3,
|
||||
Lib3dsFloat b1, Lib3dsFloat b2, Lib3dsFloat b3,
|
||||
Lib3dsFloat c1, Lib3dsFloat c2, Lib3dsFloat c3)
|
||||
Lib3dsFloat a1, Lib3dsFloat a2, Lib3dsFloat a3,
|
||||
Lib3dsFloat b1, Lib3dsFloat b2, Lib3dsFloat b3,
|
||||
Lib3dsFloat c1, Lib3dsFloat c2, Lib3dsFloat c3)
|
||||
{
|
||||
return(
|
||||
a1*det2x2(b2,b3,c2,c3)-
|
||||
b1*det2x2(a2,a3,c2,c3)+
|
||||
c1*det2x2(a2,a3,b2,b3)
|
||||
);
|
||||
return(
|
||||
a1*det2x2(b2,b3,c2,c3)-
|
||||
b1*det2x2(a2,a3,c2,c3)+
|
||||
c1*det2x2(a2,a3,b2,b3)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -238,30 +224,30 @@ Lib3dsFloat c1, Lib3dsFloat c2, Lib3dsFloat c3)
|
||||
Lib3dsFloat
|
||||
lib3ds_matrix_det(Lib3dsMatrix m)
|
||||
{
|
||||
Lib3dsFloat a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4,d1,d2,d3,d4;
|
||||
Lib3dsFloat a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4,d1,d2,d3,d4;
|
||||
|
||||
a1 = m[0][0];
|
||||
b1 = m[1][0];
|
||||
c1 = m[2][0];
|
||||
d1 = m[3][0];
|
||||
a2 = m[0][1];
|
||||
b2 = m[1][1];
|
||||
c2 = m[2][1];
|
||||
d2 = m[3][1];
|
||||
a3 = m[0][2];
|
||||
b3 = m[1][2];
|
||||
c3 = m[2][2];
|
||||
d3 = m[3][2];
|
||||
a4 = m[0][3];
|
||||
b4 = m[1][3];
|
||||
c4 = m[2][3];
|
||||
d4 = m[3][3];
|
||||
return(
|
||||
a1 * det3x3(b2, b3, b4, c2, c3, c4, d2, d3, d4)-
|
||||
b1 * det3x3(a2, a3, a4, c2, c3, c4, d2, d3, d4)+
|
||||
c1 * det3x3(a2, a3, a4, b2, b3, b4, d2, d3, d4)-
|
||||
d1 * det3x3(a2, a3, a4, b2, b3, b4, c2, c3, c4)
|
||||
);
|
||||
a1 = m[0][0];
|
||||
b1 = m[1][0];
|
||||
c1 = m[2][0];
|
||||
d1 = m[3][0];
|
||||
a2 = m[0][1];
|
||||
b2 = m[1][1];
|
||||
c2 = m[2][1];
|
||||
d2 = m[3][1];
|
||||
a3 = m[0][2];
|
||||
b3 = m[1][2];
|
||||
c3 = m[2][2];
|
||||
d3 = m[3][2];
|
||||
a4 = m[0][3];
|
||||
b4 = m[1][3];
|
||||
c4 = m[2][3];
|
||||
d4 = m[3][3];
|
||||
return(
|
||||
a1 * det3x3(b2, b3, b4, c2, c3, c4, d2, d3, d4)-
|
||||
b1 * det3x3(a2, a3, a4, c2, c3, c4, d2, d3, d4)+
|
||||
c1 * det3x3(a2, a3, a4, b2, b3, b4, d2, d3, d4)-
|
||||
d1 * det3x3(a2, a3, a4, b2, b3, b4, c2, c3, c4)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -271,159 +257,142 @@ lib3ds_matrix_det(Lib3dsMatrix m)
|
||||
void
|
||||
lib3ds_matrix_adjoint(Lib3dsMatrix m)
|
||||
{
|
||||
Lib3dsFloat a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4,d1,d2,d3,d4;
|
||||
Lib3dsFloat a1,a2,a3,a4,b1,b2,b3,b4,c1,c2,c3,c4,d1,d2,d3,d4;
|
||||
|
||||
a1 = m[0][0];
|
||||
b1 = m[1][0];
|
||||
c1 = m[2][0];
|
||||
d1 = m[3][0];
|
||||
a2 = m[0][1];
|
||||
b2 = m[1][1];
|
||||
c2 = m[2][1];
|
||||
d2 = m[3][1];
|
||||
a3 = m[0][2];
|
||||
b3 = m[1][2];
|
||||
c3 = m[2][2];
|
||||
d3 = m[3][2];
|
||||
a4 = m[0][3];
|
||||
b4 = m[1][3];
|
||||
c4 = m[2][3];
|
||||
d4 = m[3][3];
|
||||
m[0][0]= det3x3 (b2, b3, b4, c2, c3, c4, d2, d3, d4);
|
||||
m[0][1]= -det3x3 (a2, a3, a4, c2, c3, c4, d2, d3, d4);
|
||||
m[0][2]= det3x3 (a2, a3, a4, b2, b3, b4, d2, d3, d4);
|
||||
m[0][3]= -det3x3 (a2, a3, a4, b2, b3, b4, c2, c3, c4);
|
||||
m[1][0]= -det3x3 (b1, b3, b4, c1, c3, c4, d1, d3, d4);
|
||||
m[1][1]= det3x3 (a1, a3, a4, c1, c3, c4, d1, d3, d4);
|
||||
m[1][2]= -det3x3 (a1, a3, a4, b1, b3, b4, d1, d3, d4);
|
||||
m[1][3]= det3x3 (a1, a3, a4, b1, b3, b4, c1, c3, c4);
|
||||
m[2][0]= det3x3 (b1, b2, b4, c1, c2, c4, d1, d2, d4);
|
||||
m[2][1]= -det3x3 (a1, a2, a4, c1, c2, c4, d1, d2, d4);
|
||||
m[2][2]= det3x3 (a1, a2, a4, b1, b2, b4, d1, d2, d4);
|
||||
m[2][3]= -det3x3 (a1, a2, a4, b1, b2, b4, c1, c2, c4);
|
||||
m[3][0]= -det3x3 (b1, b2, b3, c1, c2, c3, d1, d2, d3);
|
||||
m[3][1]= det3x3 (a1, a2, a3, c1, c2, c3, d1, d2, d3);
|
||||
m[3][2]= -det3x3 (a1, a2, a3, b1, b2, b3, d1, d2, d3);
|
||||
m[3][3]= det3x3 (a1, a2, a3, b1, b2, b3, c1, c2, c3);
|
||||
a1 = m[0][0];
|
||||
b1 = m[1][0];
|
||||
c1 = m[2][0];
|
||||
d1 = m[3][0];
|
||||
a2 = m[0][1];
|
||||
b2 = m[1][1];
|
||||
c2 = m[2][1];
|
||||
d2 = m[3][1];
|
||||
a3 = m[0][2];
|
||||
b3 = m[1][2];
|
||||
c3 = m[2][2];
|
||||
d3 = m[3][2];
|
||||
a4 = m[0][3];
|
||||
b4 = m[1][3];
|
||||
c4 = m[2][3];
|
||||
d4 = m[3][3];
|
||||
m[0][0]= det3x3 (b2, b3, b4, c2, c3, c4, d2, d3, d4);
|
||||
m[0][1]= -det3x3 (a2, a3, a4, c2, c3, c4, d2, d3, d4);
|
||||
m[0][2]= det3x3 (a2, a3, a4, b2, b3, b4, d2, d3, d4);
|
||||
m[0][3]= -det3x3 (a2, a3, a4, b2, b3, b4, c2, c3, c4);
|
||||
m[1][0]= -det3x3 (b1, b3, b4, c1, c3, c4, d1, d3, d4);
|
||||
m[1][1]= det3x3 (a1, a3, a4, c1, c3, c4, d1, d3, d4);
|
||||
m[1][2]= -det3x3 (a1, a3, a4, b1, b3, b4, d1, d3, d4);
|
||||
m[1][3]= det3x3 (a1, a3, a4, b1, b3, b4, c1, c3, c4);
|
||||
m[2][0]= det3x3 (b1, b2, b4, c1, c2, c4, d1, d2, d4);
|
||||
m[2][1]= -det3x3 (a1, a2, a4, c1, c2, c4, d1, d2, d4);
|
||||
m[2][2]= det3x3 (a1, a2, a4, b1, b2, b4, d1, d2, d4);
|
||||
m[2][3]= -det3x3 (a1, a2, a4, b1, b2, b4, c1, c2, c4);
|
||||
m[3][0]= -det3x3 (b1, b2, b3, c1, c2, c3, d1, d2, d3);
|
||||
m[3][1]= det3x3 (a1, a2, a3, c1, c2, c3, d1, d2, d3);
|
||||
m[3][2]= -det3x3 (a1, a2, a3, b1, b2, b3, d1, d2, d3);
|
||||
m[3][3]= det3x3 (a1, a2, a3, b1, b2, b3, c1, c2, c3);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup matrix
|
||||
*
|
||||
* GGemsII, K.Wu, Fast Matrix Inversion
|
||||
* GGemsII, K.Wu, Fast Matrix Inversion
|
||||
*/
|
||||
Lib3dsBool
|
||||
lib3ds_matrix_inv(Lib3dsMatrix m)
|
||||
{
|
||||
int i,j,k;
|
||||
int pvt_i[4], pvt_j[4]; /* Locations of pivot elements */
|
||||
Lib3dsFloat pvt_val; /* Value of current pivot element */
|
||||
Lib3dsFloat hold; /* Temporary storage */
|
||||
Lib3dsFloat determinat;
|
||||
{
|
||||
int i,j,k;
|
||||
int pvt_i[4], pvt_j[4]; /* Locations of pivot elements */
|
||||
Lib3dsFloat pvt_val; /* Value of current pivot element */
|
||||
Lib3dsFloat hold; /* Temporary storage */
|
||||
Lib3dsFloat determinat;
|
||||
|
||||
determinat = 1.0f;
|
||||
for (k=0; k<4; k++)
|
||||
{
|
||||
/* Locate k'th pivot element */
|
||||
pvt_val=m[k][k]; /* Initialize for search */
|
||||
pvt_i[k]=k;
|
||||
pvt_j[k]=k;
|
||||
for (i=k; i<4; i++)
|
||||
{
|
||||
for (j=k; j<4; j++)
|
||||
{
|
||||
if (fabs(m[i][j]) > fabs(pvt_val))
|
||||
{
|
||||
pvt_i[k]=i;
|
||||
pvt_j[k]=j;
|
||||
pvt_val=m[i][j];
|
||||
}
|
||||
}
|
||||
determinat = 1.0f;
|
||||
for (k=0; k<4; k++) {
|
||||
/* Locate k'th pivot element */
|
||||
pvt_val=m[k][k]; /* Initialize for search */
|
||||
pvt_i[k]=k;
|
||||
pvt_j[k]=k;
|
||||
for (i=k; i<4; i++) {
|
||||
for (j=k; j<4; j++) {
|
||||
if (fabs(m[i][j]) > fabs(pvt_val)) {
|
||||
pvt_i[k]=i;
|
||||
pvt_j[k]=j;
|
||||
pvt_val=m[i][j];
|
||||
}
|
||||
|
||||
/* Product of pivots, gives determinant when finished */
|
||||
determinat*=pvt_val;
|
||||
if (fabs(determinat)<LIB3DS_EPSILON)
|
||||
{
|
||||
return(LIB3DS_FALSE);/* Matrix is singular (zero determinant) */
|
||||
}
|
||||
|
||||
/* "Interchange" rows (with sign change stuff) */
|
||||
i=pvt_i[k];
|
||||
if (i!=k) /* If rows are different */
|
||||
{
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
hold=-m[k][j];
|
||||
m[k][j]=m[i][j];
|
||||
m[i][j]=hold;
|
||||
}
|
||||
}
|
||||
|
||||
/* "Interchange" columns */
|
||||
j=pvt_j[k];
|
||||
if (j!=k) /* If columns are different */
|
||||
{
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
hold=-m[i][k];
|
||||
m[i][k]=m[i][j];
|
||||
m[i][j]=hold;
|
||||
}
|
||||
}
|
||||
|
||||
/* Divide column by minus pivot value */
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
if (i!=k) m[i][k]/=( -pvt_val) ;
|
||||
}
|
||||
|
||||
/* Reduce the matrix */
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
hold = m[i][k];
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
if (i!=k && j!=k) m[i][j]+=hold*m[k][j];
|
||||
}
|
||||
}
|
||||
|
||||
/* Divide row by pivot */
|
||||
for (j=0; j<4; j++)
|
||||
{
|
||||
if (j!=k) m[k][j]/=pvt_val;
|
||||
}
|
||||
|
||||
/* Replace pivot by reciprocal (at last we can touch it). */
|
||||
m[k][k] = 1.0f/pvt_val;
|
||||
}
|
||||
}
|
||||
|
||||
/* That was most of the work, one final pass of row/column interchange */
|
||||
/* to finish */
|
||||
for (k=4-2; k>=0; k--) /* Don't need to work with 1 by 1 corner*/
|
||||
{
|
||||
i=pvt_j[k]; /* Rows to swap correspond to pivot COLUMN */
|
||||
if (i!=k) /* If rows are different */
|
||||
{
|
||||
for(j=0; j<4; j++)
|
||||
{
|
||||
hold = m[k][j];
|
||||
m[k][j]=-m[i][j];
|
||||
m[i][j]=hold;
|
||||
}
|
||||
}
|
||||
|
||||
j=pvt_i[k]; /* Columns to swap correspond to pivot ROW */
|
||||
if (j!=k) /* If columns are different */
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
hold=m[i][k];
|
||||
m[i][k]=-m[i][j];
|
||||
m[i][j]=hold;
|
||||
}
|
||||
/* Product of pivots, gives determinant when finished */
|
||||
determinat*=pvt_val;
|
||||
if (fabs(determinat)<LIB3DS_EPSILON) {
|
||||
return(LIB3DS_FALSE); /* Matrix is singular (zero determinant) */
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
|
||||
/* "Interchange" rows (with sign change stuff) */
|
||||
i=pvt_i[k];
|
||||
if (i!=k) { /* If rows are different */
|
||||
for (j=0; j<4; j++) {
|
||||
hold=-m[k][j];
|
||||
m[k][j]=m[i][j];
|
||||
m[i][j]=hold;
|
||||
}
|
||||
}
|
||||
|
||||
/* "Interchange" columns */
|
||||
j=pvt_j[k];
|
||||
if (j!=k) { /* If columns are different */
|
||||
for (i=0; i<4; i++) {
|
||||
hold=-m[i][k];
|
||||
m[i][k]=m[i][j];
|
||||
m[i][j]=hold;
|
||||
}
|
||||
}
|
||||
|
||||
/* Divide column by minus pivot value */
|
||||
for (i=0; i<4; i++) {
|
||||
if (i!=k) m[i][k]/=( -pvt_val) ;
|
||||
}
|
||||
|
||||
/* Reduce the matrix */
|
||||
for (i=0; i<4; i++) {
|
||||
hold = m[i][k];
|
||||
for (j=0; j<4; j++) {
|
||||
if (i!=k && j!=k) m[i][j]+=hold*m[k][j];
|
||||
}
|
||||
}
|
||||
|
||||
/* Divide row by pivot */
|
||||
for (j=0; j<4; j++) {
|
||||
if (j!=k) m[k][j]/=pvt_val;
|
||||
}
|
||||
|
||||
/* Replace pivot by reciprocal (at last we can touch it). */
|
||||
m[k][k] = 1.0f/pvt_val;
|
||||
}
|
||||
|
||||
/* That was most of the work, one final pass of row/column interchange */
|
||||
/* to finish */
|
||||
for (k=4-2; k>=0; k--) { /* Don't need to work with 1 by 1 corner*/
|
||||
i=pvt_j[k]; /* Rows to swap correspond to pivot COLUMN */
|
||||
if (i!=k) { /* If rows are different */
|
||||
for(j=0; j<4; j++) {
|
||||
hold = m[k][j];
|
||||
m[k][j]=-m[i][j];
|
||||
m[i][j]=hold;
|
||||
}
|
||||
}
|
||||
|
||||
j=pvt_i[k]; /* Columns to swap correspond to pivot ROW */
|
||||
if (j!=k) /* If columns are different */
|
||||
for (i=0; i<4; i++) {
|
||||
hold=m[i][k];
|
||||
m[i][k]=-m[i][j];
|
||||
m[i][j]=hold;
|
||||
}
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -433,12 +402,11 @@ lib3ds_matrix_inv(Lib3dsMatrix m)
|
||||
void
|
||||
lib3ds_matrix_translate_xyz(Lib3dsMatrix m, Lib3dsFloat x, Lib3dsFloat y, Lib3dsFloat z)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<3; i++)
|
||||
{
|
||||
m[3][i]+= m[0][i]*x + m[1][i]*y + m[2][i]*z;
|
||||
}
|
||||
int i;
|
||||
|
||||
for (i=0; i<3; i++) {
|
||||
m[3][i]+= m[0][i]*x + m[1][i]*y + m[2][i]*z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -448,12 +416,11 @@ lib3ds_matrix_translate_xyz(Lib3dsMatrix m, Lib3dsFloat x, Lib3dsFloat y, Lib3ds
|
||||
void
|
||||
lib3ds_matrix_translate(Lib3dsMatrix m, Lib3dsVector t)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<3; i++)
|
||||
{
|
||||
m[3][i]+= m[0][i]*t[0] + m[1][i]*t[1] + m[2][i]*t[2];
|
||||
}
|
||||
int i;
|
||||
|
||||
for (i=0; i<3; i++) {
|
||||
m[3][i]+= m[0][i]*t[0] + m[1][i]*t[1] + m[2][i]*t[2];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -463,14 +430,13 @@ lib3ds_matrix_translate(Lib3dsMatrix m, Lib3dsVector t)
|
||||
void
|
||||
lib3ds_matrix_scale_xyz(Lib3dsMatrix m, Lib3dsFloat x, Lib3dsFloat y, Lib3dsFloat z)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
m[0][i]*=x;
|
||||
m[1][i]*=y;
|
||||
m[2][i]*=z;
|
||||
}
|
||||
for (i=0; i<4; i++) {
|
||||
m[0][i]*=x;
|
||||
m[1][i]*=y;
|
||||
m[2][i]*=z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -480,14 +446,13 @@ lib3ds_matrix_scale_xyz(Lib3dsMatrix m, Lib3dsFloat x, Lib3dsFloat y, Lib3dsFloa
|
||||
void
|
||||
lib3ds_matrix_scale(Lib3dsMatrix m, Lib3dsVector s)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
m[0][i]*=s[0];
|
||||
m[1][i]*=s[1];
|
||||
m[2][i]*=s[2];
|
||||
}
|
||||
for (i=0; i<4; i++) {
|
||||
m[0][i]*=s[0];
|
||||
m[1][i]*=s[1];
|
||||
m[2][i]*=s[2];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -497,21 +462,21 @@ lib3ds_matrix_scale(Lib3dsMatrix m, Lib3dsVector s)
|
||||
void
|
||||
lib3ds_matrix_rotate_x(Lib3dsMatrix m, Lib3dsFloat phi)
|
||||
{
|
||||
Lib3dsFloat SinPhi,CosPhi;
|
||||
Lib3dsFloat a1[4],a2[4];
|
||||
Lib3dsFloat SinPhi,CosPhi;
|
||||
Lib3dsFloat a1[4],a2[4];
|
||||
|
||||
SinPhi=(Lib3dsFloat)sin(phi);
|
||||
CosPhi=(Lib3dsFloat)cos(phi);
|
||||
memcpy(a1,m[1],4*sizeof(Lib3dsFloat));
|
||||
memcpy(a2,m[2],4*sizeof(Lib3dsFloat));
|
||||
m[1][0]=CosPhi*a1[0]+SinPhi*a2[0];
|
||||
m[1][1]=CosPhi*a1[1]+SinPhi*a2[1];
|
||||
m[1][2]=CosPhi*a1[2]+SinPhi*a2[2];
|
||||
m[1][3]=CosPhi*a1[3]+SinPhi*a2[3];
|
||||
m[2][0]=-SinPhi*a1[0]+CosPhi*a2[0];
|
||||
m[2][1]=-SinPhi*a1[1]+CosPhi*a2[1];
|
||||
m[2][2]=-SinPhi*a1[2]+CosPhi*a2[2];
|
||||
m[2][3]=-SinPhi*a1[3]+CosPhi*a2[3];
|
||||
SinPhi=(Lib3dsFloat)sin(phi);
|
||||
CosPhi=(Lib3dsFloat)cos(phi);
|
||||
memcpy(a1,m[1],4*sizeof(Lib3dsFloat));
|
||||
memcpy(a2,m[2],4*sizeof(Lib3dsFloat));
|
||||
m[1][0]=CosPhi*a1[0]+SinPhi*a2[0];
|
||||
m[1][1]=CosPhi*a1[1]+SinPhi*a2[1];
|
||||
m[1][2]=CosPhi*a1[2]+SinPhi*a2[2];
|
||||
m[1][3]=CosPhi*a1[3]+SinPhi*a2[3];
|
||||
m[2][0]=-SinPhi*a1[0]+CosPhi*a2[0];
|
||||
m[2][1]=-SinPhi*a1[1]+CosPhi*a2[1];
|
||||
m[2][2]=-SinPhi*a1[2]+CosPhi*a2[2];
|
||||
m[2][3]=-SinPhi*a1[3]+CosPhi*a2[3];
|
||||
}
|
||||
|
||||
|
||||
@@ -521,21 +486,21 @@ lib3ds_matrix_rotate_x(Lib3dsMatrix m, Lib3dsFloat phi)
|
||||
void
|
||||
lib3ds_matrix_rotate_y(Lib3dsMatrix m, Lib3dsFloat phi)
|
||||
{
|
||||
Lib3dsFloat SinPhi,CosPhi;
|
||||
Lib3dsFloat a0[4],a2[4];
|
||||
Lib3dsFloat SinPhi,CosPhi;
|
||||
Lib3dsFloat a0[4],a2[4];
|
||||
|
||||
SinPhi=(Lib3dsFloat)sin(phi);
|
||||
CosPhi=(Lib3dsFloat)cos(phi);
|
||||
memcpy(a0,m[0],4*sizeof(Lib3dsFloat));
|
||||
memcpy(a2,m[2],4*sizeof(Lib3dsFloat));
|
||||
m[0][0]=CosPhi*a0[0]-SinPhi*a2[0];
|
||||
m[0][1]=CosPhi*a0[1]-SinPhi*a2[1];
|
||||
m[0][2]=CosPhi*a0[2]-SinPhi*a2[2];
|
||||
m[0][3]=CosPhi*a0[3]-SinPhi*a2[3];
|
||||
m[2][0]=SinPhi*a0[0]+CosPhi*a2[0];
|
||||
m[2][1]=SinPhi*a0[1]+CosPhi*a2[1];
|
||||
m[2][2]=SinPhi*a0[2]+CosPhi*a2[2];
|
||||
m[2][3]=SinPhi*a0[3]+CosPhi*a2[3];
|
||||
SinPhi=(Lib3dsFloat)sin(phi);
|
||||
CosPhi=(Lib3dsFloat)cos(phi);
|
||||
memcpy(a0,m[0],4*sizeof(Lib3dsFloat));
|
||||
memcpy(a2,m[2],4*sizeof(Lib3dsFloat));
|
||||
m[0][0]=CosPhi*a0[0]-SinPhi*a2[0];
|
||||
m[0][1]=CosPhi*a0[1]-SinPhi*a2[1];
|
||||
m[0][2]=CosPhi*a0[2]-SinPhi*a2[2];
|
||||
m[0][3]=CosPhi*a0[3]-SinPhi*a2[3];
|
||||
m[2][0]=SinPhi*a0[0]+CosPhi*a2[0];
|
||||
m[2][1]=SinPhi*a0[1]+CosPhi*a2[1];
|
||||
m[2][2]=SinPhi*a0[2]+CosPhi*a2[2];
|
||||
m[2][3]=SinPhi*a0[3]+CosPhi*a2[3];
|
||||
}
|
||||
|
||||
|
||||
@@ -545,21 +510,21 @@ lib3ds_matrix_rotate_y(Lib3dsMatrix m, Lib3dsFloat phi)
|
||||
void
|
||||
lib3ds_matrix_rotate_z(Lib3dsMatrix m, Lib3dsFloat phi)
|
||||
{
|
||||
Lib3dsFloat SinPhi,CosPhi;
|
||||
Lib3dsFloat a0[4],a1[4];
|
||||
|
||||
SinPhi=(Lib3dsFloat)sin(phi);
|
||||
CosPhi=(Lib3dsFloat)cos(phi);
|
||||
memcpy(a0,m[0],4*sizeof(Lib3dsFloat));
|
||||
memcpy(a1,m[1],4*sizeof(Lib3dsFloat));
|
||||
m[0][0]=CosPhi*a0[0]+SinPhi*a1[0];
|
||||
m[0][1]=CosPhi*a0[1]+SinPhi*a1[1];
|
||||
m[0][2]=CosPhi*a0[2]+SinPhi*a1[2];
|
||||
m[0][3]=CosPhi*a0[3]+SinPhi*a1[3];
|
||||
m[1][0]=-SinPhi*a0[0]+CosPhi*a1[0];
|
||||
m[1][1]=-SinPhi*a0[1]+CosPhi*a1[1];
|
||||
m[1][2]=-SinPhi*a0[2]+CosPhi*a1[2];
|
||||
m[1][3]=-SinPhi*a0[3]+CosPhi*a1[3];
|
||||
Lib3dsFloat SinPhi,CosPhi;
|
||||
Lib3dsFloat a0[4],a1[4];
|
||||
|
||||
SinPhi=(Lib3dsFloat)sin(phi);
|
||||
CosPhi=(Lib3dsFloat)cos(phi);
|
||||
memcpy(a0,m[0],4*sizeof(Lib3dsFloat));
|
||||
memcpy(a1,m[1],4*sizeof(Lib3dsFloat));
|
||||
m[0][0]=CosPhi*a0[0]+SinPhi*a1[0];
|
||||
m[0][1]=CosPhi*a0[1]+SinPhi*a1[1];
|
||||
m[0][2]=CosPhi*a0[2]+SinPhi*a1[2];
|
||||
m[0][3]=CosPhi*a0[3]+SinPhi*a1[3];
|
||||
m[1][0]=-SinPhi*a0[0]+CosPhi*a1[0];
|
||||
m[1][1]=-SinPhi*a0[1]+CosPhi*a1[1];
|
||||
m[1][2]=-SinPhi*a0[2]+CosPhi*a1[2];
|
||||
m[1][3]=-SinPhi*a0[3]+CosPhi*a1[3];
|
||||
}
|
||||
|
||||
|
||||
@@ -569,39 +534,37 @@ lib3ds_matrix_rotate_z(Lib3dsMatrix m, Lib3dsFloat phi)
|
||||
void
|
||||
lib3ds_matrix_rotate(Lib3dsMatrix m, Lib3dsQuat q)
|
||||
{
|
||||
Lib3dsFloat s,xs,ys,zs,wx,wy,wz,xx,xy,xz,yy,yz,zz,l;
|
||||
Lib3dsMatrix a,b;
|
||||
Lib3dsFloat s,xs,ys,zs,wx,wy,wz,xx,xy,xz,yy,yz,zz,l;
|
||||
Lib3dsMatrix a,b;
|
||||
|
||||
lib3ds_matrix_copy(a, m);
|
||||
lib3ds_matrix_copy(a, m);
|
||||
|
||||
l=q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3];
|
||||
if (fabs(l)<LIB3DS_EPSILON)
|
||||
{
|
||||
s=1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
s=2.0f/l;
|
||||
}
|
||||
l=q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3];
|
||||
if (fabs(l)<LIB3DS_EPSILON) {
|
||||
s=1.0f;
|
||||
}
|
||||
else {
|
||||
s=2.0f/l;
|
||||
}
|
||||
|
||||
xs = q[0] * s; ys = q[1] * s; zs = q[2] * s;
|
||||
wx = q[3] * xs; wy = q[3] * ys; wz = q[3] * zs;
|
||||
xx = q[0] * xs; xy = q[0] * ys; xz = q[0] * zs;
|
||||
yy = q[1] * ys; yz = q[1] * zs; zz = q[2] * zs;
|
||||
xs = q[0] * s; ys = q[1] * s; zs = q[2] * s;
|
||||
wx = q[3] * xs; wy = q[3] * ys; wz = q[3] * zs;
|
||||
xx = q[0] * xs; xy = q[0] * ys; xz = q[0] * zs;
|
||||
yy = q[1] * ys; yz = q[1] * zs; zz = q[2] * zs;
|
||||
|
||||
b[0][0]=1.0f - (yy +zz);
|
||||
b[1][0]=xy - wz;
|
||||
b[2][0]=xz + wy;
|
||||
b[0][1]=xy + wz;
|
||||
b[1][1]=1.0f - (xx +zz);
|
||||
b[2][1]=yz - wx;
|
||||
b[0][2]=xz - wy;
|
||||
b[1][2]=yz + wx;
|
||||
b[2][2]=1.0f - (xx + yy);
|
||||
b[3][0]=b[3][1]=b[3][2]=b[0][3]=b[1][3]=b[2][3]=0.0f;
|
||||
b[3][3]=1.0f;
|
||||
b[0][0]=1.0f - (yy +zz);
|
||||
b[1][0]=xy - wz;
|
||||
b[2][0]=xz + wy;
|
||||
b[0][1]=xy + wz;
|
||||
b[1][1]=1.0f - (xx +zz);
|
||||
b[2][1]=yz - wx;
|
||||
b[0][2]=xz - wy;
|
||||
b[1][2]=yz + wx;
|
||||
b[2][2]=1.0f - (xx + yy);
|
||||
b[3][0]=b[3][1]=b[3][2]=b[0][3]=b[1][3]=b[2][3]=0.0f;
|
||||
b[3][3]=1.0f;
|
||||
|
||||
lib3ds_matrix_mul(m,a,b);
|
||||
lib3ds_matrix_mul(m,a,b);
|
||||
}
|
||||
|
||||
|
||||
@@ -611,10 +574,10 @@ lib3ds_matrix_rotate(Lib3dsMatrix m, Lib3dsQuat q)
|
||||
void
|
||||
lib3ds_matrix_rotate_axis(Lib3dsMatrix m, Lib3dsVector axis, Lib3dsFloat angle)
|
||||
{
|
||||
Lib3dsQuat q;
|
||||
|
||||
lib3ds_quat_axis_angle(q,axis,angle);
|
||||
lib3ds_matrix_rotate(m,q);
|
||||
Lib3dsQuat q;
|
||||
|
||||
lib3ds_quat_axis_angle(q,axis,angle);
|
||||
lib3ds_matrix_rotate(m,q);
|
||||
}
|
||||
|
||||
|
||||
@@ -623,38 +586,38 @@ lib3ds_matrix_rotate_axis(Lib3dsMatrix m, Lib3dsVector axis, Lib3dsFloat angle)
|
||||
*/
|
||||
void
|
||||
lib3ds_matrix_camera(Lib3dsMatrix matrix, Lib3dsVector pos,
|
||||
Lib3dsVector tgt, Lib3dsFloat roll)
|
||||
Lib3dsVector tgt, Lib3dsFloat roll)
|
||||
{
|
||||
Lib3dsMatrix M,R;
|
||||
Lib3dsVector x, y, z;
|
||||
Lib3dsMatrix M,R;
|
||||
Lib3dsVector x, y, z;
|
||||
|
||||
lib3ds_vector_sub(y, tgt, pos);
|
||||
lib3ds_vector_normalize(y);
|
||||
lib3ds_vector_sub(y, tgt, pos);
|
||||
lib3ds_vector_normalize(y);
|
||||
|
||||
z[0] = 0;
|
||||
z[1] = 0;
|
||||
z[2] = 1.0;
|
||||
|
||||
lib3ds_vector_cross(x, y, z);
|
||||
lib3ds_vector_cross(z, x, y);
|
||||
lib3ds_vector_normalize(x);
|
||||
lib3ds_vector_normalize(y);
|
||||
|
||||
z[0] = 0;
|
||||
z[1] = 0;
|
||||
z[2] = 1.0;
|
||||
lib3ds_matrix_identity(M);
|
||||
M[0][0] = x[0];
|
||||
M[1][0] = x[1];
|
||||
M[2][0] = x[2];
|
||||
M[0][1] = y[0];
|
||||
M[1][1] = y[1];
|
||||
M[2][1] = y[2];
|
||||
M[0][2] = z[0];
|
||||
M[1][2] = z[1];
|
||||
M[2][2] = z[2];
|
||||
|
||||
lib3ds_vector_cross(x, y, z);
|
||||
lib3ds_vector_cross(z, x, y);
|
||||
lib3ds_vector_normalize(x);
|
||||
lib3ds_vector_normalize(y);
|
||||
|
||||
lib3ds_matrix_identity(M);
|
||||
M[0][0] = x[0];
|
||||
M[1][0] = x[1];
|
||||
M[2][0] = x[2];
|
||||
M[0][1] = y[0];
|
||||
M[1][1] = y[1];
|
||||
M[2][1] = y[2];
|
||||
M[0][2] = z[0];
|
||||
M[1][2] = z[1];
|
||||
M[2][2] = z[2];
|
||||
|
||||
lib3ds_matrix_identity(R);
|
||||
lib3ds_matrix_rotate_y(R, roll);
|
||||
lib3ds_matrix_mul(matrix, R,M);
|
||||
lib3ds_matrix_translate_xyz(matrix, -pos[0],-pos[1],-pos[2]);
|
||||
lib3ds_matrix_identity(R);
|
||||
lib3ds_matrix_rotate_y(R, roll);
|
||||
lib3ds_matrix_mul(matrix, R,M);
|
||||
lib3ds_matrix_translate_xyz(matrix, -pos[0],-pos[1],-pos[2]);
|
||||
}
|
||||
|
||||
|
||||
@@ -664,14 +627,17 @@ Lib3dsVector tgt, Lib3dsFloat roll)
|
||||
void
|
||||
lib3ds_matrix_dump(Lib3dsMatrix matrix)
|
||||
{
|
||||
int i,j;
|
||||
int i,j;
|
||||
|
||||
for (i=0; i<4; ++i)
|
||||
{
|
||||
for (j=0; j<4; ++j)
|
||||
{
|
||||
printf("%f ", matrix[j][i]);
|
||||
}
|
||||
printf("%f\n", matrix[j][i]);
|
||||
for (i=0; i<4; ++i) {
|
||||
for (j=0; j<4; ++j) {
|
||||
printf("%f ", matrix[j][i]);
|
||||
}
|
||||
printf("%f\n", matrix[j][i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -65,11 +65,23 @@ struct _Lib3dsBoxMap {
|
||||
char bottom[64];
|
||||
};
|
||||
|
||||
/*!
|
||||
* Lib3dsMapData maptype
|
||||
* \ingroup tracks
|
||||
*/
|
||||
typedef enum {
|
||||
LIB3DS_MAP_NONE =0xFFFF,
|
||||
LIB3DS_MAP_PLANAR =0,
|
||||
LIB3DS_MAP_CYLINDRICAL =1,
|
||||
LIB3DS_MAP_SPHERICAL =2
|
||||
} Lib3dsMapType;
|
||||
|
||||
/*!
|
||||
* Triangular mesh texture mapping data
|
||||
* \ingroup mesh
|
||||
*/
|
||||
struct _Lib3dsMapData {
|
||||
Lib3dsWord maptype;
|
||||
Lib3dsVector pos;
|
||||
Lib3dsMatrix matrix;
|
||||
Lib3dsFloat scale;
|
||||
@@ -111,6 +123,7 @@ extern LIB3DSAPI void lib3ds_mesh_free_texel_list(Lib3dsMesh *mesh);
|
||||
extern LIB3DSAPI Lib3dsBool lib3ds_mesh_new_face_list(Lib3dsMesh *mesh, Lib3dsDword flags);
|
||||
extern LIB3DSAPI void lib3ds_mesh_free_face_list(Lib3dsMesh *mesh);
|
||||
extern LIB3DSAPI void lib3ds_mesh_bounding_box(Lib3dsMesh *mesh, Lib3dsVector min, Lib3dsVector max);
|
||||
extern LIB3DSAPI void lib3ds_mesh_calculate_normals(Lib3dsMesh *mesh, Lib3dsVector *normalL);
|
||||
extern LIB3DSAPI void lib3ds_mesh_dump(Lib3dsMesh *mesh);
|
||||
extern LIB3DSAPI Lib3dsBool lib3ds_mesh_read(Lib3dsMesh *mesh, FILE *f);
|
||||
extern LIB3DSAPI Lib3dsBool lib3ds_mesh_write(Lib3dsMesh *mesh, FILE *f);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -138,7 +138,7 @@ struct _Lib3dsNode {
|
||||
Lib3dsNode *childs;\
|
||||
Lib3dsNode *parent;\
|
||||
Lib3dsNodeTypes type;\
|
||||
Lib3dsWord id;\
|
||||
Lib3dsWord node_id;\
|
||||
char name[64];\
|
||||
Lib3dsWord flags1;\
|
||||
Lib3dsWord flags2;\
|
||||
@@ -157,7 +157,7 @@ extern LIB3DSAPI void lib3ds_node_free(Lib3dsNode *node);
|
||||
extern LIB3DSAPI void lib3ds_node_eval(Lib3dsNode *node, Lib3dsFloat t);
|
||||
extern LIB3DSAPI Lib3dsNode* lib3ds_node_by_name(Lib3dsNode *node, const char* name,
|
||||
Lib3dsNodeTypes type);
|
||||
extern LIB3DSAPI Lib3dsNode* lib3ds_node_by_id(Lib3dsNode *node, Lib3dsWord id);
|
||||
extern LIB3DSAPI Lib3dsNode* lib3ds_node_by_id(Lib3dsNode *node, Lib3dsWord node_id);
|
||||
extern LIB3DSAPI void lib3ds_node_dump(Lib3dsNode *node, Lib3dsIntd level);
|
||||
extern LIB3DSAPI Lib3dsBool lib3ds_node_read(Lib3dsNode *node, Lib3dsFile *file, FILE *f);
|
||||
extern LIB3DSAPI Lib3dsBool lib3ds_node_write(Lib3dsNode *node, Lib3dsFile *file, FILE *f);
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <quat.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \defgroup quat Quaternion Mathematics
|
||||
*
|
||||
@@ -33,13 +34,14 @@
|
||||
* \ingroup quat
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup quat
|
||||
*/
|
||||
void
|
||||
lib3ds_quat_zero(Lib3dsQuat c)
|
||||
{
|
||||
c[0]=c[1]=c[2]=c[3]=0.0f;
|
||||
c[0]=c[1]=c[2]=c[3]=0.0f;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,22 +51,21 @@ lib3ds_quat_zero(Lib3dsQuat c)
|
||||
void
|
||||
lib3ds_quat_identity(Lib3dsQuat c)
|
||||
{
|
||||
c[0]=c[1]=c[2]=0.0f;
|
||||
c[3]=1.0f;
|
||||
c[0]=c[1]=c[2]=0.0f;
|
||||
c[3]=1.0f;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup quat
|
||||
*/
|
||||
void
|
||||
void
|
||||
lib3ds_quat_copy(Lib3dsQuat dest, Lib3dsQuat src)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<4; ++i)
|
||||
{
|
||||
dest[i]=src[i];
|
||||
}
|
||||
int i;
|
||||
for (i=0; i<4; ++i) {
|
||||
dest[i]=src[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,24 +75,22 @@ lib3ds_quat_copy(Lib3dsQuat dest, Lib3dsQuat src)
|
||||
void
|
||||
lib3ds_quat_axis_angle(Lib3dsQuat c, Lib3dsVector axis, Lib3dsFloat angle)
|
||||
{
|
||||
Lib3dsDouble omega,s;
|
||||
Lib3dsDouble l;
|
||||
Lib3dsDouble omega,s;
|
||||
Lib3dsDouble l;
|
||||
|
||||
l=sqrt(axis[0]*axis[0] + axis[1]*axis[1] + axis[2]*axis[2]);
|
||||
if (l<LIB3DS_EPSILON)
|
||||
{
|
||||
c[0]=c[1]=c[2]=0.0f;
|
||||
c[3]=1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
omega=-0.5*angle;
|
||||
s=sin(omega)/l;
|
||||
c[0]=(Lib3dsFloat)s*axis[0];
|
||||
c[1]=(Lib3dsFloat)s*axis[1];
|
||||
c[2]=(Lib3dsFloat)s*axis[2];
|
||||
c[3]=(Lib3dsFloat)cos(omega);
|
||||
}
|
||||
l=sqrt(axis[0]*axis[0] + axis[1]*axis[1] + axis[2]*axis[2]);
|
||||
if (l<LIB3DS_EPSILON) {
|
||||
c[0]=c[1]=c[2]=0.0f;
|
||||
c[3]=1.0f;
|
||||
}
|
||||
else {
|
||||
omega=-0.5*angle;
|
||||
s=sin(omega)/l;
|
||||
c[0]=(Lib3dsFloat)s*axis[0];
|
||||
c[1]=(Lib3dsFloat)s*axis[1];
|
||||
c[2]=(Lib3dsFloat)s*axis[2];
|
||||
c[3]=(Lib3dsFloat)cos(omega);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,11 +100,10 @@ lib3ds_quat_axis_angle(Lib3dsQuat c, Lib3dsVector axis, Lib3dsFloat angle)
|
||||
void
|
||||
lib3ds_quat_neg(Lib3dsQuat c)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<4; ++i)
|
||||
{
|
||||
c[i]=-c[i];
|
||||
}
|
||||
int i;
|
||||
for (i=0; i<4; ++i) {
|
||||
c[i]=-c[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -115,11 +113,10 @@ lib3ds_quat_neg(Lib3dsQuat c)
|
||||
void
|
||||
lib3ds_quat_abs(Lib3dsQuat c)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<4; ++i)
|
||||
{
|
||||
c[i]=(Lib3dsFloat)fabs(c[i]);
|
||||
}
|
||||
int i;
|
||||
for (i=0; i<4; ++i) {
|
||||
c[i]=(Lib3dsFloat)fabs(c[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,11 +126,10 @@ lib3ds_quat_abs(Lib3dsQuat c)
|
||||
void
|
||||
lib3ds_quat_cnj(Lib3dsQuat c)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
c[i]=-c[i];
|
||||
}
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
c[i]=-c[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -143,10 +139,10 @@ lib3ds_quat_cnj(Lib3dsQuat c)
|
||||
void
|
||||
lib3ds_quat_mul(Lib3dsQuat c, Lib3dsQuat a, Lib3dsQuat b)
|
||||
{
|
||||
c[0]=a[3]*b[0] + a[0]*b[3] + a[1]*b[2] - a[2]*b[1];
|
||||
c[1]=a[3]*b[1] + a[1]*b[3] + a[2]*b[0] - a[0]*b[2];
|
||||
c[2]=a[3]*b[2] + a[2]*b[3] + a[0]*b[1] - a[1]*b[0];
|
||||
c[3]=a[3]*b[3] - a[0]*b[0] - a[1]*b[1] - a[2]*b[2];
|
||||
c[0]=a[3]*b[0] + a[0]*b[3] + a[1]*b[2] - a[2]*b[1];
|
||||
c[1]=a[3]*b[1] + a[1]*b[3] + a[2]*b[0] - a[0]*b[2];
|
||||
c[2]=a[3]*b[2] + a[2]*b[3] + a[0]*b[1] - a[1]*b[0];
|
||||
c[3]=a[3]*b[3] - a[0]*b[0] - a[1]*b[1] - a[2]*b[2];
|
||||
}
|
||||
|
||||
|
||||
@@ -156,11 +152,10 @@ lib3ds_quat_mul(Lib3dsQuat c, Lib3dsQuat a, Lib3dsQuat b)
|
||||
void
|
||||
lib3ds_quat_scalar(Lib3dsQuat c, Lib3dsFloat k)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<4; ++i)
|
||||
{
|
||||
c[i]*=k;
|
||||
}
|
||||
int i;
|
||||
for (i=0; i<4; ++i) {
|
||||
c[i]*=k;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,23 +165,20 @@ lib3ds_quat_scalar(Lib3dsQuat c, Lib3dsFloat k)
|
||||
void
|
||||
lib3ds_quat_normalize(Lib3dsQuat c)
|
||||
{
|
||||
Lib3dsDouble l,m;
|
||||
Lib3dsDouble l,m;
|
||||
|
||||
l=sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2] + c[3]*c[3]);
|
||||
if (fabs(l)<LIB3DS_EPSILON)
|
||||
{
|
||||
c[0]=c[1]=c[2]=0.0f;
|
||||
c[3]=1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
m=1.0f/l;
|
||||
for (i=0; i<4; ++i)
|
||||
{
|
||||
c[i]=(Lib3dsFloat)(c[i]*m);
|
||||
}
|
||||
l=sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2] + c[3]*c[3]);
|
||||
if (fabs(l)<LIB3DS_EPSILON) {
|
||||
c[0]=c[1]=c[2]=0.0f;
|
||||
c[3]=1.0f;
|
||||
}
|
||||
else {
|
||||
int i;
|
||||
m=1.0f/l;
|
||||
for (i=0; i<4; ++i) {
|
||||
c[i]=(Lib3dsFloat)(c[i]*m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -196,22 +188,20 @@ lib3ds_quat_normalize(Lib3dsQuat c)
|
||||
void
|
||||
lib3ds_quat_inv(Lib3dsQuat c)
|
||||
{
|
||||
Lib3dsDouble l,m;
|
||||
Lib3dsDouble l,m;
|
||||
|
||||
l=sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2] + c[3]*c[3]);
|
||||
if (fabs(l)<LIB3DS_EPSILON)
|
||||
{
|
||||
c[0]=c[1]=c[2]=0.0f;
|
||||
c[3]=1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
m=1.0f/l;
|
||||
c[0]=(Lib3dsFloat)(-c[0]*m);
|
||||
c[1]=(Lib3dsFloat)(-c[1]*m);
|
||||
c[2]=(Lib3dsFloat)(-c[2]*m);
|
||||
c[3]=(Lib3dsFloat)(c[3]*m);
|
||||
}
|
||||
l=sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2] + c[3]*c[3]);
|
||||
if (fabs(l)<LIB3DS_EPSILON) {
|
||||
c[0]=c[1]=c[2]=0.0f;
|
||||
c[3]=1.0f;
|
||||
}
|
||||
else {
|
||||
m=1.0f/l;
|
||||
c[0]=(Lib3dsFloat)(-c[0]*m);
|
||||
c[1]=(Lib3dsFloat)(-c[1]*m);
|
||||
c[2]=(Lib3dsFloat)(-c[2]*m);
|
||||
c[3]=(Lib3dsFloat)(c[3]*m);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -221,7 +211,7 @@ lib3ds_quat_inv(Lib3dsQuat c)
|
||||
Lib3dsFloat
|
||||
lib3ds_quat_dot(Lib3dsQuat a, Lib3dsQuat b)
|
||||
{
|
||||
return(a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3]);
|
||||
return(a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3]);
|
||||
}
|
||||
|
||||
|
||||
@@ -231,7 +221,7 @@ lib3ds_quat_dot(Lib3dsQuat a, Lib3dsQuat b)
|
||||
Lib3dsFloat
|
||||
lib3ds_quat_squared(Lib3dsQuat c)
|
||||
{
|
||||
return(c[0]*c[0] + c[1]*c[1] + c[2]*c[2] + c[3]*c[3]);
|
||||
return(c[0]*c[0] + c[1]*c[1] + c[2]*c[2] + c[3]*c[3]);
|
||||
}
|
||||
|
||||
|
||||
@@ -241,7 +231,7 @@ lib3ds_quat_squared(Lib3dsQuat c)
|
||||
Lib3dsFloat
|
||||
lib3ds_quat_length(Lib3dsQuat c)
|
||||
{
|
||||
return((Lib3dsFloat)sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2] + c[3]*c[3]));
|
||||
return((Lib3dsFloat)sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2] + c[3]*c[3]));
|
||||
}
|
||||
|
||||
|
||||
@@ -251,26 +241,23 @@ lib3ds_quat_length(Lib3dsQuat c)
|
||||
void
|
||||
lib3ds_quat_ln(Lib3dsQuat c)
|
||||
{
|
||||
Lib3dsDouble om,s,t;
|
||||
Lib3dsDouble om,s,t;
|
||||
|
||||
s=sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2]);
|
||||
om=atan2(s,(double)c[3]);
|
||||
if (fabs(s)<LIB3DS_EPSILON)
|
||||
{
|
||||
t=0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
t=om/s;
|
||||
}
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
c[i]=(Lib3dsFloat)(c[i]*t);
|
||||
}
|
||||
c[3]=0.0f;
|
||||
s=sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2]);
|
||||
om=atan2(s,c[3]);
|
||||
if (fabs(s)<LIB3DS_EPSILON) {
|
||||
t=0.0f;
|
||||
}
|
||||
else {
|
||||
t=om/s;
|
||||
}
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
c[i]=(Lib3dsFloat)(c[i]*t);
|
||||
}
|
||||
c[3]=0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -280,12 +267,12 @@ lib3ds_quat_ln(Lib3dsQuat c)
|
||||
void
|
||||
lib3ds_quat_ln_dif(Lib3dsQuat c, Lib3dsQuat a, Lib3dsQuat b)
|
||||
{
|
||||
Lib3dsQuat invp;
|
||||
Lib3dsQuat invp;
|
||||
|
||||
lib3ds_quat_copy(invp, a);
|
||||
lib3ds_quat_inv(invp);
|
||||
lib3ds_quat_mul(c, invp, b);
|
||||
lib3ds_quat_ln(c);
|
||||
lib3ds_quat_copy(invp, a);
|
||||
lib3ds_quat_inv(invp);
|
||||
lib3ds_quat_mul(c, invp, b);
|
||||
lib3ds_quat_ln(c);
|
||||
}
|
||||
|
||||
|
||||
@@ -295,25 +282,22 @@ lib3ds_quat_ln_dif(Lib3dsQuat c, Lib3dsQuat a, Lib3dsQuat b)
|
||||
void
|
||||
lib3ds_quat_exp(Lib3dsQuat c)
|
||||
{
|
||||
Lib3dsDouble om,sinom;
|
||||
Lib3dsDouble om,sinom;
|
||||
|
||||
om=sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2]);
|
||||
if (fabs(om)<LIB3DS_EPSILON)
|
||||
{
|
||||
sinom=1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
sinom=sin(om)/om;
|
||||
}
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
c[i]=(Lib3dsFloat)(c[i]*sinom);
|
||||
}
|
||||
c[3]=(Lib3dsFloat)cos(om);
|
||||
om=sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2]);
|
||||
if (fabs(om)<LIB3DS_EPSILON) {
|
||||
sinom=1.0f;
|
||||
}
|
||||
else {
|
||||
sinom=sin(om)/om;
|
||||
}
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
c[i]=(Lib3dsFloat)(c[i]*sinom);
|
||||
}
|
||||
c[3]=(Lib3dsFloat)cos(om);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -323,45 +307,41 @@ lib3ds_quat_exp(Lib3dsQuat c)
|
||||
void
|
||||
lib3ds_quat_slerp(Lib3dsQuat c, Lib3dsQuat a, Lib3dsQuat b, Lib3dsFloat t)
|
||||
{
|
||||
Lib3dsDouble l;
|
||||
Lib3dsDouble om,sinom;
|
||||
Lib3dsDouble sp,sq;
|
||||
Lib3dsQuat q;
|
||||
Lib3dsDouble l;
|
||||
Lib3dsDouble om,sinom;
|
||||
Lib3dsDouble sp,sq;
|
||||
Lib3dsQuat q;
|
||||
|
||||
l=a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3];
|
||||
if ((1.0+l)>LIB3DS_EPSILON)
|
||||
{
|
||||
if (fabs(l)>1.0f) l/=fabs(l);
|
||||
om=acos(l);
|
||||
sinom=sin(om);
|
||||
if (fabs(sinom)>LIB3DS_EPSILON)
|
||||
{
|
||||
sp=sin((1.0f-t)*om)/sinom;
|
||||
sq=sin(t*om)/sinom;
|
||||
}
|
||||
else
|
||||
{
|
||||
sp=1.0f-t;
|
||||
sq=t;
|
||||
}
|
||||
c[0]=(Lib3dsFloat)(sp*a[0] + sq*b[0]);
|
||||
c[1]=(Lib3dsFloat)(sp*a[1] + sq*b[1]);
|
||||
c[2]=(Lib3dsFloat)(sp*a[2] + sq*b[2]);
|
||||
c[3]=(Lib3dsFloat)(sp*a[3] + sq*b[3]);
|
||||
l=a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3];
|
||||
if ((1.0+l)>LIB3DS_EPSILON) {
|
||||
if (fabs(l)>1.0f) l/=fabs(l);
|
||||
om=acos(l);
|
||||
sinom=sin(om);
|
||||
if (fabs(sinom)>LIB3DS_EPSILON) {
|
||||
sp=sin((1.0f-t)*om)/sinom;
|
||||
sq=sin(t*om)/sinom;
|
||||
}
|
||||
else
|
||||
{
|
||||
q[0]=-a[1];
|
||||
q[1]=a[0];
|
||||
q[2]=-a[3];
|
||||
q[3]=a[2];
|
||||
sp=sin((1.0-t)*LIB3DS_HALFPI);
|
||||
sq=sin(t*LIB3DS_HALFPI);
|
||||
c[0]=(Lib3dsFloat)(sp*a[0] + sq*q[0]);
|
||||
c[1]=(Lib3dsFloat)(sp*a[1] + sq*q[1]);
|
||||
c[2]=(Lib3dsFloat)(sp*a[2] + sq*q[2]);
|
||||
c[3]=(Lib3dsFloat)(sp*a[3] + sq*q[3]);
|
||||
else {
|
||||
sp=1.0f-t;
|
||||
sq=t;
|
||||
}
|
||||
c[0]=(Lib3dsFloat)(sp*a[0] + sq*b[0]);
|
||||
c[1]=(Lib3dsFloat)(sp*a[1] + sq*b[1]);
|
||||
c[2]=(Lib3dsFloat)(sp*a[2] + sq*b[2]);
|
||||
c[3]=(Lib3dsFloat)(sp*a[3] + sq*b[3]);
|
||||
}
|
||||
else {
|
||||
q[0]=-a[1];
|
||||
q[1]=a[0];
|
||||
q[2]=-a[3];
|
||||
q[3]=a[2];
|
||||
sp=sin((1.0-t)*LIB3DS_HALFPI);
|
||||
sq=sin(t*LIB3DS_HALFPI);
|
||||
c[0]=(Lib3dsFloat)(sp*a[0] + sq*q[0]);
|
||||
c[1]=(Lib3dsFloat)(sp*a[1] + sq*q[1]);
|
||||
c[2]=(Lib3dsFloat)(sp*a[2] + sq*q[2]);
|
||||
c[3]=(Lib3dsFloat)(sp*a[3] + sq*q[3]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -370,14 +350,14 @@ lib3ds_quat_slerp(Lib3dsQuat c, Lib3dsQuat a, Lib3dsQuat b, Lib3dsFloat t)
|
||||
*/
|
||||
void
|
||||
lib3ds_quat_squad(Lib3dsQuat c, Lib3dsQuat a, Lib3dsQuat p, Lib3dsQuat q,
|
||||
Lib3dsQuat b, Lib3dsFloat t)
|
||||
Lib3dsQuat b, Lib3dsFloat t)
|
||||
{
|
||||
Lib3dsQuat ab;
|
||||
Lib3dsQuat pq;
|
||||
Lib3dsQuat ab;
|
||||
Lib3dsQuat pq;
|
||||
|
||||
lib3ds_quat_slerp(ab,a,b,t);
|
||||
lib3ds_quat_slerp(pq,p,q,t);
|
||||
lib3ds_quat_slerp(c,ab,pq,2*t*(1-t));
|
||||
lib3ds_quat_slerp(ab,a,b,t);
|
||||
lib3ds_quat_slerp(pq,p,q,t);
|
||||
lib3ds_quat_slerp(c,ab,pq,2*t*(1-t));
|
||||
}
|
||||
|
||||
|
||||
@@ -387,18 +367,17 @@ Lib3dsQuat b, Lib3dsFloat t)
|
||||
void
|
||||
lib3ds_quat_tangent(Lib3dsQuat c, Lib3dsQuat p, Lib3dsQuat q, Lib3dsQuat n)
|
||||
{
|
||||
Lib3dsQuat dn,dp,x;
|
||||
int i;
|
||||
Lib3dsQuat dn,dp,x;
|
||||
int i;
|
||||
|
||||
lib3ds_quat_ln_dif(dn, q, n);
|
||||
lib3ds_quat_ln_dif(dp, q, p);
|
||||
lib3ds_quat_ln_dif(dn, q, n);
|
||||
lib3ds_quat_ln_dif(dp, q, p);
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
x[i]=-1.0f/4.0f*(dn[i]+dp[i]);
|
||||
}
|
||||
lib3ds_quat_exp(x);
|
||||
lib3ds_quat_mul(c,q,x);
|
||||
for (i=0; i<4; i++) {
|
||||
x[i]=-1.0f/4.0f*(dn[i]+dp[i]);
|
||||
}
|
||||
lib3ds_quat_exp(x);
|
||||
lib3ds_quat_mul(c,q,x);
|
||||
}
|
||||
|
||||
|
||||
@@ -408,5 +387,6 @@ lib3ds_quat_tangent(Lib3dsQuat c, Lib3dsQuat p, Lib3dsQuat q, Lib3dsQuat n)
|
||||
void
|
||||
lib3ds_quat_dump(Lib3dsQuat q)
|
||||
{
|
||||
printf("%f %f %f %f\n", q[0], q[1], q[2], q[3]);
|
||||
printf("%f %f %f %f\n", q[0], q[1], q[2], q[3]);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
@@ -22,168 +22,170 @@
|
||||
#define LIB3DS_EXPORT
|
||||
#include <readwrite.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \defgroup readwrite Portable Binary Input/Ouput
|
||||
*
|
||||
* \author J.E. Hoffmann <je-h@gmx.net>
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup readwrite
|
||||
*
|
||||
* Read a byte from a file stream.
|
||||
* Read a byte from a file stream.
|
||||
*
|
||||
* \param f Input file stream.
|
||||
* \param f Input file stream.
|
||||
*
|
||||
* \return The byte read.
|
||||
* \return The byte read.
|
||||
*/
|
||||
Lib3dsByte
|
||||
lib3ds_byte_read(FILE *f)
|
||||
{
|
||||
Lib3dsByte b;
|
||||
Lib3dsByte b;
|
||||
|
||||
ASSERT(f);
|
||||
fread(&b,1,1,f);
|
||||
return(b);
|
||||
ASSERT(f);
|
||||
fread(&b,1,1,f);
|
||||
return(b);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read a word from a file stream in little endian format.
|
||||
* Read a word from a file stream in little endian format.
|
||||
*
|
||||
* \param f Input file stream.
|
||||
* \param f Input file stream.
|
||||
*
|
||||
* \return The word read.
|
||||
* \return The word read.
|
||||
*/
|
||||
Lib3dsWord
|
||||
lib3ds_word_read(FILE *f)
|
||||
{
|
||||
Lib3dsByte b[2];
|
||||
Lib3dsWord w;
|
||||
Lib3dsByte b[2];
|
||||
Lib3dsWord w;
|
||||
|
||||
ASSERT(f);
|
||||
fread(b,2,1,f);
|
||||
w=((Lib3dsWord)b[1] << 8) |
|
||||
((Lib3dsWord)b[0]);
|
||||
return(w);
|
||||
ASSERT(f);
|
||||
fread(b,2,1,f);
|
||||
w=((Lib3dsWord)b[1] << 8) |
|
||||
((Lib3dsWord)b[0]);
|
||||
return(w);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup readwrite
|
||||
*
|
||||
* Read a dword from file a stream in little endian format.
|
||||
* Read a dword from file a stream in little endian format.
|
||||
*
|
||||
* \param f Input file stream.
|
||||
* \param f Input file stream.
|
||||
*
|
||||
* \return The dword read.
|
||||
* \return The dword read.
|
||||
*/
|
||||
Lib3dsDword
|
||||
lib3ds_dword_read(FILE *f)
|
||||
{
|
||||
Lib3dsByte b[4];
|
||||
Lib3dsDword d;
|
||||
|
||||
ASSERT(f);
|
||||
fread(b,4,1,f);
|
||||
d=((Lib3dsDword)b[3] << 24) |
|
||||
((Lib3dsDword)b[2] << 16) |
|
||||
((Lib3dsDword)b[1] << 8) |
|
||||
((Lib3dsDword)b[0]);
|
||||
return(d);
|
||||
Lib3dsByte b[4];
|
||||
Lib3dsDword d;
|
||||
|
||||
ASSERT(f);
|
||||
fread(b,4,1,f);
|
||||
d=((Lib3dsDword)b[3] << 24) |
|
||||
((Lib3dsDword)b[2] << 16) |
|
||||
((Lib3dsDword)b[1] << 8) |
|
||||
((Lib3dsDword)b[0]);
|
||||
return(d);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup readwrite
|
||||
*
|
||||
* Read a signed byte from a file stream.
|
||||
* Read a signed byte from a file stream.
|
||||
*
|
||||
* \param f Input file stream.
|
||||
* \param f Input file stream.
|
||||
*
|
||||
* \return The signed byte read.
|
||||
* \return The signed byte read.
|
||||
*/
|
||||
Lib3dsIntb
|
||||
lib3ds_intb_read(FILE *f)
|
||||
{
|
||||
Lib3dsIntb b;
|
||||
Lib3dsIntb b;
|
||||
|
||||
ASSERT(f);
|
||||
fread(&b,1,1,f);
|
||||
return(b);
|
||||
ASSERT(f);
|
||||
fread(&b,1,1,f);
|
||||
return(b);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup readwrite
|
||||
*
|
||||
* Read a signed word from a file stream in little endian format.
|
||||
* Read a signed word from a file stream in little endian format.
|
||||
*
|
||||
* \param f Input file stream.
|
||||
* \param f Input file stream.
|
||||
*
|
||||
* \return The signed word read.
|
||||
* \return The signed word read.
|
||||
*/
|
||||
Lib3dsIntw
|
||||
lib3ds_intw_read(FILE *f)
|
||||
{
|
||||
Lib3dsByte b[2];
|
||||
Lib3dsWord w;
|
||||
Lib3dsByte b[2];
|
||||
Lib3dsWord w;
|
||||
|
||||
ASSERT(f);
|
||||
fread(b,2,1,f);
|
||||
w=((Lib3dsWord)b[1] << 8) |
|
||||
((Lib3dsWord)b[0]);
|
||||
return((Lib3dsIntw)w);
|
||||
ASSERT(f);
|
||||
fread(b,2,1,f);
|
||||
w=((Lib3dsWord)b[1] << 8) |
|
||||
((Lib3dsWord)b[0]);
|
||||
return((Lib3dsIntw)w);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup readwrite
|
||||
*
|
||||
* Read a signed dword a from file stream in little endian format.
|
||||
* Read a signed dword a from file stream in little endian format.
|
||||
*
|
||||
* \param f Input file stream.
|
||||
* \param f Input file stream.
|
||||
*
|
||||
* \return The signed dword read.
|
||||
* \return The signed dword read.
|
||||
*/
|
||||
Lib3dsIntd
|
||||
lib3ds_intd_read(FILE *f)
|
||||
{
|
||||
Lib3dsByte b[4];
|
||||
Lib3dsDword d;
|
||||
|
||||
ASSERT(f);
|
||||
fread(b,4,1,f);
|
||||
d=((Lib3dsDword)b[3] << 24) |
|
||||
((Lib3dsDword)b[2] << 16) |
|
||||
((Lib3dsDword)b[1] << 8) |
|
||||
((Lib3dsDword)b[0]);
|
||||
return((Lib3dsIntd)d);
|
||||
Lib3dsByte b[4];
|
||||
Lib3dsDword d;
|
||||
|
||||
ASSERT(f);
|
||||
fread(b,4,1,f);
|
||||
d=((Lib3dsDword)b[3] << 24) |
|
||||
((Lib3dsDword)b[2] << 16) |
|
||||
((Lib3dsDword)b[1] << 8) |
|
||||
((Lib3dsDword)b[0]);
|
||||
return((Lib3dsIntd)d);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup readwrite
|
||||
*
|
||||
* Read a float from a file stream in little endian format.
|
||||
* Read a float from a file stream in little endian format.
|
||||
*
|
||||
* \param f Input file stream.
|
||||
* \param f Input file stream.
|
||||
*
|
||||
* \return The float read.
|
||||
* \return The float read.
|
||||
*/
|
||||
Lib3dsFloat
|
||||
lib3ds_float_read(FILE *f)
|
||||
{
|
||||
Lib3dsByte b[4];
|
||||
Lib3dsDword d;
|
||||
Lib3dsByte b[4];
|
||||
Lib3dsDword d;
|
||||
|
||||
ASSERT(f);
|
||||
fread(b,4,1,f);
|
||||
d=((Lib3dsDword)b[3] << 24) |
|
||||
((Lib3dsDword)b[2] << 16) |
|
||||
((Lib3dsDword)b[1] << 8) |
|
||||
((Lib3dsDword)b[0]);
|
||||
return(*((Lib3dsFloat*)&d));
|
||||
ASSERT(f);
|
||||
fread(b,4,1,f);
|
||||
d=((Lib3dsDword)b[3] << 24) |
|
||||
((Lib3dsDword)b[2] << 16) |
|
||||
((Lib3dsDword)b[1] << 8) |
|
||||
((Lib3dsDword)b[0]);
|
||||
return(*((Lib3dsFloat*)&d));
|
||||
}
|
||||
|
||||
|
||||
@@ -191,25 +193,24 @@ lib3ds_float_read(FILE *f)
|
||||
* \ingroup readwrite
|
||||
* \ingroup vector
|
||||
*
|
||||
* Read a vector from a file stream in little endian format.
|
||||
* Read a vector from a file stream in little endian format.
|
||||
*
|
||||
* \param v The vector to store the data.
|
||||
* \param f Input file stream.
|
||||
* \param v The vector to store the data.
|
||||
* \param f Input file stream.
|
||||
*
|
||||
* \return The float read.
|
||||
* \return The float read.
|
||||
*/
|
||||
Lib3dsBool
|
||||
lib3ds_vector_read(Lib3dsVector v, FILE *f)
|
||||
{
|
||||
v[0]=lib3ds_float_read(f);
|
||||
v[1]=lib3ds_float_read(f);
|
||||
v[2]=lib3ds_float_read(f);
|
||||
v[0]=lib3ds_float_read(f);
|
||||
v[1]=lib3ds_float_read(f);
|
||||
v[2]=lib3ds_float_read(f);
|
||||
|
||||
if (ferror(f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
if (ferror(f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -219,15 +220,14 @@ lib3ds_vector_read(Lib3dsVector v, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_rgb_read(Lib3dsRgb rgb, FILE *f)
|
||||
{
|
||||
rgb[0]=lib3ds_float_read(f);
|
||||
rgb[1]=lib3ds_float_read(f);
|
||||
rgb[2]=lib3ds_float_read(f);
|
||||
rgb[0]=lib3ds_float_read(f);
|
||||
rgb[1]=lib3ds_float_read(f);
|
||||
rgb[2]=lib3ds_float_read(f);
|
||||
|
||||
if (ferror(f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
if (ferror(f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -245,20 +245,17 @@ lib3ds_rgb_read(Lib3dsRgb rgb, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_string_read(char *s, int buflen, FILE *f)
|
||||
{
|
||||
int k=0;
|
||||
ASSERT(f);
|
||||
while ((*s++=fgetc(f))!=0)
|
||||
{
|
||||
if (++k>buflen)
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
int k=0;
|
||||
ASSERT(f);
|
||||
while ((*s++=fgetc(f))!=0) {
|
||||
if (++k>=buflen) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (ferror(f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
if (ferror(f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -275,12 +272,11 @@ lib3ds_string_read(char *s, int buflen, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_byte_write(Lib3dsByte b, FILE *f)
|
||||
{
|
||||
ASSERT(f);
|
||||
if (fwrite(&b,1,1,f)!=1)
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
ASSERT(f);
|
||||
if (fwrite(&b,1,1,f)!=1) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -297,16 +293,15 @@ lib3ds_byte_write(Lib3dsByte b, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_word_write(Lib3dsWord w, FILE *f)
|
||||
{
|
||||
Lib3dsByte b[2];
|
||||
Lib3dsByte b[2];
|
||||
|
||||
ASSERT(f);
|
||||
b[1]=((Lib3dsWord)w & 0xFF00) >> 8;
|
||||
b[0]=((Lib3dsWord)w & 0x00FF);
|
||||
if (fwrite(b,2,1,f)!=1)
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
ASSERT(f);
|
||||
b[1]=((Lib3dsWord)w & 0xFF00) >> 8;
|
||||
b[0]=((Lib3dsWord)w & 0x00FF);
|
||||
if (fwrite(b,2,1,f)!=1) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -323,18 +318,17 @@ lib3ds_word_write(Lib3dsWord w, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_dword_write(Lib3dsDword d, FILE *f)
|
||||
{
|
||||
Lib3dsByte b[4];
|
||||
Lib3dsByte b[4];
|
||||
|
||||
ASSERT(f);
|
||||
b[3]=(Lib3dsByte)(((Lib3dsDword)d & 0xFF000000) >> 24);
|
||||
b[2]=(Lib3dsByte)(((Lib3dsDword)d & 0x00FF0000) >> 16);
|
||||
b[1]=(Lib3dsByte)(((Lib3dsDword)d & 0x0000FF00) >> 8);
|
||||
b[0]=(Lib3dsByte)(((Lib3dsDword)d & 0x000000FF));
|
||||
if (fwrite(b,4,1,f)!=1)
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
ASSERT(f);
|
||||
b[3]=(Lib3dsByte)(((Lib3dsDword)d & 0xFF000000) >> 24);
|
||||
b[2]=(Lib3dsByte)(((Lib3dsDword)d & 0x00FF0000) >> 16);
|
||||
b[1]=(Lib3dsByte)(((Lib3dsDword)d & 0x0000FF00) >> 8);
|
||||
b[0]=(Lib3dsByte)(((Lib3dsDword)d & 0x000000FF));
|
||||
if (fwrite(b,4,1,f)!=1) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -351,12 +345,11 @@ lib3ds_dword_write(Lib3dsDword d, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_intb_write(Lib3dsIntb b, FILE *f)
|
||||
{
|
||||
ASSERT(f);
|
||||
if (fwrite(&b,1,1,f)!=1)
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
ASSERT(f);
|
||||
if (fwrite(&b,1,1,f)!=1) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -373,16 +366,15 @@ lib3ds_intb_write(Lib3dsIntb b, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_intw_write(Lib3dsIntw w, FILE *f)
|
||||
{
|
||||
Lib3dsByte b[2];
|
||||
Lib3dsByte b[2];
|
||||
|
||||
ASSERT(f);
|
||||
b[1]=((Lib3dsWord)w & 0xFF00) >> 8;
|
||||
b[0]=((Lib3dsWord)w & 0x00FF);
|
||||
if (fwrite(b,2,1,f)!=1)
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
ASSERT(f);
|
||||
b[1]=((Lib3dsWord)w & 0xFF00) >> 8;
|
||||
b[0]=((Lib3dsWord)w & 0x00FF);
|
||||
if (fwrite(b,2,1,f)!=1) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -399,18 +391,17 @@ lib3ds_intw_write(Lib3dsIntw w, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_intd_write(Lib3dsIntd d, FILE *f)
|
||||
{
|
||||
Lib3dsByte b[4];
|
||||
Lib3dsByte b[4];
|
||||
|
||||
ASSERT(f);
|
||||
b[3]=(Lib3dsByte)(((Lib3dsDword)d & 0xFF000000) >> 24);
|
||||
b[2]=(Lib3dsByte)(((Lib3dsDword)d & 0x00FF0000) >> 16);
|
||||
b[1]=(Lib3dsByte)(((Lib3dsDword)d & 0x0000FF00) >> 8);
|
||||
b[0]=(Lib3dsByte)(((Lib3dsDword)d & 0x000000FF));
|
||||
if (fwrite(b,4,1,f)!=1)
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
ASSERT(f);
|
||||
b[3]=(Lib3dsByte)(((Lib3dsDword)d & 0xFF000000) >> 24);
|
||||
b[2]=(Lib3dsByte)(((Lib3dsDword)d & 0x00FF0000) >> 16);
|
||||
b[1]=(Lib3dsByte)(((Lib3dsDword)d & 0x0000FF00) >> 8);
|
||||
b[0]=(Lib3dsByte)(((Lib3dsDword)d & 0x000000FF));
|
||||
if (fwrite(b,4,1,f)!=1) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -427,20 +418,19 @@ lib3ds_intd_write(Lib3dsIntd d, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_float_write(Lib3dsFloat l, FILE *f)
|
||||
{
|
||||
Lib3dsByte b[4];
|
||||
Lib3dsDword d;
|
||||
Lib3dsByte b[4];
|
||||
Lib3dsDword d;
|
||||
|
||||
ASSERT(f);
|
||||
d=*((Lib3dsDword*)&l);
|
||||
b[3]=(Lib3dsByte)(((Lib3dsDword)d & 0xFF000000) >> 24);
|
||||
b[2]=(Lib3dsByte)(((Lib3dsDword)d & 0x00FF0000) >> 16);
|
||||
b[1]=(Lib3dsByte)(((Lib3dsDword)d & 0x0000FF00) >> 8);
|
||||
b[0]=(Lib3dsByte)(((Lib3dsDword)d & 0x000000FF));
|
||||
if (fwrite(b,4,1,f)!=1)
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
ASSERT(f);
|
||||
d=*((Lib3dsDword*)&l);
|
||||
b[3]=(Lib3dsByte)(((Lib3dsDword)d & 0xFF000000) >> 24);
|
||||
b[2]=(Lib3dsByte)(((Lib3dsDword)d & 0x00FF0000) >> 16);
|
||||
b[1]=(Lib3dsByte)(((Lib3dsDword)d & 0x0000FF00) >> 8);
|
||||
b[0]=(Lib3dsByte)(((Lib3dsDword)d & 0x000000FF));
|
||||
if (fwrite(b,4,1,f)!=1) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -448,27 +438,24 @@ lib3ds_float_write(Lib3dsFloat l, FILE *f)
|
||||
* \ingroup readwrite
|
||||
* \ingroup vector
|
||||
*
|
||||
* Writes a vector into a file stream in little endian format.
|
||||
* Writes a vector into a file stream in little endian format.
|
||||
*
|
||||
* \param v The vector to write to the file stream.
|
||||
* \param f Input file stream.
|
||||
* \param v The vector to write to the file stream.
|
||||
* \param f Input file stream.
|
||||
*/
|
||||
Lib3dsBool
|
||||
lib3ds_vector_write(Lib3dsVector v, FILE *f)
|
||||
{
|
||||
if (!lib3ds_float_write(v[0], f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (!lib3ds_float_write(v[1], f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (!lib3ds_float_write(v[2], f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
if (!lib3ds_float_write(v[0], f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (!lib3ds_float_write(v[1], f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (!lib3ds_float_write(v[2], f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -478,19 +465,16 @@ lib3ds_vector_write(Lib3dsVector v, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_rgb_write(Lib3dsRgb rgb, FILE *f)
|
||||
{
|
||||
if (!lib3ds_float_write(rgb[0], f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (!lib3ds_float_write(rgb[1], f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (!lib3ds_float_write(rgb[2], f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
if (!lib3ds_float_write(rgb[0], f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (!lib3ds_float_write(rgb[1], f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (!lib3ds_float_write(rgb[2], f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -507,12 +491,12 @@ lib3ds_rgb_write(Lib3dsRgb rgb, FILE *f)
|
||||
Lib3dsBool
|
||||
lib3ds_string_write(const char *s, FILE *f)
|
||||
{
|
||||
ASSERT(s);
|
||||
ASSERT(f);
|
||||
do fputc(*s,f); while (*s++);
|
||||
if (ferror(f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
ASSERT(s);
|
||||
ASSERT(f);
|
||||
do fputc(*s,f); while (*s++);
|
||||
if (ferror(f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
@@ -23,6 +23,8 @@
|
||||
#include <shadow.h>
|
||||
#include <chunk.h>
|
||||
#include <readwrite.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \defgroup shadow Shadow Map Settings
|
||||
@@ -30,118 +32,122 @@
|
||||
* \author J.E. Hoffmann <je-h@gmx.net>
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup shadow
|
||||
* \ingroup shadow
|
||||
*/
|
||||
Lib3dsBool
|
||||
lib3ds_shadow_read(Lib3dsShadow *shadow, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
Lib3dsChunk c;
|
||||
|
||||
if (!lib3ds_chunk_read(&c, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
|
||||
switch (c.chunk)
|
||||
{
|
||||
case LIB3DS_SHADOW_MAP_SIZE:
|
||||
{
|
||||
shadow->map_size=lib3ds_intw_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_LO_SHADOW_BIAS:
|
||||
{
|
||||
shadow->lo_bias=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_HI_SHADOW_BIAS:
|
||||
{
|
||||
shadow->hi_bias=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_SHADOW_SAMPLES:
|
||||
{
|
||||
shadow->samples=lib3ds_intw_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_SHADOW_RANGE:
|
||||
{
|
||||
shadow->range=lib3ds_intw_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_SHADOW_FILTER:
|
||||
{
|
||||
shadow->filter=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_RAY_BIAS:
|
||||
{
|
||||
shadow->ray_bias=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return(LIB3DS_TRUE);
|
||||
if (!lib3ds_chunk_read(&c, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
|
||||
switch (c.chunk) {
|
||||
case LIB3DS_SHADOW_MAP_SIZE:
|
||||
{
|
||||
shadow->map_size=lib3ds_intw_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_LO_SHADOW_BIAS:
|
||||
{
|
||||
shadow->lo_bias=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_HI_SHADOW_BIAS:
|
||||
{
|
||||
shadow->hi_bias=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_SHADOW_SAMPLES:
|
||||
{
|
||||
shadow->samples=lib3ds_intw_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_SHADOW_RANGE:
|
||||
{
|
||||
shadow->range=lib3ds_intd_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_SHADOW_FILTER:
|
||||
{
|
||||
shadow->filter=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_RAY_BIAS:
|
||||
{
|
||||
shadow->ray_bias=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup shadow
|
||||
* \ingroup shadow
|
||||
*/
|
||||
Lib3dsBool
|
||||
lib3ds_shadow_write(Lib3dsShadow *shadow, FILE *f)
|
||||
{
|
||||
{ /*---- LIB3DS_LO_SHADOW_BIAS ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_LO_SHADOW_BIAS;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_float_write(shadow->lo_bias,f);
|
||||
}
|
||||
{ /*---- LIB3DS_HI_SHADOW_BIAS ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_HI_SHADOW_BIAS;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_float_write(shadow->hi_bias,f);
|
||||
}
|
||||
{ /*---- LIB3DS_SHADOW_MAP_SIZE ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_SHADOW_MAP_SIZE;
|
||||
c.size=8;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_intw_write(shadow->map_size,f);
|
||||
}
|
||||
{ /*---- LIB3DS_SHADOW_SAMPLES ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_SHADOW_SAMPLES;
|
||||
c.size=8;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_intw_write(shadow->samples,f);
|
||||
}
|
||||
{ /*---- LIB3DS_SHADOW_RANGE ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_SHADOW_RANGE;
|
||||
c.size=8;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_intw_write(shadow->range,f);
|
||||
}
|
||||
{ /*---- LIB3DS_SHADOW_FILTER ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_SHADOW_FILTER;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_float_write(shadow->filter,f);
|
||||
}
|
||||
{ /*---- LIB3DS_RAY_BIAS ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_RAY_BIAS;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_float_write(shadow->ray_bias,f);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
if (fabs(shadow->lo_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_LO_SHADOW_BIAS ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_LO_SHADOW_BIAS;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_float_write(shadow->lo_bias,f);
|
||||
}
|
||||
|
||||
if (fabs(shadow->hi_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_HI_SHADOW_BIAS ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_HI_SHADOW_BIAS;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_float_write(shadow->hi_bias,f);
|
||||
}
|
||||
|
||||
if (shadow->map_size) { /*---- LIB3DS_SHADOW_MAP_SIZE ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_SHADOW_MAP_SIZE;
|
||||
c.size=8;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_intw_write(shadow->map_size,f);
|
||||
}
|
||||
|
||||
if (shadow->samples) { /*---- LIB3DS_SHADOW_SAMPLES ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_SHADOW_SAMPLES;
|
||||
c.size=8;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_intw_write(shadow->samples,f);
|
||||
}
|
||||
|
||||
if (shadow->range) { /*---- LIB3DS_SHADOW_RANGE ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_SHADOW_RANGE;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_intd_write(shadow->range,f);
|
||||
}
|
||||
|
||||
if (fabs(shadow->filter)>LIB3DS_EPSILON) { /*---- LIB3DS_SHADOW_FILTER ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_SHADOW_FILTER;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_float_write(shadow->filter,f);
|
||||
}
|
||||
if (fabs(shadow->ray_bias)>LIB3DS_EPSILON) { /*---- LIB3DS_RAY_BIAS ----*/
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_RAY_BIAS;
|
||||
c.size=10;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_float_write(shadow->ray_bias,f);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ struct _Lib3dsShadow {
|
||||
Lib3dsFloat lo_bias;
|
||||
Lib3dsFloat hi_bias;
|
||||
Lib3dsIntw samples;
|
||||
Lib3dsIntw range;
|
||||
Lib3dsIntd range;
|
||||
Lib3dsFloat filter;
|
||||
Lib3dsFloat ray_bias;
|
||||
};
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
@@ -24,125 +24,116 @@
|
||||
#include <readwrite.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \defgroup tcb Tension/Continuity/Bias Splines
|
||||
*
|
||||
* \author J.E. Hoffmann <je-h@gmx.net>
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup tcb
|
||||
* \ingroup tcb
|
||||
*/
|
||||
void
|
||||
lib3ds_tcb(Lib3dsTcb *p, Lib3dsTcb *pc, Lib3dsTcb *c, Lib3dsTcb *nc, Lib3dsTcb *n,
|
||||
Lib3dsFloat *ksm, Lib3dsFloat *ksp, Lib3dsFloat *kdm, Lib3dsFloat *kdp)
|
||||
Lib3dsFloat *ksm, Lib3dsFloat *ksp, Lib3dsFloat *kdm, Lib3dsFloat *kdp)
|
||||
{
|
||||
Lib3dsFloat tm,cm,cp,bm,bp,tmcm,tmcp,cc;
|
||||
Lib3dsFloat dt,fp,fn;
|
||||
Lib3dsFloat tm,cm,cp,bm,bp,tmcm,tmcp,cc;
|
||||
Lib3dsFloat dt,fp,fn;
|
||||
|
||||
if (!pc)
|
||||
{
|
||||
pc=c;
|
||||
}
|
||||
if (!nc)
|
||||
{
|
||||
nc=c;
|
||||
}
|
||||
if (!pc) {
|
||||
pc=c;
|
||||
}
|
||||
if (!nc) {
|
||||
nc=c;
|
||||
}
|
||||
|
||||
fp=fn=1.0f;
|
||||
if (p&&n) {
|
||||
dt=0.5f*(Lib3dsFloat)(pc->frame-p->frame+n->frame-nc->frame);
|
||||
fp=((Lib3dsFloat)(pc->frame-p->frame))/dt;
|
||||
fn=((Lib3dsFloat)(n->frame-nc->frame))/dt;
|
||||
cc=(Lib3dsFloat)fabs(c->cont);
|
||||
fp=fp+cc-cc*fp;
|
||||
fn=fn+cc-cc*fn;
|
||||
}
|
||||
|
||||
fp=fn=1.0f;
|
||||
if (p&&n)
|
||||
{
|
||||
dt=0.5f*(Lib3dsFloat)(pc->frame-p->frame+n->frame-nc->frame);
|
||||
fp=((Lib3dsFloat)(pc->frame-p->frame))/dt;
|
||||
fn=((Lib3dsFloat)(n->frame-nc->frame))/dt;
|
||||
cc=(Lib3dsFloat)fabs(c->cont);
|
||||
fp=fp+cc-cc*fp;
|
||||
fn=fn+cc-cc*fn;
|
||||
}
|
||||
|
||||
cm=1.0f-c->cont;
|
||||
tm=0.5f*(1.0f-c->tens);
|
||||
cp=2.0f-cm;
|
||||
bm=1.0f-c->bias;
|
||||
bp=2.0f-bm;
|
||||
tmcm=tm*cm;
|
||||
tmcp=tm*cp;
|
||||
*ksm=tmcm*bp*fp;
|
||||
*ksp=tmcp*bm*fp;
|
||||
*kdm=tmcp*bp*fn;
|
||||
*kdp=tmcm*bm*fn;
|
||||
cm=1.0f-c->cont;
|
||||
tm=0.5f*(1.0f-c->tens);
|
||||
cp=2.0f-cm;
|
||||
bm=1.0f-c->bias;
|
||||
bp=2.0f-bm;
|
||||
tmcm=tm*cm;
|
||||
tmcp=tm*cp;
|
||||
*ksm=tmcm*bp*fp;
|
||||
*ksp=tmcp*bm*fp;
|
||||
*kdm=tmcp*bp*fn;
|
||||
*kdp=tmcm*bm*fn;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup tcb
|
||||
* \ingroup tcb
|
||||
*/
|
||||
Lib3dsBool
|
||||
lib3ds_tcb_read(Lib3dsTcb *tcb, FILE *f)
|
||||
{
|
||||
Lib3dsWord flags;
|
||||
|
||||
tcb->frame=lib3ds_intd_read(f);
|
||||
tcb->flags=flags=lib3ds_word_read(f);
|
||||
if (flags&LIB3DS_USE_TENSION)
|
||||
{
|
||||
tcb->tens=lib3ds_float_read(f);
|
||||
}
|
||||
if (flags&LIB3DS_USE_CONTINUITY)
|
||||
{
|
||||
tcb->cont=lib3ds_float_read(f);
|
||||
}
|
||||
if (flags&LIB3DS_USE_BIAS)
|
||||
{
|
||||
tcb->bias=lib3ds_float_read(f);
|
||||
}
|
||||
if (flags&LIB3DS_USE_EASE_TO)
|
||||
{
|
||||
tcb->ease_to=lib3ds_float_read(f);
|
||||
}
|
||||
if (flags&LIB3DS_USE_EASE_FROM)
|
||||
{
|
||||
tcb->ease_from=lib3ds_float_read(f);
|
||||
}
|
||||
if (ferror(f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
Lib3dsWord flags;
|
||||
|
||||
tcb->frame=lib3ds_intd_read(f);
|
||||
tcb->flags=flags=lib3ds_word_read(f);
|
||||
if (flags&LIB3DS_USE_TENSION) {
|
||||
tcb->tens=lib3ds_float_read(f);
|
||||
}
|
||||
if (flags&LIB3DS_USE_CONTINUITY) {
|
||||
tcb->cont=lib3ds_float_read(f);
|
||||
}
|
||||
if (flags&LIB3DS_USE_BIAS) {
|
||||
tcb->bias=lib3ds_float_read(f);
|
||||
}
|
||||
if (flags&LIB3DS_USE_EASE_TO) {
|
||||
tcb->ease_to=lib3ds_float_read(f);
|
||||
}
|
||||
if (flags&LIB3DS_USE_EASE_FROM) {
|
||||
tcb->ease_from=lib3ds_float_read(f);
|
||||
}
|
||||
if (ferror(f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup tcb
|
||||
* \ingroup tcb
|
||||
*/
|
||||
Lib3dsBool
|
||||
lib3ds_tcb_write(Lib3dsTcb *tcb, FILE *f)
|
||||
{
|
||||
lib3ds_intd_write(tcb->frame,f);
|
||||
lib3ds_word_write(tcb->flags,f);
|
||||
if (tcb->flags&LIB3DS_USE_TENSION)
|
||||
{
|
||||
lib3ds_float_write(tcb->tens,f);
|
||||
}
|
||||
if (tcb->flags&LIB3DS_USE_CONTINUITY)
|
||||
{
|
||||
lib3ds_float_write(tcb->cont,f);
|
||||
}
|
||||
if (tcb->flags&LIB3DS_USE_BIAS)
|
||||
{
|
||||
lib3ds_float_write(tcb->bias,f);
|
||||
}
|
||||
if (tcb->flags&LIB3DS_USE_EASE_TO)
|
||||
{
|
||||
lib3ds_float_write(tcb->ease_to,f);
|
||||
}
|
||||
if (tcb->flags&LIB3DS_USE_EASE_FROM)
|
||||
{
|
||||
lib3ds_float_write(tcb->ease_from,f);
|
||||
}
|
||||
if (ferror(f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
lib3ds_intd_write(tcb->frame,f);
|
||||
lib3ds_word_write(tcb->flags,f);
|
||||
if (tcb->flags&LIB3DS_USE_TENSION) {
|
||||
lib3ds_float_write(tcb->tens,f);
|
||||
}
|
||||
if (tcb->flags&LIB3DS_USE_CONTINUITY) {
|
||||
lib3ds_float_write(tcb->cont,f);
|
||||
}
|
||||
if (tcb->flags&LIB3DS_USE_BIAS) {
|
||||
lib3ds_float_write(tcb->bias,f);
|
||||
}
|
||||
if (tcb->flags&LIB3DS_USE_EASE_TO) {
|
||||
lib3ds_float_write(tcb->ease_to,f);
|
||||
}
|
||||
if (tcb->flags&LIB3DS_USE_EASE_FROM) {
|
||||
lib3ds_float_write(tcb->ease_from,f);
|
||||
}
|
||||
if (ferror(f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,15 +26,19 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && (!defined(__GNUC__))
|
||||
#ifdef LIB3DS_EXPORT
|
||||
#define LIB3DSAPI __declspec(dllexport)
|
||||
#else
|
||||
#define LIB3DSAPI __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
/*
|
||||
* #if defined (_LIB3DS_DLL) && defined(_WIN32) && (!defined(__GNUC__))
|
||||
* #ifdef LIB3DS_EXPORT
|
||||
* #define LIB3DSAPI __declspec(dllexport)
|
||||
* #else
|
||||
* #define LIB3DSAPI __declspec(dllimport)
|
||||
* #endif
|
||||
* #else
|
||||
* #define LIB3DSAPI
|
||||
* #endif
|
||||
*/
|
||||
// within the OSG just use the libary inline, no need to export symbols.
|
||||
#define LIB3DSAPI
|
||||
#endif
|
||||
|
||||
#define LIB3DS_TRUE 1
|
||||
#define LIB3DS_FALSE 0
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <vector.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \defgroup vector Vector Mathematics
|
||||
*
|
||||
@@ -33,17 +34,17 @@
|
||||
* \ingroup vector
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup vector
|
||||
*/
|
||||
void
|
||||
lib3ds_vector_zero(Lib3dsVector c)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
c[i]=0.0f;
|
||||
}
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
c[i]=0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,11 +54,10 @@ lib3ds_vector_zero(Lib3dsVector c)
|
||||
void
|
||||
lib3ds_vector_copy(Lib3dsVector dest, Lib3dsVector src)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
dest[i]=src[i];
|
||||
}
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
dest[i]=src[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,11 +67,10 @@ lib3ds_vector_copy(Lib3dsVector dest, Lib3dsVector src)
|
||||
void
|
||||
lib3ds_vector_neg(Lib3dsVector c)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
c[i]=-c[i];
|
||||
}
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
c[i]=-c[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,11 +80,10 @@ lib3ds_vector_neg(Lib3dsVector c)
|
||||
void
|
||||
lib3ds_vector_add(Lib3dsVector c, Lib3dsVector a, Lib3dsVector b)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
c[i]=a[i]+b[i];
|
||||
}
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
c[i]=a[i]+b[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,11 +93,10 @@ lib3ds_vector_add(Lib3dsVector c, Lib3dsVector a, Lib3dsVector b)
|
||||
void
|
||||
lib3ds_vector_sub(Lib3dsVector c, Lib3dsVector a, Lib3dsVector b)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
c[i]=a[i]-b[i];
|
||||
}
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
c[i]=a[i]-b[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,11 +106,10 @@ lib3ds_vector_sub(Lib3dsVector c, Lib3dsVector a, Lib3dsVector b)
|
||||
void
|
||||
lib3ds_vector_scalar(Lib3dsVector c, Lib3dsFloat k)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i)
|
||||
{
|
||||
c[i]*=k;
|
||||
}
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
c[i]*=k;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,9 +119,9 @@ lib3ds_vector_scalar(Lib3dsVector c, Lib3dsFloat k)
|
||||
void
|
||||
lib3ds_vector_cross(Lib3dsVector c, Lib3dsVector a, Lib3dsVector b)
|
||||
{
|
||||
c[0]=a[1]*b[2] - a[2]*b[1];
|
||||
c[1]=a[2]*b[0] - a[0]*b[2];
|
||||
c[2]=a[0]*b[1] - a[1]*b[0];
|
||||
c[0]=a[1]*b[2] - a[2]*b[1];
|
||||
c[1]=a[2]*b[0] - a[0]*b[2];
|
||||
c[2]=a[0]*b[1] - a[1]*b[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +131,7 @@ lib3ds_vector_cross(Lib3dsVector c, Lib3dsVector a, Lib3dsVector b)
|
||||
Lib3dsFloat
|
||||
lib3ds_vector_dot(Lib3dsVector a, Lib3dsVector b)
|
||||
{
|
||||
return(a[0]*b[0] + a[1]*b[1] + a[2]*b[2]);
|
||||
return(a[0]*b[0] + a[1]*b[1] + a[2]*b[2]);
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +141,7 @@ lib3ds_vector_dot(Lib3dsVector a, Lib3dsVector b)
|
||||
Lib3dsFloat
|
||||
lib3ds_vector_squared(Lib3dsVector c)
|
||||
{
|
||||
return(c[0]*c[0] + c[1]*c[1] + c[2]*c[2]);
|
||||
return(c[0]*c[0] + c[1]*c[1] + c[2]*c[2]);
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +151,7 @@ lib3ds_vector_squared(Lib3dsVector c)
|
||||
Lib3dsFloat
|
||||
lib3ds_vector_length(Lib3dsVector c)
|
||||
{
|
||||
return((Lib3dsFloat)sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2]));
|
||||
return((Lib3dsFloat)sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2]));
|
||||
}
|
||||
|
||||
|
||||
@@ -165,33 +161,28 @@ lib3ds_vector_length(Lib3dsVector c)
|
||||
void
|
||||
lib3ds_vector_normalize(Lib3dsVector c)
|
||||
{
|
||||
Lib3dsFloat l,m;
|
||||
Lib3dsFloat l,m;
|
||||
|
||||
l=(Lib3dsFloat)sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2]);
|
||||
if (fabs(l)<LIB3DS_EPSILON)
|
||||
{
|
||||
c[0]=c[1]=c[2]=0.0f;
|
||||
if ((c[0]>=c[1]) && (c[0]>=c[2]))
|
||||
{
|
||||
c[0]=1.0f;
|
||||
}
|
||||
else
|
||||
if (c[1]>=c[2])
|
||||
{
|
||||
c[1]=1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
c[2]=1.0f;
|
||||
}
|
||||
l=(Lib3dsFloat)sqrt(c[0]*c[0] + c[1]*c[1] + c[2]*c[2]);
|
||||
if (fabs(l)<LIB3DS_EPSILON) {
|
||||
c[0]=c[1]=c[2]=0.0f;
|
||||
if ((c[0]>=c[1]) && (c[0]>=c[2])) {
|
||||
c[0]=1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
m=1.0f/l;
|
||||
c[0]*=m;
|
||||
c[1]*=m;
|
||||
c[2]*=m;
|
||||
if (c[1]>=c[2]) {
|
||||
c[1]=1.0f;
|
||||
}
|
||||
else {
|
||||
c[2]=1.0f;
|
||||
}
|
||||
}
|
||||
else {
|
||||
m=1.0f/l;
|
||||
c[0]*=m;
|
||||
c[1]*=m;
|
||||
c[2]*=m;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -201,12 +192,12 @@ lib3ds_vector_normalize(Lib3dsVector c)
|
||||
void
|
||||
lib3ds_vector_normal(Lib3dsVector n, Lib3dsVector a, Lib3dsVector b, Lib3dsVector c)
|
||||
{
|
||||
Lib3dsVector p,q;
|
||||
Lib3dsVector p,q;
|
||||
|
||||
lib3ds_vector_sub(p,c,b);
|
||||
lib3ds_vector_sub(q,a,b);
|
||||
lib3ds_vector_cross(n,p,q);
|
||||
lib3ds_vector_normalize(n);
|
||||
lib3ds_vector_sub(p,c,b);
|
||||
lib3ds_vector_sub(q,a,b);
|
||||
lib3ds_vector_cross(n,p,q);
|
||||
lib3ds_vector_normalize(n);
|
||||
}
|
||||
|
||||
|
||||
@@ -216,9 +207,9 @@ lib3ds_vector_normal(Lib3dsVector n, Lib3dsVector a, Lib3dsVector b, Lib3dsVecto
|
||||
void
|
||||
lib3ds_vector_transform(Lib3dsVector c, Lib3dsMatrix m, Lib3dsVector a)
|
||||
{
|
||||
c[0]= m[0][0]*a[0] + m[1][0]*a[1] + m[2][0]*a[2] + m[3][0];
|
||||
c[1]= m[0][1]*a[0] + m[1][1]*a[1] + m[2][1]*a[2] + m[3][1];
|
||||
c[2]= m[0][2]*a[0] + m[1][2]*a[1] + m[2][2]*a[2] + m[3][2];
|
||||
c[0]= m[0][0]*a[0] + m[1][0]*a[1] + m[2][0]*a[2] + m[3][0];
|
||||
c[1]= m[0][1]*a[0] + m[1][1]*a[1] + m[2][1]*a[2] + m[3][1];
|
||||
c[2]= m[0][2]*a[0] + m[1][2]*a[1] + m[2][2]*a[2] + m[3][2];
|
||||
}
|
||||
|
||||
|
||||
@@ -227,17 +218,49 @@ lib3ds_vector_transform(Lib3dsVector c, Lib3dsMatrix m, Lib3dsVector a)
|
||||
*/
|
||||
void
|
||||
lib3ds_vector_cubic(Lib3dsVector c, Lib3dsVector a, Lib3dsVector p, Lib3dsVector q,
|
||||
Lib3dsVector b, Lib3dsFloat t)
|
||||
Lib3dsVector b, Lib3dsFloat t)
|
||||
{
|
||||
Lib3dsDouble x,y,z,w;
|
||||
Lib3dsDouble x,y,z,w;
|
||||
|
||||
x=2*t*t*t - 3*t*t + 1;
|
||||
y=-2*t*t*t + 3*t*t;
|
||||
z=t*t*t - 2*t*t + t;
|
||||
w=t*t*t - t*t;
|
||||
c[0]=(Lib3dsFloat)(x*a[0] + y*b[0] + z*p[0] + w*q[0]);
|
||||
c[1]=(Lib3dsFloat)(x*a[1] + y*b[1] + z*p[1] + w*q[1]);
|
||||
c[2]=(Lib3dsFloat)(x*a[2] + y*b[2] + z*p[2] + w*q[2]);
|
||||
x=2*t*t*t - 3*t*t + 1;
|
||||
y=-2*t*t*t + 3*t*t;
|
||||
z=t*t*t - 2*t*t + t;
|
||||
w=t*t*t - t*t;
|
||||
c[0]=(Lib3dsFloat)(x*a[0] + y*b[0] + z*p[0] + w*q[0]);
|
||||
c[1]=(Lib3dsFloat)(x*a[1] + y*b[1] + z*p[1] + w*q[1]);
|
||||
c[2]=(Lib3dsFloat)(x*a[2] + y*b[2] + z*p[2] + w*q[2]);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* c[i] = min(c[i], a[i]);
|
||||
* \ingroup vector
|
||||
*/
|
||||
void
|
||||
lib3ds_vector_min(Lib3dsVector c, Lib3dsVector a)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
if (a[i]<c[i]) {
|
||||
c[i] = a[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* c[i] = max(c[i], a[i]);
|
||||
* \ingroup vector
|
||||
*/
|
||||
void
|
||||
lib3ds_vector_max(Lib3dsVector c, Lib3dsVector a)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
if (a[i]>c[i]) {
|
||||
c[i] = a[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -247,5 +270,6 @@ Lib3dsVector b, Lib3dsFloat t)
|
||||
void
|
||||
lib3ds_vector_dump(Lib3dsVector c)
|
||||
{
|
||||
fprintf(stderr, "%f %f %f\n", c[0], c[1], c[2]);
|
||||
fprintf(stderr, "%f %f %f\n", c[0], c[1], c[2]);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ extern LIB3DSAPI void lib3ds_vector_normal(Lib3dsVector n, Lib3dsVector a,
|
||||
extern LIB3DSAPI void lib3ds_vector_transform(Lib3dsVector c, Lib3dsMatrix m, Lib3dsVector a);
|
||||
extern LIB3DSAPI void lib3ds_vector_cubic(Lib3dsVector c, Lib3dsVector a, Lib3dsVector p,
|
||||
Lib3dsVector q, Lib3dsVector b, Lib3dsFloat t);
|
||||
extern LIB3DSAPI void lib3ds_vector_min(Lib3dsVector c, Lib3dsVector a);
|
||||
extern LIB3DSAPI void lib3ds_vector_max(Lib3dsVector c, Lib3dsVector a);
|
||||
extern LIB3DSAPI void lib3ds_vector_dump(Lib3dsVector c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
@@ -26,351 +26,335 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*!
|
||||
* \defgroup viewport Viewport and default view settings
|
||||
*
|
||||
* \author J.E. Hoffmann <je-h@gmx.net>
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup viewport
|
||||
* \ingroup viewport
|
||||
*/
|
||||
Lib3dsBool
|
||||
lib3ds_viewport_read(Lib3dsViewport *viewport, FILE *f)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
Lib3dsChunk c;
|
||||
Lib3dsWord chunk;
|
||||
|
||||
if (!lib3ds_chunk_read(&c, f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
if (!lib3ds_chunk_read_start(&c, 0, f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
|
||||
switch (c.chunk) {
|
||||
case LIB3DS_VIEWPORT_LAYOUT:
|
||||
{
|
||||
int cur=0;
|
||||
viewport->layout.style=lib3ds_word_read(f);
|
||||
viewport->layout.active=lib3ds_intw_read(f);
|
||||
lib3ds_intw_read(f);
|
||||
viewport->layout.swap=lib3ds_intw_read(f);
|
||||
lib3ds_intw_read(f);
|
||||
viewport->layout.swap_prior=lib3ds_intw_read(f);
|
||||
viewport->layout.swap_view=lib3ds_intw_read(f);
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
|
||||
switch (chunk) {
|
||||
case LIB3DS_VIEWPORT_SIZE:
|
||||
{
|
||||
viewport->layout.position[0]=lib3ds_word_read(f);
|
||||
viewport->layout.position[1]=lib3ds_word_read(f);
|
||||
viewport->layout.size[0]=lib3ds_word_read(f);
|
||||
viewport->layout.size[1]=lib3ds_word_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEWPORT_DATA_3:
|
||||
{
|
||||
lib3ds_viewport_set_views(viewport,cur+1);
|
||||
lib3ds_intw_read(f);
|
||||
viewport->layout.viewL[cur].axis_lock=lib3ds_word_read(f);
|
||||
viewport->layout.viewL[cur].position[0]=lib3ds_intw_read(f);
|
||||
viewport->layout.viewL[cur].position[1]=lib3ds_intw_read(f);
|
||||
viewport->layout.viewL[cur].size[0]=lib3ds_intw_read(f);
|
||||
viewport->layout.viewL[cur].size[1]=lib3ds_intw_read(f);
|
||||
viewport->layout.viewL[cur].type=lib3ds_word_read(f);
|
||||
viewport->layout.viewL[cur].zoom=lib3ds_float_read(f);
|
||||
lib3ds_vector_read(viewport->layout.viewL[cur].center,f);
|
||||
viewport->layout.viewL[cur].horiz_angle=lib3ds_float_read(f);
|
||||
viewport->layout.viewL[cur].vert_angle=lib3ds_float_read(f);
|
||||
fread(viewport->layout.viewL[cur].camera,11,1,f);
|
||||
++cur;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEWPORT_DATA:
|
||||
/* 3DS R2 & R3 chunk
|
||||
unsupported */
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DEFAULT_VIEW:
|
||||
{
|
||||
memset(&viewport->default_view,0,sizeof(Lib3dsDefaultView));
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0) {
|
||||
switch (chunk) {
|
||||
case LIB3DS_VIEW_TOP:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_TOP;
|
||||
lib3ds_vector_read(viewport->default_view.position,f);
|
||||
viewport->default_view.width=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_BOTTOM:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_BOTTOM;
|
||||
lib3ds_vector_read(viewport->default_view.position,f);
|
||||
viewport->default_view.width=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_LEFT:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_LEFT;
|
||||
lib3ds_vector_read(viewport->default_view.position,f);
|
||||
viewport->default_view.width=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_RIGHT:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_RIGHT;
|
||||
lib3ds_vector_read(viewport->default_view.position,f);
|
||||
viewport->default_view.width=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_FRONT:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_FRONT;
|
||||
lib3ds_vector_read(viewport->default_view.position,f);
|
||||
viewport->default_view.width=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_BACK:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_BACK;
|
||||
lib3ds_vector_read(viewport->default_view.position,f);
|
||||
viewport->default_view.width=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_USER:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_USER;
|
||||
lib3ds_vector_read(viewport->default_view.position,f);
|
||||
viewport->default_view.width=lib3ds_float_read(f);
|
||||
viewport->default_view.horiz_angle=lib3ds_float_read(f);
|
||||
viewport->default_view.vert_angle=lib3ds_float_read(f);
|
||||
viewport->default_view.roll_angle=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_CAMERA:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_CAMERA;
|
||||
fread(viewport->default_view.camera,11,1,f);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c.chunk)
|
||||
{
|
||||
case LIB3DS_VIEWPORT_LAYOUT:
|
||||
{
|
||||
int cur=0;
|
||||
viewport->layout.style=lib3ds_word_read(f);
|
||||
viewport->layout.active=lib3ds_intw_read(f);
|
||||
lib3ds_intw_read(f);
|
||||
viewport->layout.swap=lib3ds_intw_read(f);
|
||||
lib3ds_intw_read(f);
|
||||
viewport->layout.swap_prior=lib3ds_intw_read(f);
|
||||
viewport->layout.swap_view=lib3ds_intw_read(f);
|
||||
lib3ds_chunk_read_tell(&c, f);
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0)
|
||||
{
|
||||
switch (chunk)
|
||||
{
|
||||
case LIB3DS_VIEWPORT_SIZE:
|
||||
{
|
||||
viewport->layout.position[0]=lib3ds_word_read(f);
|
||||
viewport->layout.position[1]=lib3ds_word_read(f);
|
||||
viewport->layout.size[0]=lib3ds_word_read(f);
|
||||
viewport->layout.size[1]=lib3ds_word_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEWPORT_DATA_3:
|
||||
{
|
||||
lib3ds_viewport_set_views(viewport,cur+1);
|
||||
lib3ds_intw_read(f);
|
||||
viewport->layout.viewL[cur].axis_lock=lib3ds_word_read(f);
|
||||
viewport->layout.viewL[cur].position[0]=lib3ds_intw_read(f);
|
||||
viewport->layout.viewL[cur].position[1]=lib3ds_intw_read(f);
|
||||
viewport->layout.viewL[cur].size[0]=lib3ds_intw_read(f);
|
||||
viewport->layout.viewL[cur].size[1]=lib3ds_intw_read(f);
|
||||
viewport->layout.viewL[cur].type=lib3ds_word_read(f);
|
||||
viewport->layout.viewL[cur].zoom=lib3ds_float_read(f);
|
||||
lib3ds_vector_read(viewport->layout.viewL[cur].center,f);
|
||||
viewport->layout.viewL[cur].horiz_angle=lib3ds_float_read(f);
|
||||
viewport->layout.viewL[cur].vert_angle=lib3ds_float_read(f);
|
||||
fread(viewport->layout.viewL[cur].camera,11,1,f);
|
||||
++cur;
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEWPORT_DATA:
|
||||
/* 3DS R2 & R3 chunk
|
||||
unsupported */
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
}
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_DEFAULT_VIEW:
|
||||
{
|
||||
memset(&viewport->default_view,0,sizeof(Lib3dsDefaultView));
|
||||
while ((chunk=lib3ds_chunk_read_next(&c, f))!=0)
|
||||
{
|
||||
switch (chunk)
|
||||
{
|
||||
case LIB3DS_VIEW_TOP:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_TOP;
|
||||
lib3ds_vector_read(viewport->default_view.position,f);
|
||||
viewport->default_view.width=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_BOTTOM:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_BOTTOM;
|
||||
lib3ds_vector_read(viewport->default_view.position,f);
|
||||
viewport->default_view.width=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_LEFT:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_LEFT;
|
||||
lib3ds_vector_read(viewport->default_view.position,f);
|
||||
viewport->default_view.width=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_RIGHT:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_RIGHT;
|
||||
lib3ds_vector_read(viewport->default_view.position,f);
|
||||
viewport->default_view.width=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_FRONT:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_FRONT;
|
||||
lib3ds_vector_read(viewport->default_view.position,f);
|
||||
viewport->default_view.width=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_BACK:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_BACK;
|
||||
lib3ds_vector_read(viewport->default_view.position,f);
|
||||
viewport->default_view.width=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_USER:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_USER;
|
||||
lib3ds_vector_read(viewport->default_view.position,f);
|
||||
viewport->default_view.width=lib3ds_float_read(f);
|
||||
viewport->default_view.horiz_angle=lib3ds_float_read(f);
|
||||
viewport->default_view.vert_angle=lib3ds_float_read(f);
|
||||
viewport->default_view.roll_angle=lib3ds_float_read(f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_CAMERA:
|
||||
{
|
||||
viewport->default_view.type=LIB3DS_VIEW_TYPE_CAMERA;
|
||||
fread(viewport->default_view.camera,11,1,f);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lib3ds_chunk_unknown(chunk);
|
||||
}
|
||||
}
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
lib3ds_chunk_read_end(&c, f);
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup viewport
|
||||
* \ingroup viewport
|
||||
*/
|
||||
void
|
||||
lib3ds_viewport_set_views(Lib3dsViewport *viewport, Lib3dsDword views)
|
||||
{
|
||||
ASSERT(viewport);
|
||||
if (viewport->layout.views)
|
||||
{
|
||||
if (views)
|
||||
{
|
||||
viewport->layout.views=views;
|
||||
viewport->layout.viewL=(Lib3dsView*)realloc(viewport->layout.viewL, sizeof(Lib3dsView)*views);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(viewport->layout.viewL);
|
||||
viewport->layout.views=0;
|
||||
viewport->layout.viewL=0;
|
||||
}
|
||||
ASSERT(viewport);
|
||||
if (viewport->layout.views) {
|
||||
if (views) {
|
||||
viewport->layout.views=views;
|
||||
viewport->layout.viewL=(Lib3dsView*)realloc(viewport->layout.viewL, sizeof(Lib3dsView)*views);
|
||||
}
|
||||
else
|
||||
{
|
||||
viewport->layout.views=views;
|
||||
viewport->layout.viewL=(Lib3dsView*)calloc(sizeof(Lib3dsView),views);
|
||||
else {
|
||||
free(viewport->layout.viewL);
|
||||
viewport->layout.views=0;
|
||||
viewport->layout.viewL=0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
viewport->layout.views=views;
|
||||
viewport->layout.viewL=(Lib3dsView*)calloc(sizeof(Lib3dsView),views);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \ingroup viewport
|
||||
* \ingroup viewport
|
||||
*/
|
||||
Lib3dsBool
|
||||
lib3ds_viewport_write(Lib3dsViewport *viewport, FILE *f)
|
||||
{
|
||||
if (viewport->layout.views)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
unsigned i;
|
||||
if (viewport->layout.views) {
|
||||
Lib3dsChunk c;
|
||||
unsigned i;
|
||||
|
||||
c.chunk=LIB3DS_VIEWPORT_LAYOUT;
|
||||
if (!lib3ds_chunk_write_start(&c,f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
|
||||
lib3ds_word_write(viewport->layout.style,f);
|
||||
lib3ds_intw_write(viewport->layout.active,f);
|
||||
lib3ds_intw_write(0,f);
|
||||
lib3ds_intw_write(viewport->layout.swap,f);
|
||||
lib3ds_intw_write(0,f);
|
||||
lib3ds_intw_write(viewport->layout.swap_prior,f);
|
||||
lib3ds_intw_write(viewport->layout.swap_view,f);
|
||||
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEWPORT_SIZE;
|
||||
c.size=14;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_intw_write(viewport->layout.position[0],f);
|
||||
lib3ds_intw_write(viewport->layout.position[1],f);
|
||||
lib3ds_intw_write(viewport->layout.size[0],f);
|
||||
lib3ds_intw_write(viewport->layout.size[1],f);
|
||||
}
|
||||
|
||||
for (i=0; i<viewport->layout.views; ++i)
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEWPORT_DATA_3;
|
||||
c.size=55;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
|
||||
lib3ds_intw_write(0,f);
|
||||
lib3ds_word_write(viewport->layout.viewL[i].axis_lock,f);
|
||||
lib3ds_intw_write(viewport->layout.viewL[i].position[0],f);
|
||||
lib3ds_intw_write(viewport->layout.viewL[i].position[1],f);
|
||||
lib3ds_intw_write(viewport->layout.viewL[i].size[0],f);
|
||||
lib3ds_intw_write(viewport->layout.viewL[i].size[1],f);
|
||||
lib3ds_word_write(viewport->layout.viewL[i].type,f);
|
||||
lib3ds_float_write(viewport->layout.viewL[i].zoom,f);
|
||||
lib3ds_vector_write(viewport->layout.viewL[i].center,f);
|
||||
lib3ds_float_write(viewport->layout.viewL[i].horiz_angle,f);
|
||||
lib3ds_float_write(viewport->layout.viewL[i].vert_angle,f);
|
||||
fwrite(viewport->layout.viewL[i].camera,11,1,f);
|
||||
}
|
||||
|
||||
if (!lib3ds_chunk_write_end(&c,f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
c.chunk=LIB3DS_VIEWPORT_LAYOUT;
|
||||
if (!lib3ds_chunk_write_start(&c,f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
|
||||
if (viewport->default_view.type)
|
||||
lib3ds_word_write(viewport->layout.style,f);
|
||||
lib3ds_intw_write(viewport->layout.active,f);
|
||||
lib3ds_intw_write(0,f);
|
||||
lib3ds_intw_write(viewport->layout.swap,f);
|
||||
lib3ds_intw_write(0,f);
|
||||
lib3ds_intw_write(viewport->layout.swap_prior,f);
|
||||
lib3ds_intw_write(viewport->layout.swap_view,f);
|
||||
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
|
||||
c.chunk=LIB3DS_DEFAULT_VIEW;
|
||||
if (!lib3ds_chunk_write_start(&c,f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
|
||||
switch (viewport->default_view.type)
|
||||
{
|
||||
case LIB3DS_VIEW_TYPE_TOP:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_TOP;
|
||||
c.size=22;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_vector_write(viewport->default_view.position,f);
|
||||
lib3ds_float_write(viewport->default_view.width,f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_TYPE_BOTTOM:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_BOTTOM;
|
||||
c.size=22;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_vector_write(viewport->default_view.position,f);
|
||||
lib3ds_float_write(viewport->default_view.width,f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_TYPE_LEFT:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_LEFT;
|
||||
c.size=22;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_vector_write(viewport->default_view.position,f);
|
||||
lib3ds_float_write(viewport->default_view.width,f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_TYPE_RIGHT:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_RIGHT;
|
||||
c.size=22;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_vector_write(viewport->default_view.position,f);
|
||||
lib3ds_float_write(viewport->default_view.width,f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_TYPE_FRONT:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_FRONT;
|
||||
c.size=22;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_vector_write(viewport->default_view.position,f);
|
||||
lib3ds_float_write(viewport->default_view.width,f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_TYPE_BACK:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_BACK;
|
||||
c.size=22;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_vector_write(viewport->default_view.position,f);
|
||||
lib3ds_float_write(viewport->default_view.width,f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_TYPE_USER:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_USER;
|
||||
c.size=34;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_vector_write(viewport->default_view.position,f);
|
||||
lib3ds_float_write(viewport->default_view.width,f);
|
||||
lib3ds_float_write(viewport->default_view.horiz_angle,f);
|
||||
lib3ds_float_write(viewport->default_view.vert_angle,f);
|
||||
lib3ds_float_write(viewport->default_view.roll_angle,f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_TYPE_CAMERA:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_CAMERA;
|
||||
c.size=17;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
fwrite(viewport->default_view.camera,1,11,f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!lib3ds_chunk_write_end(&c,f))
|
||||
{
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEWPORT_SIZE;
|
||||
c.size=14;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_intw_write(viewport->layout.position[0],f);
|
||||
lib3ds_intw_write(viewport->layout.position[1],f);
|
||||
lib3ds_intw_write(viewport->layout.size[0],f);
|
||||
lib3ds_intw_write(viewport->layout.size[1],f);
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
|
||||
for (i=0; i<viewport->layout.views; ++i) {
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEWPORT_DATA_3;
|
||||
c.size=55;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
|
||||
lib3ds_intw_write(0,f);
|
||||
lib3ds_word_write(viewport->layout.viewL[i].axis_lock,f);
|
||||
lib3ds_intw_write(viewport->layout.viewL[i].position[0],f);
|
||||
lib3ds_intw_write(viewport->layout.viewL[i].position[1],f);
|
||||
lib3ds_intw_write(viewport->layout.viewL[i].size[0],f);
|
||||
lib3ds_intw_write(viewport->layout.viewL[i].size[1],f);
|
||||
lib3ds_word_write(viewport->layout.viewL[i].type,f);
|
||||
lib3ds_float_write(viewport->layout.viewL[i].zoom,f);
|
||||
lib3ds_vector_write(viewport->layout.viewL[i].center,f);
|
||||
lib3ds_float_write(viewport->layout.viewL[i].horiz_angle,f);
|
||||
lib3ds_float_write(viewport->layout.viewL[i].vert_angle,f);
|
||||
fwrite(viewport->layout.viewL[i].camera,11,1,f);
|
||||
}
|
||||
|
||||
if (!lib3ds_chunk_write_end(&c,f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
if (viewport->default_view.type) {
|
||||
Lib3dsChunk c;
|
||||
|
||||
c.chunk=LIB3DS_DEFAULT_VIEW;
|
||||
if (!lib3ds_chunk_write_start(&c,f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
|
||||
switch (viewport->default_view.type) {
|
||||
case LIB3DS_VIEW_TYPE_TOP:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_TOP;
|
||||
c.size=22;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_vector_write(viewport->default_view.position,f);
|
||||
lib3ds_float_write(viewport->default_view.width,f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_TYPE_BOTTOM:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_BOTTOM;
|
||||
c.size=22;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_vector_write(viewport->default_view.position,f);
|
||||
lib3ds_float_write(viewport->default_view.width,f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_TYPE_LEFT:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_LEFT;
|
||||
c.size=22;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_vector_write(viewport->default_view.position,f);
|
||||
lib3ds_float_write(viewport->default_view.width,f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_TYPE_RIGHT:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_RIGHT;
|
||||
c.size=22;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_vector_write(viewport->default_view.position,f);
|
||||
lib3ds_float_write(viewport->default_view.width,f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_TYPE_FRONT:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_FRONT;
|
||||
c.size=22;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_vector_write(viewport->default_view.position,f);
|
||||
lib3ds_float_write(viewport->default_view.width,f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_TYPE_BACK:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_BACK;
|
||||
c.size=22;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_vector_write(viewport->default_view.position,f);
|
||||
lib3ds_float_write(viewport->default_view.width,f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_TYPE_USER:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_USER;
|
||||
c.size=34;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
lib3ds_vector_write(viewport->default_view.position,f);
|
||||
lib3ds_float_write(viewport->default_view.width,f);
|
||||
lib3ds_float_write(viewport->default_view.horiz_angle,f);
|
||||
lib3ds_float_write(viewport->default_view.vert_angle,f);
|
||||
lib3ds_float_write(viewport->default_view.roll_angle,f);
|
||||
}
|
||||
break;
|
||||
case LIB3DS_VIEW_TYPE_CAMERA:
|
||||
{
|
||||
Lib3dsChunk c;
|
||||
c.chunk=LIB3DS_VIEW_CAMERA;
|
||||
c.size=17;
|
||||
lib3ds_chunk_write(&c,f);
|
||||
fwrite(viewport->default_view.camera,1,11,f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!lib3ds_chunk_write_end(&c,f)) {
|
||||
return(LIB3DS_FALSE);
|
||||
}
|
||||
}
|
||||
return(LIB3DS_TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user