Example #1
0
        void Test5::SetupMeshes() {
            mesh1 = GetGreng().GetMeshManager().CreateMeshCube();
            mesh2 = GetGreng().GetMeshManager().CreateMeshQuad();
            mesh3 = GetGreng().GetMeshManager().CreateMeshFromObjFile(
                "assets/mt.obj");
            mesh4 = GetGreng().GetMeshManager().CreateMeshFromObjFile(
                "assets/RB-BumbleBee.obj");

            GetGreng().GetMeshManager().ComputeNormals(mesh3);
            GetGreng().GetMeshManager().ComputeTangentSpace(mesh3);
            GetGreng().GetMeshManager().ComputeNormals(mesh4);

            Matrix4f s;
            MatrixScale(s, Vec3f(0.1));

            Matrix4f rx;
            MatrixRotationX(rx, -M_PI / 2.0);

            Matrix4f ry;
            MatrixRotationY(ry, -M_PI / 2.0);

            Matrix4f rxy;
            MatrixMultiply(ry, rx, rxy);

            MatrixMultiply(rxy, s, mesh3ConstMatrix);
        }
Example #2
0
void BoxBrowser::SetZoomMatrix()
{
	MATRIX mtxScale = MatrixScale( zScale, zScale, zScale );
	MATRIX matrixX = MatrixRotationX( FROM_ANGLE( zRotX ) );
	MATRIX matrixZ = MatrixRotationZ( FROM_ANGLE( zRotZ ) );

	// rotate and translate
	MATRIX mx = MatrixRotationY( FROM_ANGLE( zRotY ) );					//rotate
	mx = MatrixMultiply( mx, matrixX );
	mx = MatrixMultiply( mx, matrixZ );
	mx = MatrixMultiply( mx, mtxScale );								//scale this thing up

	mx = MatrixMultiply( mx, MatrixTranslation( zPosX, zPosY, zPosZ ) ); //translate into place

	//apply matrix
	tiny3d_SetMatrixModelView( &mx );
}
Example #3
0
void BoxBrowser::CreateMatrix( float xpos, float ypos, float zpos, float xrot, float yrot, float zrot, float scale )
{
	MATRIX mtxScale = MatrixScale( scale, scale, scale );
	MATRIX matrixX = MatrixRotationX( FROM_ANGLE( xrot ) );
	MATRIX matrixZ = MatrixRotationZ( FROM_ANGLE( zrot ) );

	// rotate and translate
	MATRIX mx = MatrixRotationY( FROM_ANGLE( yrot ) );					//rotate
	mx = MatrixMultiply( mx, matrixX );
	mx = MatrixMultiply( mx, matrixZ );
	mx = MatrixMultiply( mx, mtxScale );								//scale this thing up

	mx = MatrixMultiply( mx, MatrixTranslation( xpos, ypos, zpos ) ); //translate into place

	//put this matrix in the list
	mtxBox.push_back( mx );
}
Example #4
0
//==============
// arglの初期化
//==============
bool cARTK::initArgl( void )
{
	// arglをOpenGLの現在のコンテキスト用にセットアップ
	if( (m_pArglSettings = arglSetupForCurrentContext()) == NULL )
	{
		ErrorMessage( "arglSetupForCurrentContext() returned error.\n" );
		return false;
	}

	double	c = cos( 3.1515926 * 0.5 );
	double	s = sin( 3.1515926 * 0.5 );
	m_dmatRotX[ 0] = 1.0; m_dmatRotX[ 1] = 0.0; m_dmatRotX[ 2] = 0.0; m_dmatRotX[ 3] = 0.0;
	m_dmatRotX[ 4] = 0.0; m_dmatRotX[ 5] =   c; m_dmatRotX[ 6] =   s; m_dmatRotX[ 7] = 0.0;
	m_dmatRotX[ 8] = 0.0; m_dmatRotX[ 9] =  -s; m_dmatRotX[10] =   c; m_dmatRotX[11] = 0.0;
	m_dmatRotX[12] = 0.0; m_dmatRotX[13] = 0.0; m_dmatRotX[14] = 0.0; m_dmatRotX[15] = 1.0;

	MatrixRotationX( m_matRotX, -3.1415926f * 0.5f );

	return true;
}
Example #5
0
void BoxBrowser::UpdateCamera()
{
	//adjust the camera a little bit
	MATRIX cam = MatrixRotationX( FROM_ANGLE( -3.5 ) );
	cam = MatrixMultiply( cam, MatrixTranslation( 0, camY, 0 ) );
	tiny3d_SetProjectionMatrix( &cam );
	if( !--camDelay )
	{
		camDelay = 3;
		camY += camdif;
		if( camY == 10 )
		{
			camdif = -1;
		}
		else if( !camY )
		{
			camdif = 1;
		}
	}
}
Example #6
0
void ImportPLYFormat(Octree* octree, const char* const filename, const int startbyte, const int vertices)
{
printf(filename);
	FILE *file = fopen(filename, "rb");
	
	// obtain file size:
	fseek(file , 0 , SEEK_END);
	long filesize = ftell(file);
	rewind(file);
  
	long pos = 0;
	long lastprogess = 0;
	long pointCount = 0;
	
	VECTOR3 min;
	VECTOR3 max;
	bool init = true;

	uint8_t byte;
	for (int i = 0; i < startbyte; ++i)
	{
		fread(&byte, sizeof(uint8_t), 1, file);
		printf("%c", byte);
	}
	
	VECTOR3 normal;
	MATRIX m;
	MatrixRotationX(m, M_PI_2);
		
	int i = 0;
	while (i < vertices)//((pos < filesize) && (lastprogess < 1))
	{
		++i;
		
		WVSPoint p;
		p.radius = 0.001f;

		fread(&p.position, sizeof(VECTOR3), 1, file);
		fread(&normal, sizeof(VECTOR3), 1, file);
		
//		uint8_t sevenBitNormal = 0;
//		float_t dot = 0;
//		float_t bestDot = 0;
//		for (uint8_t j=0; j < 128; ++j)
//		{
//			dot =	normal.x * sevenBitNormalMap[3*j+0] + 
//					normal.y * sevenBitNormalMap[3*j+1] +
//					normal.z * sevenBitNormalMap[3*j+2];
//			
//			if (dot > bestDot)
//			{
//				bestDot = dot;
//				sevenBitNormal = j;
//			}
//		}
//		assert(sevenBitNormal < 128);
//		p.normalIndex = sevenBitNormal;
	
		fread(&p.color, sizeof(RGBColor), 1, file);
		fseek(file, 1, SEEK_CUR);
		
		if (startbyte == 341)
		{
			p.position.x *= 25;
			p.position.y *= 25;
			p.position.z *= 25;
			
			p.position.z += 2500;
		}
		else {
			p.position.x *= 5;
			p.position.y *= 5;
			p.position.z *= 5;
		}

		
		if (init) {
			init = false;
			min = p.position;
			max = p.position;
		}
		
		if (min.x > p.position.x) min.x = p.position.x; 
		if (min.y > p.position.y) min.y = p.position.y; 
		if (min.z > p.position.z) min.z = p.position.z; 
		
		if (max.x < p.position.x) max.x = p.position.x; 
		if (max.y < p.position.y) max.y = p.position.y; 
		if (max.z < p.position.z) max.z = p.position.z; 
		
		octree->addPoint(&p);
		pointCount++;
		
		pos = ftell(file);
		
		long progress = long(100.0f * float(pos) / float(filesize));
		if ((progress > lastprogess) && (progress % 2 == 0))
		{
			lastprogess = progress;
			printf("%.0f %%\n", 100.0f * float(pos) / float(filesize));
		}
	}

	fclose(file);
	
	printf("%li points loaded.\n\nBounding Box:\n", pointCount);
	PRINT_VECTOR3(min);
	PRINT_VECTOR3(max);
	
}