All pastes #223247 Raw Edit

Anonymous

public text v1 · immutable
#223247 ·published 2006-10-26 20:37 UTC
rendered paste body
	// Create a test sphere
	csVector3 radius (3.396 , 3.396, 3.396);
	csVector3 center ( 0,0,0);
	Create_Sphere( "100000" , radius, center, "grid.jpg" , csVector3 (1,0,0) );



bool AppTest::Create_Sphere(const char *name, csVector3 radius,csVector3 center,const char *matname , csVector3 pos )

   {

  // Create the ball mesh factory.
  csRef<iMeshFactoryWrapper> ballFact = engine->CreateMeshFactory(
  	"crystalspace.mesh.object.genmesh", "ballFact");
  if (ballFact == 0)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
      "SolApp",
      "Error creating mesh object factory!");
  }

  csRef<iGeneralFactoryState> gmstate = scfQueryInterface<iGeneralFactoryState> (
  	ballFact->GetMeshObjectFactory ());

  csEllipsoid ellips (center, radius);
  gmstate->GenerateSphere (ellips, 64);
  // Create the mesh.
  iSector* room = engine->FindSector("system" , 0 );
  csRef<iMeshWrapper> mesh (engine->CreateMeshWrapper (ballFact, name , room));
	iMovable* movable = mesh->GetMovable();
	movable->SetPosition ( pos );
  iMaterialWrapper* mat = engine->GetMaterialList ()->FindByName ("gstar");
	printf ("MAterial Count:%d\n" , engine->GetMaterialList ()-> GetCount() );
  mesh->GetMeshObject ()->SetMaterialWrapper (mat);


  return true;
}




void Body::Load_Texture(AppTest* app, std::string filename, std::string mat_name ) { 
	csColor* transp;
	iTextureList* texturelist;

	csRef<iEngine> engine = app->GetEngine();
	if (!engine) printf("Star::Load_Texture: Failed to locate iEngine renderer!");
	
	transp = new csColor;
	transp->Set(1,0,1);
	
	// Create a Texture from a image file on VFS
	if ( !engine->CreateTexture ( mat_name.c_str() , filename.c_str() , transp , CS_TEXTURE_3D ) ) {
			printf("Star::Load_Texture: Failed loading Texture %s\n" , filename.c_str() );
 	}
	// Use the texture to create a Material 
	texturelist = engine->GetTextureList();
	engine->CreateMaterial ( mat_name.c_str() , texturelist->FindByName(mat_name.c_str())	); 

	iMaterialWrapper* mat = engine->GetMaterialList ()->FindByName (mat_name.c_str() );

	 if ( !mat ) { printf(" Star::Load_Texture: Material %s not found!\n",mat_name.c_str() ); } 
	// Now add the texture to the mesh
	if (!mesh->GetMeshObject ()->SetMaterialWrapper (mat))
				printf ("Body::Load_Texture: Error SetMaterialWrapper failed\n") ;
		
}