assimp/test/unit/utColladaExportCamera.cpp

97 lines
2.5 KiB
C++
Raw Normal View History

2015-05-17 19:25:47 +00:00
/*
* ColladaCameraExporter.cpp
*
* Created on: May 17, 2015
* Author: wise
*/
#include "UnitTestPCH.h"
#include <assimp/cexport.h>
#include <assimp/Exporter.hpp>
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#ifndef ASSIMP_BUILD_NO_EXPORT
class ColladaExportCamera : public ::testing::Test {
public:
2015-05-19 04:26:05 +00:00
virtual void SetUp()
{
ex = new Assimp::Exporter();
im = new Assimp::Importer();
2015-05-17 19:25:47 +00:00
2015-05-19 04:26:05 +00:00
}
2015-05-17 19:25:47 +00:00
2015-05-19 04:26:05 +00:00
virtual void TearDown()
{
delete ex;
delete im;
}
2015-05-17 19:25:47 +00:00
protected:
2015-05-19 04:26:05 +00:00
Assimp::Exporter* ex;
Assimp::Importer* im;
2015-05-17 19:25:47 +00:00
};
// ------------------------------------------------------------------------------------------------
TEST_F(ColladaExportCamera, testExportCamera)
{
2015-05-19 04:26:05 +00:00
const char* file = "cameraExp.dae";
2015-05-17 19:25:47 +00:00
const aiScene* pTest = im->ReadFile(ASSIMP_TEST_MODELS_DIR "/Collada/cameras.dae",0);
2015-05-19 04:26:05 +00:00
ASSERT_TRUE(pTest!=NULL);
ASSERT_TRUE(pTest->HasCameras());
2015-05-17 19:25:47 +00:00
2015-05-19 04:26:05 +00:00
EXPECT_EQ(AI_SUCCESS,ex->Export(pTest,"collada",file));
const unsigned int origNumCams( pTest->mNumCameras );
float *origFOV = new float[ origNumCams ];
float *orifClipPlaneNear = new float[ origNumCams ];
float *orifClipPlaneFar = new float[ origNumCams ];
aiString *names = new aiString[ origNumCams ];
aiVector3D *pos = new aiVector3D[ origNumCams ];
for (size_t i = 0; i < origNumCams; i++) {
const aiCamera *orig = pTest->mCameras[ i ];
origFOV[ i ] = orig->mHorizontalFOV;
orifClipPlaneNear[ i ] = orig->mClipPlaneNear;
orifClipPlaneFar[ i ] = orig->mClipPlaneFar;
names[ i ] = orig->mName;
pos[ i ] = orig->mPosition;
}
2015-05-19 04:26:05 +00:00
const aiScene* imported = im->ReadFile(file,0);
2015-05-17 19:25:47 +00:00
2015-05-19 04:26:05 +00:00
ASSERT_TRUE(imported!=NULL);
2015-05-17 19:25:47 +00:00
EXPECT_TRUE( imported->HasCameras() );
EXPECT_EQ( origNumCams, imported->mNumCameras );
2015-05-17 19:25:47 +00:00
for(size_t i=0; i< imported->mNumCameras;i++){
const aiCamera *read = imported->mCameras[ i ];
2015-05-17 19:25:47 +00:00
EXPECT_TRUE( names[ i ] == read->mName );
EXPECT_FLOAT_EQ( origFOV[ i ],read->mHorizontalFOV );
EXPECT_FLOAT_EQ( orifClipPlaneNear[ i ], read->mClipPlaneNear);
EXPECT_FLOAT_EQ( orifClipPlaneFar[ i ], read->mClipPlaneFar);
2015-05-17 19:25:47 +00:00
EXPECT_FLOAT_EQ( pos[ i ].x,read->mPosition.x);
EXPECT_FLOAT_EQ( pos[ i ].y,read->mPosition.y);
EXPECT_FLOAT_EQ( pos[ i ].z,read->mPosition.z);
2015-05-19 04:26:05 +00:00
}
delete [] origFOV;
delete [] orifClipPlaneNear;
delete [] orifClipPlaneFar;
delete [] names;
delete [] pos;
2015-05-17 19:25:47 +00:00
}
#endif