|
From: Charles L. <cn...@us...> - 2005-12-18 02:47:04
|
Update of /cvsroot/hgengine/Mercury/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5961 Modified Files: Mercury.dsp Added Files: MercuryShapes.cpp MercuryShapes.h Log Message: Add Mercury Shapes --- NEW FILE: MercuryShapes.cpp --- #include "MercuryShapes.h" #include <iostream> MercuryShape::MercuryShape() : MercuryModel() { m_material = new MercuryMaterial; AddMaterial( m_material ); } MercuryShape::~MercuryShape() { SAFE_DELETE( m_material ); } bool MercuryShape::LoadPNG( const CString & Filename ) { if ( !m_material->m_diffuse_texture.LoadPNG(Filename) ) return false; m_material->m_diffuse.SetA( 1 ); m_material->m_diffuse.SetB( 1 ); m_material->m_diffuse.SetG( 1 ); m_material->m_diffuse.SetR( 1 ); m_material->m_emissive.SetA( 1 ); m_material->m_emissive.SetB( 1 ); m_material->m_emissive.SetG( 1 ); m_material->m_emissive.SetR( 1 ); m_scale.SetX((m_material->m_diffuse_texture.GetWidth() / m_material->m_diffuse_texture.GetDpiX()) * 12); m_scale.SetY((m_material->m_diffuse_texture.GetHeight() / m_material->m_diffuse_texture.GetDpiY()) * 12); return true; } void MercuryShape::SetMaterial( const MercuryMaterial & mat ) { (*m_material) = mat; } void MercuryShape::MakeSphere( int Stacks, int Slices ) { for ( int i = 0; i < m_meshes.size(); i++ ) { SAFE_DELETE(m_meshes[i]); } m_meshes.resize(1); m_meshes[0] = new MercuryMesh; m_hidden = false; m_meshes[0]->SetMaterial( 0 ); for ( int y = 0; y < Stacks; y++ ) for ( int x = 0; x < Slices; x++ ) { float dY = 6.2831853072f / float(Stacks)/2; float dX = 6.2831853072f / float(Slices); MercuryVert * p1 = new MercuryVert; MercuryVert * p2 = new MercuryVert; MercuryVert * p3 = new MercuryVert; MercuryVert * p4 = new MercuryVert; MercuryVert * p5 = new MercuryVert; MercuryVert * p6 = new MercuryVert; p1->x = COS( dX * x ) * SIN( dY * y ); p1->y = SIN( dX * x ) * SIN( dY * y ); p1->z = COS( dY * y ); p1->SetV( float( y ) / Stacks ); p1->SetU( float( x ) / Slices ); p2->x = COS( dX * ( x + 1 ) ) * SIN( dY * y ); p2->y = SIN( dX * ( x + 1 ) ) * SIN( dY * y ); p2->z = COS( dY * y ); p2->SetV( float( y ) / Stacks ); p2->SetU( float( x + 1 ) / Slices ); p3->x = COS( dX * x ) * SIN( dY * ( y + 1 ) ); p3->y = SIN( dX * x ) * SIN( dY * ( y + 1 ) ); p3->z = COS( dX * ( y + 1 ) ); p3->SetV( float( y + 1 ) / Stacks ); p3->SetU( float( x ) / Slices ); p4->x = COS( dX * ( x + 1 ) ) * SIN( dY * y ); p4->y = SIN( dX * ( x + 1 ) ) * SIN( dY * y ); p4->z = COS( dY * y ); p4->SetV( float( y ) / Stacks ); p4->SetU( float( x + 1 ) / Slices ); p5->x = COS( dX * x ) * SIN( dY * ( y + 1 ) ); p5->y = SIN( dX * x ) * SIN( dY * ( y + 1 ) ); p5->z = COS( dX * ( y + 1 ) ); p5->SetV( float( y + 1 ) / Stacks ); p5->SetU( float( x ) / Slices ); p6->x = COS( dX * ( x + 1 ) ) * SIN( dY * ( y + 1 ) ); p6->y = SIN( dX * ( x + 1 ) ) * SIN( dY * ( y + 1 ) ); p6->z = COS( dX * ( y + 1 ) ); p6->SetV( float( y + 1 ) / Stacks ); p6->SetU( float( x + 1 ) / Slices ); MercuryPoly * l = new MercuryPoly; l->AddVert( p2 ); l->AddVert( p1 ); l->AddVert( p3 ); m_meshes[0]->AddPoly( l ); l = new MercuryPoly; l->AddVert( p4 ); l->AddVert( p5 ); l->AddVert( p6 ); m_meshes[0]->AddPoly( l ); } cout<<"Normal time."<<endl; m_meshes[0]->CalculateVertexNormals(); } void MercuryShape::MakeSprite( ) { for ( int i = 0; i < m_meshes.size(); i++ ) { SAFE_DELETE(m_meshes[i]); } m_meshes.resize(1); m_meshes[0] = new MercuryMesh; m_hidden = false; m_meshes[0]->SetMaterial( 0 ); MercuryVert * p1 = new MercuryVert; MercuryVert * p2 = new MercuryVert; MercuryVert * p3 = new MercuryVert; MercuryVert * p4 = new MercuryVert; MercuryVert * p5 = new MercuryVert; MercuryVert * p6 = new MercuryVert; p1->x = -0.5f; p1->y = -0.5f; p1->z = 0; p1->SetU( 0 ); p1->SetV( 0 ); p2->x = -0.5f; p2->y = 0.5f; p2->z = 0; p2->SetU( 0 ); p2->SetV( 1 ); p3->x = 0.5f; p3->y = -0.5f; p3->z = 0; p3->SetU( 1 ); p3->SetV( 0 ); p4->x = 0.5f; p4->y = -0.5f; p4->z = 0; p4->SetU( 1 ); p4->SetV( 0 ); p5->x = -0.5f; p5->y = 0.5f; p5->z = 0; p5->SetU( 0 ); p5->SetV( 1 ); p6->x = 0.5f; p6->y = 0.5f; p6->z = 0; p6->SetU( 1 ); p6->SetV( 1 ); MercuryPoly * l = new MercuryPoly; l->AddVert( p2 ); l->AddVert( p1 ); l->AddVert( p3 ); m_meshes[0]->AddPoly( l ); l = new MercuryPoly; l->AddVert( p5 ); l->AddVert( p4 ); l->AddVert( p6 ); m_meshes[0]->AddPoly( l ); m_meshes[0]->CalculateVertexNormals(); } void MercuryShape::MakeCylinder( int Stacks, int Slices ) { int i,y,x,z; for ( i = 0; i < m_meshes.size(); i++ ) { SAFE_DELETE(m_meshes[i]); } m_meshes.resize(1); m_meshes[0] = new MercuryMesh; m_hidden = false; m_meshes[0]->SetMaterial( 0 ); int SP2 = Stacks + 2; for ( y = 0; y < Stacks; y++ ) for ( x = 0; x < Slices; x++ ) { float dY = 6.2831853072f / float(Stacks)/2; float dX = 6.2831853072f / float(Slices); MercuryVert * p1 = new MercuryVert; MercuryVert * p2 = new MercuryVert; MercuryVert * p3 = new MercuryVert; MercuryVert * p4 = new MercuryVert; MercuryVert * p5 = new MercuryVert; MercuryVert * p6 = new MercuryVert; p1->x = COS( dX * x ); p1->y = SIN( dX * x ); p1->z = ( float( y ) / Stacks ) - 0.5f; p1->SetV( float( y + 1 ) / SP2 ); p1->SetU( float( x ) / Slices ); p2->x = COS( dX * ( x + 1 ) ); p2->y = SIN( dX * ( x + 1 ) ); p2->z = ( float( y ) / Stacks ) - 0.5f; p2->SetV( float( y + 1 ) / SP2 ); p2->SetU( float( x + 1 ) / Slices ); p3->x = COS( dX * x ); p3->y = SIN( dX * x ); p3->z = ( float( y + 1 ) / Stacks ) - 0.5f; p3->SetV( float( y + 2 ) / SP2 ); p3->SetU( float( x ) / Slices ); p4->x = COS( dX * ( x + 1 ) ); p4->y = SIN( dX * ( x + 1 ) ); p4->z = ( float( y ) / Stacks ) - 0.5f; p4->SetV( float( y + 1 ) / SP2 ); p4->SetU( float( x + 1 ) / Slices ); p5->x = COS( dX * x ); p5->y = SIN( dX * x ); p5->z = ( float( y + 1 ) / Stacks ) - 0.5f; p5->SetV( float( y + 2 ) / SP2 ); p5->SetU( float( x ) / Slices ); p6->x = COS( dX * ( x + 1 ) ); p6->y = SIN( dX * ( x + 1 ) ); p6->z = ( float( y + 1 ) / Stacks ) - 0.5f; p6->SetV( float( y + 2 ) / SP2 ); p6->SetU( float( x + 1 ) / Slices ); MercuryPoly * l = new MercuryPoly; l->AddVert( p1 ); l->AddVert( p2 ); l->AddVert( p3 ); m_meshes[0]->AddPoly( l ); l = new MercuryPoly; l->AddVert( p5 ); l->AddVert( p4 ); l->AddVert( p6 ); m_meshes[0]->AddPoly( l ); } for ( z = 0; z < 2; z++ ) for ( x = 0; x < Slices; x++ ) { float dY = 6.2831853072f / float(Stacks)/2; float dX = 6.2831853072f / float(Slices); MercuryVert * p1 = new MercuryVert; MercuryVert * p2 = new MercuryVert; MercuryVert * p3 = new MercuryVert; if ( z == 0 ) { p1->SetV( float( 0 ) / SP2 ); p2->SetV( float( 1 ) / SP2 ); p3->SetV( float( 1 ) / SP2 ); y = 0; } else { p1->SetV( float( Stacks+2 ) / SP2 ); p2->SetV( float( Stacks+1 ) / SP2 ); p3->SetV( float( Stacks+1 ) / SP2 ); y = Stacks; } p1->x = 0; p1->y = 0; p1->z = z - 0.5f; p1->SetU( float( x ) / Slices ); p2->x = COS( dX * ( x + 1 ) ); p2->y = SIN( dX * ( x + 1 ) ); p2->z = z - 0.5f; p2->SetU( float( x + 1 ) / Slices ); p3->x = COS( dX * x ); p3->y = SIN( dX * x ); p3->z = z - 0.5f; p3->SetU( float( x ) / Slices ); MercuryPoly * l = new MercuryPoly; if ( z == 0 ) { l->AddVert( p1 ); l->AddVert( p2 ); l->AddVert( p3 ); } else { l->AddVert( p2 ); l->AddVert( p1 ); l->AddVert( p3 ); } m_meshes[0]->AddPoly( l ); } m_meshes[0]->CalculateVertexNormals(); } void MercuryShape::MakeBox( bool bWholeMap ) { unsigned int i; for ( i = 0; i < m_meshes.size(); i++ ) { SAFE_DELETE(m_meshes[i]); } m_meshes.resize(1); m_meshes[0] = new MercuryMesh; m_hidden = false; m_meshes[0]->SetMaterial( 0 ); for ( i = 0; i < 6; i++ ) { MercuryVert * h[2][2]; for ( int x = 0; x < 2; x++ ) for ( int y = 0; y < 2; y++ ) { int SV = i/3; int RV = i%3; float v1 = SV - 0.5f; float v2 = x - 0.5f; float v3 = y - 0.5f; switch ( RV ) { case 0: h[x][y] = new MercuryVert( v1,v2,v3,x,y); break; case 1: h[x][y] = new MercuryVert( v2,v3,v1,x,y); break; case 2: h[x][y] = new MercuryVert( v3,v1,v2,x,y); break; } } bool bSwapOrder = i / 3; MercuryPoly * l = new MercuryPoly; if ( bSwapOrder ) { l->AddVert( h[0][0] ); l->AddVert( h[1][0] ); l->AddVert( h[0][1] ); } else { l->AddVert( h[0][1] ); l->AddVert( h[1][0] ); l->AddVert( h[0][0] ); } m_meshes[0]->AddPoly( l ); l = new MercuryPoly; if ( bSwapOrder ) { l->AddVert( h[1][0] ); l->AddVert( h[1][1] ); l->AddVert( h[0][1] ); } else { l->AddVert( h[0][1] ); l->AddVert( h[1][1] ); l->AddVert( h[1][0] ); } m_meshes[0]->AddPoly( l ); } m_meshes[0]->CalculateVertexNormals(); } /* * (c) 2005 Charles Lohr * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, and/or sell copies of the Software, and to permit persons to * whom the Software is furnished to do so, provided that the above * copyright notice(s) and this permission notice appear in all copies of * the Software and that both the above copyright notice(s) and this * permission notice appear in supporting documentation. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ --- NEW FILE: MercuryShapes.h --- #ifndef _MERCURY_SHAPES_H #define _MERCURY_SHAPES_H #include "MercuryModel.h" class MercuryShape : public MercuryModel { public: MercuryShape(); virtual ~MercuryShape(); bool LoadPNG( const CString & Filename ); void SetMaterial( const MercuryMaterial & mat ); void LoadModel() { } void MakeSphere( int Stacks=6, int Slices=12 ); void MakeCylinder( int Stacks=6, int Slices=12 ); void MakeSprite( ); void MakeBox( bool bWholeMap = true ); protected: MercuryMaterial * m_material; }; #endif /* * (c) 2005 Charles Lohr * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, and/or sell copies of the Software, and to permit persons to * whom the Software is furnished to do so, provided that the above * copyright notice(s) and this permission notice appear in all copies of * the Software and that both the above copyright notice(s) and this * permission notice appear in supporting documentation. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ Index: Mercury.dsp =================================================================== RCS file: /cvsroot/hgengine/Mercury/src/Mercury.dsp,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** Mercury.dsp 5 Dec 2005 21:27:25 -0000 1.27 --- Mercury.dsp 18 Dec 2005 02:46:52 -0000 1.28 *************** *** 55,59 **** # Begin Special Build Tool IntDir=.\../Release ! TargetDir=\Mercury\Release TargetName=Mercury SOURCE="$(InputPath)" --- 55,59 ---- # Begin Special Build Tool IntDir=.\../Release ! TargetDir=\HGENGINE\Mercury\Release TargetName=Mercury SOURCE="$(InputPath)" *************** *** 88,92 **** # Begin Special Build Tool IntDir=.\../Debug ! TargetDir=\Mercury\Debug TargetName=Mercury SOURCE="$(InputPath)" --- 88,92 ---- # Begin Special Build Tool IntDir=.\../Debug ! TargetDir=\HGENGINE\Mercury\Debug TargetName=Mercury SOURCE="$(InputPath)" *************** *** 121,125 **** # Begin Special Build Tool IntDir=.\../AllIn ! TargetDir=\Mercury\AllIn TargetName=Mercury SOURCE="$(InputPath)" --- 121,125 ---- # Begin Special Build Tool IntDir=.\../AllIn ! TargetDir=\HGENGINE\Mercury\AllIn TargetName=Mercury SOURCE="$(InputPath)" *************** *** 220,223 **** --- 220,227 ---- # Begin Source File + SOURCE=.\MercuryShapes.cpp + # End Source File + # Begin Source File + SOURCE=.\MercurySprite.cpp # End Source File *************** *** 344,347 **** --- 348,355 ---- # Begin Source File + SOURCE=.\MercuryShapes.h + # End Source File + # Begin Source File + SOURCE=.\MercurySprite.h # End Source File |