void HexMapTest::SetModelMatrix() { s_ModelMatrix.SetIdentity(); CIwVec3 vectCenter = getWorldCoords(IwGxGetScreenWidth()/2, IwGxGetScreenHeight()/2); s_ModelMatrix.t.x = vectCenter.x; s_ModelMatrix.t.y = vectCenter.y; //Zoom s_ModelMatrix.Scale(IW_FIXED_FROM_FLOAT(zoom)); CIwVec3 vect = getWorldCoords(0, 0); CIwVec3 vect2 = getWorldCoords(screenTranslationX, screenTranslationY); int32 dx = int32((vect2.x-vect.x) * zoom); int32 dy = int32((vect2.y-vect.y) * zoom); //s_ModelMatrix.t.x = -dx; //s_ModelMatrix.t.y = -dy; iwfixed sinTheta = IwGeomSin(IW_ANGLE_FROM_DEGREES(-rotation)); iwfixed cosTheta = IwGeomCos(IW_ANGLE_FROM_DEGREES(-rotation)); s_ModelMatrix.t.x = -vectCenter.x-(IW_FIXED_MUL(dx, cosTheta) - IW_FIXED_MUL(dy, sinTheta)); s_ModelMatrix.t.y = -vectCenter.y-(IW_FIXED_MUL(dx, sinTheta) + IW_FIXED_MUL(dy, cosTheta)); //Rotate CIwMat rotationMat = CIwMat::g_Identity; rotationMat.SetRotZ(IW_ANGLE_FROM_DEGREES(rotation), true, true); s_ModelMatrix *= rotationMat; }
void renderImageWorldSpace(CIwFVec2& position, float angle, float scaleFactor, int textureSize, float worldRot, int frameNumber, int numFrames, float z) { static CIwSVec3 vertices[4]; static CIwSVec2 UVs[4]; //set up model space vertices int vertexDist = scaleFactor*textureSize/2; vertices[0] = CIwSVec3(-1*vertexDist, -1*vertexDist, z); vertices[2] = CIwSVec3(vertexDist, -1*vertexDist, z); vertices[3] = CIwSVec3(vertexDist, vertexDist, z); vertices[1] = CIwSVec3(-1*vertexDist, vertexDist, z); CIwMat modelTransform = CIwMat::g_Identity; modelTransform.SetRotZ(IW_ANGLE_FROM_RADIANS(angle)); modelTransform.SetTrans(CIwVec3(position.x, -position.y, 0)); CIwMat rot = CIwMat::g_Identity; rot.SetRotZ(IW_ANGLE_FROM_RADIANS(worldRot)); modelTransform = modelTransform*rot; IwGxSetModelMatrix(&modelTransform, false); float frameRatio = 1.0/numFrames; //set up sprite UV's iwfixed cf = IW_FIXED((float)frameNumber / numFrames); iwfixed nf = IW_FIXED((frameNumber + 1.0) / numFrames); UVs[0] = CIwSVec2(cf, 0); UVs[2] = CIwSVec2(nf, 0); UVs[3] = CIwSVec2(nf, IW_GEOM_ONE); UVs[1] = CIwSVec2(cf, IW_GEOM_ONE); //render the unit in model space IwGxSetUVStream(UVs); IwGxSetZDepthFixed(8); IwGxSetVertStreamModelSpace(vertices, 4); IwGxDrawPrims(IW_GX_QUAD_STRIP, NULL, 4); IwGxFlush(); }
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; }
CIwVec3 HexMapTest::getWorldCoords(int x, int y) { // Generate a ray pointing to the view plane from the camera CIwVec3 dir(x - IwGxGetScreenWidth()/2, y - IwGxGetScreenHeight()/2, IwGxGetPerspMul()); CIwVec3 origin = s_viewMatrix.t; // Rotate into camera space dir = s_viewMatrix.RotateVec(dir); // dir.NormaliseSlow(); CIwVec3 inter = getIntersectionNew(origin, dir); inter = inter - s_ModelMatrix.t; iwfixed z = IW_FIXED_FROM_FLOAT(1.0f/zoom); inter.x = IW_FIXED_MUL(inter.x, z); inter.y = IW_FIXED_MUL(inter.y, z); inter.z = IW_FIXED_MUL(inter.z, z); CIwMat rotationMat = CIwMat::g_Identity; rotationMat.SetRotZ(IW_ANGLE_FROM_DEGREES(-rotation), true, true); inter = rotationMat.RotateVec(inter); return inter; }
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++; } }