ScenePreviewControl::~ScenePreviewControl()
{
    ReleaseScene();

    SafeRelease(editorScene);
    SafeRelease(cameraController);
}
// Calls previously set release function and deletes rendering context.
// lpParam - pointer to whatever you want
void COpenGLControl::ReleaseOpenGLControl(LPVOID lpParam)
{
	if(ReleaseScene)ReleaseScene(lpParam);

	wglMakeCurrent(NULL, NULL);
	wglDeleteContext(hRC);
	ReleaseDC(*hWnd, hDC);

	hWnd = NULL;
}
Exemplo n.º 3
0
void ReleaseMultiScene(EERIE_MULTI3DSCENE * ms) {
	
	if(ms) {
		for(long i = 0; i < ms->nb_scenes; i++) {
			ReleaseScene(ms->scenes[i]);
			ms->scenes[i] = NULL;
		}
	}
	
	free(ms);
}
int32 ScenePreviewControl::OpenScene(const FilePath &pathToFile)
{
    ReleaseScene();
    RecreateScene();
    
    int32 retError = SceneFileV2::ERROR_NO_ERROR;
    if(pathToFile.IsEqualToExtension(".sce"))
    {
        SceneFile *file = new SceneFile();
        file->SetDebugLog(true);
        if(!file->LoadScene(pathToFile, editorScene))
        {
            retError = ERROR_CANNOT_OPEN_FILE;
        }
        
        SafeRelease(file);
    }
    else if(pathToFile.IsEqualToExtension(".sc2"))
    {
        SceneFileV2 *file = new SceneFileV2();
        file->EnableDebugLog(true);
        retError = file->LoadScene(pathToFile, editorScene);
        SafeRelease(file);
    }
    else
    {
        retError = ERROR_WRONG_EXTENSION;
    }
    
    if(SceneFileV2::ERROR_NO_ERROR == retError)
    {
        rootNode = editorScene->GetRootNode(pathToFile);
        if(rootNode)
        {
            currentScenePath = pathToFile;
            editorScene->AddNode(rootNode);
            
            needSetCamera = true;
            Camera *cam = editorScene->GetCamera(0);
            if(!cam)
            {
                Camera * cam = new Camera();
                //cam->SetDebugFlags(Entity::DEBUG_DRAW_ALL);
                cam->SetUp(Vector3(0.0f, 0.0f, 1.0f));
                cam->SetPosition(Vector3(0.0f, 0.0f, 0.0f));
                cam->SetTarget(Vector3(0.0f, 1.0f, 0.0f));
                
                cam->SetupPerspective(70.0f, 320.0f / 480.0f, 1.0f, 5000.0f); 
                

                
                ScopedPtr<Entity> node(new Entity());
                node->SetName("preview-camera");
                node->AddComponent(new CameraComponent(cam));
                editorScene->AddNode(node);
                editorScene->AddCamera(cam);
                editorScene->SetCurrentCamera(cam);
                cameraController->SetScene(editorScene);
                
                SafeRelease(cam);
                
                sceCamera = false;
            }
            else
            {
                sceCamera = true;
            }
        }
    }
    
    SceneValidator::Instance()->ValidateSceneAndShowErrors(editorScene);
    
    return retError;
}
Exemplo n.º 5
0
//*********************************************************************************
// Read OBJ file from disk
//
SCENE *ReadOBJFile(const char *sFileName, bool bGenerateMissingNormals)
{
	FILE *pScene;
	char pcLine[512], pcMaterialLib[MAX_PATH], pcMaterialName[64];
	const char *pcArgs;
	TAG_NAME Tag;
	SCENE *pS = NULL;
	unsigned int i, j;
	float fL;
	VERTEX FaceCenter, AB, AC, N;

	//--- Check parameters

	if (!sFileName)
		return(NULL);

	//--- Open scene file

	//pScene = fopen(sFileName, "r");

	fopen_s(&pScene, sFileName, "r");

	if (!pScene)
		return(NULL);

	//--- Create scene object

	pS = new SCENE;
	if (!pS)
		goto Exit;

	pS->pObjects = NULL;
	pS->u32ObjectsCount = 0;

	pS->pVertices = NULL;
	pS->u32VerticesCount = 0;
		
	pS->pNormals = NULL;
	pS->u32NormalsCount = 0;

	pS->pUV = NULL;
	pS->u32UVCount = 0;

	pS->pFaces = NULL;
	pS->u32FacesCount = 0;

	pS->pMaterials = NULL;
	pS->u32MaterialsCount = 0;

	//--- Parse scene file, first pass

	while (fgets(pcLine, sizeof(pcLine), pScene))
	{
		//--- Parse file line

		pcArgs = TokenizeFileLine(pcLine, &Tag);

		//--- Process file line

		switch (Tag)
		{
		case TAGNAME_VERTEX:
			//--- Count vertex

			++pS->u32VerticesCount;
			break;

		case TAGNAME_NORMAL:
			//--- Count normal

			++pS->u32NormalsCount;
			break;

		case TAGNAME_TEXTURECOORDS:
			//--- Count UV pair

			++pS->u32UVCount;
			break;

		case TAGNAME_FACE3:
			//--- Count face

			++pS->u32FacesCount;
			break;

		case TAGNAME_FACE4:
			//--- Count 2 faces

			pS->u32FacesCount += 2;
			break;

		case TAGNAME_OBJECT:
			//--- Count object

			++pS->u32ObjectsCount;
			break;

		case TAGNAME_MATLIB:
			//--- Parse materials library

			ExtractParameters(Tag, pcArgs, pcMaterialLib);
			ParseMaterialLibrary(pS, sFileName, pcMaterialLib, TRUE);
			break;
		}
	}

	if (!pS->u32VerticesCount || !pS->u32FacesCount)
	{
		ReleaseScene(pS);
		pS = NULL;
		goto Exit;
	}

	//--- Allocate scene buffers

	if (bGenerateMissingNormals && (pS->u32NormalsCount == 0))
		pS->u32NormalsCount = pS->u32VerticesCount;
	else
		bGenerateMissingNormals = false;
	
	pS->pVertices = new VERTEX[pS->u32VerticesCount + pS->u32NormalsCount];
	if (!pS->pVertices)
	{
		ReleaseScene(pS);
		pS = NULL;
		goto Exit;
	}

	if (pS->u32NormalsCount)
		pS->pNormals = pS->pVertices + pS->u32VerticesCount;
	else
		pS->pNormals = NULL;

	if (pS->u32UVCount)
	{
		pS->pUV = new TEXTURE_COORDS[pS->u32UVCount];
		if (!pS->pUV)
		{
			ReleaseScene(pS);
			pS = NULL;
			goto Exit;
		}
	}

	pS->pFaces = new FACE[pS->u32FacesCount];
	if (!pS->pFaces)
	{
		ReleaseScene(pS);
		pS = NULL;
		goto Exit;
	}

	pS->pMaterials = new MATERIAL[pS->u32MaterialsCount];
	if (!pS->pMaterials)
	{
		ReleaseScene(pS);
		pS = NULL;
		goto Exit;
	}
	memset(pS->pMaterials, 0, sizeof(MATERIAL)*pS->u32MaterialsCount);

	//--- Init objects table

	pS->pObjects = new OBJECT[pS->u32ObjectsCount+1];
	if (!pS->pObjects)
	{
		ReleaseScene(pS);
		pS = NULL;
		goto Exit;
	}

	pS->pObjects[0].u32FirstFace = 0;
	pS->pObjects[0].u32FacesCount = 0;
	pS->pObjects[0].u32Material = 0xFFFFFFFF;

	for (i=0; i<=pS->u32ObjectsCount; ++i)
	{
		memset(&pS->pObjects[i].Center, 0, sizeof(pS->pObjects[i].Center));

		memset(pS->pObjects[i].pfMatrix, 0, sizeof(pS->pObjects[i].pfMatrix));
		pS->pObjects[i].pfMatrix[0] = pS->pObjects[i].pfMatrix[5] = pS->pObjects[i].pfMatrix[10] = pS->pObjects[i].pfMatrix[15] = 1;
	}

	//--- Reparse scene file

	pS->u32VerticesCount = pS->u32NormalsCount = pS->u32UVCount = pS->u32FacesCount = pS->u32ObjectsCount = pS->u32MaterialsCount = 0;

	fseek(pScene, 0, SEEK_SET);
	while (fgets(pcLine, sizeof(pcLine), pScene))
	{
		//--- Parse file line

		pcArgs = TokenizeFileLine(pcLine, &Tag);

		//--- Process file line

		switch (Tag)
		{
		case TAGNAME_VERTEX:
			//--- Retrieve vertex position

			ExtractParameters(Tag, pcArgs, &pS->pVertices[pS->u32VerticesCount++]);
			break;

		case TAGNAME_NORMAL:
			//--- Retrieve vertex normal

			ExtractParameters(Tag, pcArgs, &pS->pNormals[pS->u32NormalsCount++]);
			break;

		case TAGNAME_TEXTURECOORDS:
			//--- Retrieve UV coordinates

			ExtractParameters(Tag, pcArgs, &pS->pUV[pS->u32UVCount++]);
			break;

		case TAGNAME_FACE3:
			//--- Retrieve face description

			ExtractParameters(Tag, pcArgs, &pS->pFaces[pS->u32FacesCount++]);
			(pS->pObjects[pS->u32ObjectsCount].u32FacesCount)++;

			assert(!pS->u32NormalsCount || pS->pFaces[pS->u32FacesCount-1].pu32Normals[0] < pS->u32NormalsCount);
			assert(!pS->u32NormalsCount || pS->pFaces[pS->u32FacesCount-1].pu32Normals[1] < pS->u32NormalsCount);
			assert(!pS->u32NormalsCount || pS->pFaces[pS->u32FacesCount-1].pu32Normals[2] < pS->u32NormalsCount);

			assert(!pS->u32UVCount || pS->pFaces[pS->u32FacesCount-1].pu32UV[0] < pS->u32UVCount);
			assert(!pS->u32UVCount || pS->pFaces[pS->u32FacesCount-1].pu32UV[1] < pS->u32UVCount);
			assert(!pS->u32UVCount || pS->pFaces[pS->u32FacesCount-1].pu32UV[2] < pS->u32UVCount);
			break;

		case TAGNAME_FACE4:
			//--- Retrieve faces description

			ExtractParameters(Tag, pcArgs, &pS->pFaces[pS->u32FacesCount]);
			pS->u32FacesCount += 2;
			pS->pObjects[pS->u32ObjectsCount].u32FacesCount += 2;

			assert(!pS->u32NormalsCount || pS->pFaces[pS->u32FacesCount-1].pu32Normals[0] < pS->u32NormalsCount);
			assert(!pS->u32NormalsCount || pS->pFaces[pS->u32FacesCount-1].pu32Normals[1] < pS->u32NormalsCount);
			assert(!pS->u32NormalsCount || pS->pFaces[pS->u32FacesCount-1].pu32Normals[2] < pS->u32NormalsCount);

			assert(!pS->u32UVCount || pS->pFaces[pS->u32FacesCount-1].pu32UV[0] < pS->u32UVCount);
			assert(!pS->u32UVCount || pS->pFaces[pS->u32FacesCount-1].pu32UV[1] < pS->u32UVCount);
			assert(!pS->u32UVCount || pS->pFaces[pS->u32FacesCount-1].pu32UV[2] < pS->u32UVCount);

			assert(!pS->u32NormalsCount || pS->pFaces[pS->u32FacesCount-2].pu32Normals[0] < pS->u32NormalsCount);
			assert(!pS->u32NormalsCount || pS->pFaces[pS->u32FacesCount-2].pu32Normals[1] < pS->u32NormalsCount);
			assert(!pS->u32NormalsCount || pS->pFaces[pS->u32FacesCount-2].pu32Normals[2] < pS->u32NormalsCount);

			assert(!pS->u32UVCount || pS->pFaces[pS->u32FacesCount-2].pu32UV[0] < pS->u32UVCount);
			assert(!pS->u32UVCount || pS->pFaces[pS->u32FacesCount-2].pu32UV[1] < pS->u32UVCount);
			assert(!pS->u32UVCount || pS->pFaces[pS->u32FacesCount-2].pu32UV[2] < pS->u32UVCount);
			break;

		case TAGNAME_OBJECT:
			//--- Switch to next object

			pS->u32ObjectsCount++;
			pS->pObjects[pS->u32ObjectsCount].u32FirstFace = pS->u32FacesCount;
			pS->pObjects[pS->u32ObjectsCount].u32FacesCount = 0;

			//--- Retrieve material parameters

			ExtractParameters(Tag, pcArgs, pcMaterialName);

			//--- Look for material

			pS->pObjects[pS->u32ObjectsCount].u32Material = 0;
			for (; pS->pObjects[pS->u32ObjectsCount].u32Material<pS->u32MaterialsCount; pS->pObjects[pS->u32ObjectsCount].u32Material++)
			{
				if (!_stricmp(pS->pMaterials[pS->pObjects[pS->u32ObjectsCount].u32Material].pcName, pcMaterialName))
					break;
			}
	
			if (pS->pObjects[pS->u32ObjectsCount].u32Material >= pS->u32MaterialsCount)
				pS->pObjects[pS->u32ObjectsCount].u32Material = 0xFFFFFFFF;
			break;

		case TAGNAME_MATLIB:
			//--- Parse materials library

			ExtractParameters(Tag, pcArgs, pcMaterialLib);
			ParseMaterialLibrary(pS, sFileName, pcMaterialLib, FALSE);
			break;
		}
	}

	pS->u32ObjectsCount++;

	//--- Initialize normals

	if (bGenerateMissingNormals)
	{
		pS->u32NormalsCount = pS->u32VerticesCount;

		for (i=0; i<pS->u32NormalsCount; ++i)
			pS->pNormals[i].fX = pS->pNormals[i].fY = pS->pNormals[i].fZ = 0;

		for (i=0; i<pS->u32FacesCount; ++i)
		{
			//--- Update normals indices

			pS->pFaces[i].pu32Normals[0] = pS->pFaces[i].pu32Vertices[0];
			pS->pFaces[i].pu32Normals[1] = pS->pFaces[i].pu32Vertices[1];
			pS->pFaces[i].pu32Normals[2] = pS->pFaces[i].pu32Vertices[2];

			//--- Compute face normal

			AB.fX = pS->pVertices[pS->pFaces[i].pu32Vertices[1]].fX - pS->pVertices[pS->pFaces[i].pu32Vertices[0]].fX;
			AB.fY = pS->pVertices[pS->pFaces[i].pu32Vertices[1]].fY - pS->pVertices[pS->pFaces[i].pu32Vertices[0]].fY;
			AB.fZ = pS->pVertices[pS->pFaces[i].pu32Vertices[1]].fZ - pS->pVertices[pS->pFaces[i].pu32Vertices[0]].fZ;

			AC.fX = pS->pVertices[pS->pFaces[i].pu32Vertices[2]].fX - pS->pVertices[pS->pFaces[i].pu32Vertices[0]].fX;
			AC.fY = pS->pVertices[pS->pFaces[i].pu32Vertices[2]].fY - pS->pVertices[pS->pFaces[i].pu32Vertices[0]].fY;
			AC.fZ = pS->pVertices[pS->pFaces[i].pu32Vertices[2]].fZ - pS->pVertices[pS->pFaces[i].pu32Vertices[0]].fZ;

			N.fX = AB.fY*AC.fZ - AC.fY*AB.fZ;
			N.fY = AC.fX*AB.fZ - AB.fX*AC.fZ;
			N.fZ = AB.fX*AC.fY - AC.fX*AB.fY;

			//--- Normalize

			fL = sqrtf(N.fX*N.fX + N.fY*N.fY + N.fZ*N.fZ);
			if (fL > 0)
			{
				fL = 1.f/fL;
				N.fX *= fL;
				N.fY *= fL;
				N.fZ *= fL;
			}

			//--- Store for contribution to face's vertices

			pS->pNormals[pS->pFaces[i].pu32Normals[0]].fX += N.fX;
			pS->pNormals[pS->pFaces[i].pu32Normals[0]].fY += N.fY;
			pS->pNormals[pS->pFaces[i].pu32Normals[0]].fZ += N.fZ;

			pS->pNormals[pS->pFaces[i].pu32Normals[1]].fX += N.fX;
			pS->pNormals[pS->pFaces[i].pu32Normals[1]].fY += N.fY;
			pS->pNormals[pS->pFaces[i].pu32Normals[1]].fZ += N.fZ;

			pS->pNormals[pS->pFaces[i].pu32Normals[2]].fX += N.fX;
			pS->pNormals[pS->pFaces[i].pu32Normals[2]].fY += N.fY;
			pS->pNormals[pS->pFaces[i].pu32Normals[2]].fZ += N.fZ;
		}
	
		//--- Renormalize

		for (i=0; i<pS->u32NormalsCount; ++i)
		{
			fL = sqrtf(pS->pNormals[i].fX*pS->pNormals[i].fX + pS->pNormals[i].fY*pS->pNormals[i].fY + pS->pNormals[i].fZ*pS->pNormals[i].fZ);
			if (fL > 0)
			{
				fL = 1.f/fL;
				pS->pNormals[i].fX *= fL;
				pS->pNormals[i].fY *= fL;
				pS->pNormals[i].fZ *= fL;
			}
		}
	}

	//--- Compute centers for all objects

	for (i=0; i<pS->u32ObjectsCount; ++i)
	{
		for (j=0; j<pS->pObjects[i].u32FacesCount; ++j)
		{
			//--- Compute face center

			FaceCenter.fX = pS->pVertices[pS->pFaces[pS->pObjects[i].u32FirstFace + j].pu32Vertices[0]].fX;
			FaceCenter.fX+= pS->pVertices[pS->pFaces[pS->pObjects[i].u32FirstFace + j].pu32Vertices[1]].fX;
			FaceCenter.fX += pS->pVertices[pS->pFaces[pS->pObjects[i].u32FirstFace + j].pu32Vertices[2]].fX;

			FaceCenter.fY = pS->pVertices[pS->pFaces[pS->pObjects[i].u32FirstFace + j].pu32Vertices[0]].fY;
			FaceCenter.fY += pS->pVertices[pS->pFaces[pS->pObjects[i].u32FirstFace + j].pu32Vertices[1]].fY;
			FaceCenter.fY += pS->pVertices[pS->pFaces[pS->pObjects[i].u32FirstFace + j].pu32Vertices[2]].fY;

			FaceCenter.fZ = pS->pVertices[pS->pFaces[pS->pObjects[i].u32FirstFace + j].pu32Vertices[0]].fZ;
			FaceCenter.fZ += pS->pVertices[pS->pFaces[pS->pObjects[i].u32FirstFace + j].pu32Vertices[1]].fZ;
			FaceCenter.fZ += pS->pVertices[pS->pFaces[pS->pObjects[i].u32FirstFace + j].pu32Vertices[2]].fZ;

			pS->pObjects[i].Center.fX += FaceCenter.fX/3;
			pS->pObjects[i].Center.fY += FaceCenter.fY/3;
			pS->pObjects[i].Center.fZ += FaceCenter.fZ/3;
		}

		pS->pObjects[i].Center.fX /= pS->pObjects[i].u32FacesCount;
		pS->pObjects[i].Center.fY /= pS->pObjects[i].u32FacesCount;
		pS->pObjects[i].Center.fZ /= pS->pObjects[i].u32FacesCount;
	}

Exit:

	//--- Close scene file

	fclose(pScene);

	return(pS);
}
Exemplo n.º 6
0
void GSceneSelector::ChangeSceneCheck()
{
	gstring& changeName = GScene::GetChangeSceneName();
	if( changeName.empty() == false )
	{
		CCDirector* pDirector = CCDirector::sharedDirector();
		GScene* changeScene = NULL;
		if( changeName == GScene::SCENENAME_START )
		{
			if( mpLoadingScene == NULL )
			{
				SetLoadingScene();
				return;
			}
			ReleaseScene();
			changeScene = CreateStartScene();
		}
		else if( changeName == GScene::SCENENAME_STATE )
		{
			if( mPlayOpening )
			{
				mPlayOpening = false;
				CCScene* openingScene = GOpeningScene::CreateLoadingScene( 0 );
				if( openingScene )
				{
					pDirector->replaceScene( openingScene );
					changeName.clear();
				}
				return;
			}			
			else if( mpCurrentScene->GetSceneName() == GScene::SCENENAME_SELECTSTAGE )
			{
				if( mpStateScene )
					changeScene = mpStateScene;
				else
					changeScene = CreateStateScene();
			}
			else
			{
//				if( mpCurrentScene->GetSceneName() == GScene::SCENENAME_GAME )
//				{
//					if( mpGameScene->IsWinGame() )
//					{
//						GPlayingData* playing = GPlayingDataManager::GetSingleton()->GetPlayingPlayerData();
//						GPlayingData::ModeInfo& info = playing->GetCurrentModeInfo();
//						info.mLastClearStage += 1;
//						GPlayingDataManager::GetSingleton()->SaveData();
//					}
//				}
				if( mpLoadingScene == NULL )
				{
					SetLoadingScene();
					return;
				}
				ReleaseScene();
				changeScene = CreateStateScene();
			}
		}
		else if( changeName == GScene::SCENENAME_SELECTSTAGE )
		{
			
			if( mpCurrentScene->GetSceneName() == GScene::SCENENAME_STATE )
			{
				if( mpSelectStageScene )
					changeScene = mpSelectStageScene;
				else
					changeScene = CreateSelectStageScene();
			}
			else
			{
				if( mpLoadingScene == NULL )
				{
					SetLoadingScene();
					return;
				}
				ReleaseScene();
				changeScene = CreateSelectStageScene();
			}
		}
		else if( changeName == GScene::SCENENAME_GAME )
		{
			if( mpLoadingScene == NULL )
			{
				SetLoadingScene();
				return;
			}
			ReleaseScene();
			changeScene = CreateGameScene();
		}
		
		SetCurrentScene( changeScene );
		if( changeScene )
			pDirector->replaceScene( changeScene );
		mpLoadingScene = NULL;
		changeName.clear();
	}
}
JNIEXPORT void JNICALL Java_net_airtheva_assdroid_Native_ReleaseScene(JNIEnv* env, jclass thiz, jint jSceneKey)
{
	ReleaseScene(jSceneKey);
}