long UpdateScreenOrientation() { int rot = s3eSurfaceGetInt(S3E_SURFACE_DEVICE_BLIT_DIRECTION); if (rot == S3E_SURFACE_BLIT_DIR_NORMAL) { s_OrientationCompensation.SetIdentity(); } else if (rot == S3E_SURFACE_BLIT_DIR_ROT90) { s_OrientationCompensation.SetRotZ(0x0c00); } else if (rot == S3E_SURFACE_BLIT_DIR_ROT180) { s_OrientationCompensation.SetRotZ(0x800); } else if (rot == S3E_SURFACE_BLIT_DIR_ROT270) { s_OrientationCompensation.SetRotZ(0x400); } return 0; }
void MapBackground::DownloadTiles() { CIwTexture* tx = (CIwTexture*)IwGetResManager()->GetResNamed("logo", IW_GX_RESTYPE_TEXTURE); uint32 w1 = tx->GetWidth(); uint32 h1 = tx->GetHeight(); //static CIwSVec2 uvs[4] = //{ // CIwSVec2(0 << 12, 0 << 12), // CIwSVec2(0 << 12, 1 << 12), // CIwSVec2(1 << 12, 1 << 12), // CIwSVec2(1 << 12, 0 << 12), //}; static CIwSVec2 uvs[4] = { CIwSVec2((0 << 12) + 10, (0 << 12) + 10), CIwSVec2((0 << 12) + 10, (1 << 12) - 10), CIwSVec2((1 << 12) - 10, (1 << 12) - 10), CIwSVec2((1 << 12) - 10, (0 << 12) + 10), }; int w = w1/2; int h = h1/2; int counter = 0; while (true) { IwGetHTTPQueue()->Update(); IwGetNotificationHandler()->Update(); IwGetMultiplayerHandler()->Update(); IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL(); pMat->SetModulateMode(CIwMaterial::MODULATE_NONE); pMat->SetTexture(tx); IwGxSetMaterial(pMat); CIwMat rotMat; rotMat.SetIdentity(); double perCentAngle = (counter / 80.0); iwangle degAng = (iwangle)(IW_GEOM_ONE * perCentAngle); rotMat.SetRotZ(degAng); rotMat.t.z = -0x200; IwGxSetViewMatrix(&rotMat); CIwSVec3* pWSCoords= IW_GX_ALLOC(CIwSVec3, 4); pWSCoords[0].x = -w; pWSCoords[0].y = -h; pWSCoords[1].x = -w; pWSCoords[1].y = h; pWSCoords[2].x = w; pWSCoords[2].y = h; pWSCoords[3].x = w; pWSCoords[3].y = -h; pWSCoords[0].z = pWSCoords[1].z = pWSCoords[2].z = pWSCoords[3].z = 0; if (!g_bInProgress) { MapTile* pNextDownload = GetNextDownload(NULL); if (pNextDownload) { IwGetNotificationHandler()->PushNotification((int)this, pNextDownload->szImageUrl, 10*1000); g_bInProgress = true; LoadMapTileImage(pNextDownload); } else { IwGetNotificationHandler()->ClearNotification((int)this); break; } } IwGxSetVertStreamWorldSpace(pWSCoords, 4); IwGxSetUVStream(uvs); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); IwGetNotificationHandler()->Render(); IwGxFlush(); IwGxSwapBuffers(); s3eDeviceYield(50); counter++; } }
bool MapBackground::Update(bool forceUpdate = false) { if (gDeleteImageUrls.size() > 0) { std::list<MapTile*>::iterator iter = gDeleteImageUrls.begin(); std::list<MapTile*> delList; while (iter != gDeleteImageUrls.end()) { MapTile* delTile = *iter; if (!delTile->bInProgress || !g_bInProgress) { delList.push_back(delTile); } iter++; } iter = delList.begin(); while (iter != delList.end()) { MapTile* delTile = *iter; gDeleteImageUrls.remove(delTile); delete delTile; iter++; } } bool setViewMatrix = false; double scaleX, scaleY, perCentAngle; if (true) { if (CalculatePosition(forceUpdate) || g_bLocationChanged) { CalculateTiles(); } if (g_bScaledMode) { double rotAngle = gScaledModeScaler->GetRotationAngle(); perCentAngle = LiveMaps::RadToDeg(rotAngle) / 360; scaleX = gScaledModeScaler->GetScaleX(); scaleY = gScaledModeScaler->GetScaleY(); setViewMatrix = true; g_viewMatrix = gScaledModeScaler->GetDrawRotationMatrix(1.0); } else { float offset = 1 - (ceil(g_tempZoom) - g_tempZoom) / 2; CIwMat viewMatrix; viewMatrix.SetIdentity(); viewMatrix.t.x = 0; viewMatrix.t.y = 0; viewMatrix.t.z = -0x200; CIwMat scaleMat; scaleMat.SetIdentity(); scaleMat.m[0][0] = (iwfixed)(scaleMat.m[0][0] * offset); scaleMat.m[1][1] = (iwfixed)(scaleMat.m[1][1] * offset); g_viewMatrix = viewMatrix.PreMult(scaleMat); setViewMatrix = true; } } else { g_animationPercent = (double)g_iAnimationIndex / 40; // take 2 seconds // Handle the rotation animation here double rotAngle = gScaledModeScaler->GetRotationAngle(); perCentAngle = LiveMaps::RadToDeg(rotAngle) / 360; perCentAngle = perCentAngle * g_animationPercent; scaleX = 1 + ((gScaledModeScaler->GetScaleX() - 1) * g_animationPercent); scaleY = 1 + ((gScaledModeScaler->GetScaleY() - 1) * g_animationPercent); g_iAnimationIndex++; if (g_iAnimationIndex == 40) { g_bIsAnimating = false; } g_viewMatrix = gScaledModeScaler->GetDrawRotationMatrix(g_animationPercent); setViewMatrix = true; } if (setViewMatrix) { // Set our viewing point to the same as our field of view in Main.cpp -- IwGxSetPerspMul //g_viewMatrix.t.z = -0x200; //// Rotate the angle of our view matrix //iwangle degAng = (iwangle)(IW_GEOM_ONE * perCentAngle); //CIwMat rotZ; //rotZ.SetRotZ(degAng); //g_viewMatrix.CopyRot(rotZ); //CIwMat scaleMat; //scaleMat.SetIdentity(); //scaleMat.m[0][0] = 4096 / scaleX; //scaleMat.m[1][1] = 4096 / scaleY; //g_viewMatrix = g_viewMatrix.PreMult(scaleMat); // Give a range of zooming for effect //IwGxSetFarZNearZ(0x400, 0x10); IwGxSetViewMatrix(&g_viewMatrix); } if (!g_bInitialLoad) { if (!g_bInProgress) { //if ((s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN) == 0) { MapTile* pNextDownload = GetNextDownload(NULL); if (pNextDownload) { g_bInProgress = true; LoadMapTileImage(pNextDownload); } } } } return true; }