Exemple #1
0
void renderMap() {
	IwGxLightingOff();
	
	CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
    pMat->SetModulateMode(CIwMaterial::MODULATE_NONE);
    pMat->SetTexture(mapTexture);

	IwGxSetMaterial(pMat);

	IwGxSetScreenSpaceSlot(-1);

	float zoom = getMapZoom()->getZoom();

	int16 hScrW = (double)IwGxGetScreenWidth()*0.5f;
	int16 hScrH = (double)IwGxGetScreenHeight()*0.5f;
	int16 x1 = hScrW - hScrW*zoom;
	int16 x2 = hScrW + hScrW*zoom;
	int16 y1 = hScrH - hScrH*zoom;
	int16 y2 = hScrH + hScrH*zoom;

	mapVertZoom[0].x = x1, mapVertZoom[0].y = y1;
	mapVertZoom[1].x = x1, mapVertZoom[1].y = y2;
	mapVertZoom[2].x = x2, mapVertZoom[2].y = y2;
	mapVertZoom[3].x = x2, mapVertZoom[3].y = y1;

    IwGxSetUVStream(mapDefaultUvs);
    IwGxSetVertStreamScreenSpace(mapVertZoom, 4);

    IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4);
}
void MapBackground::RenderElement(CIwUIGraphics& parentGraphics)
{
	// Render tiles for the background
	std::list<MapTile*>::iterator iter = gVectorImageUrls.begin();

	int i = 0;
	while (iter != gVectorImageUrls.end())
	{
		MapTile* pTile = *iter;

		if (pTile->pTexture)
		{
			//Calculate the top left of the map image
			CIwSVec2 topLeft, bottomRight;
			topLeft.x = pTile->location.x;
			topLeft.y = pTile->location.y;
			CIwUIRect rect(CIwVec2(topLeft.x, topLeft.y), CIwVec2(pTile->pTexture->GetWidth(), pTile->pTexture->GetHeight()));

			CIwUIColour c(0xff,0xff,0xff,0xff);
			CIwColour* wtf = IW_GX_ALLOC(CIwColour, 4);

			CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
			pMat->SetModulateMode(CIwMaterial::MODULATE_NONE);
			pMat->SetTexture(pTile->pTexture);

			parentGraphics.DrawImage(pTile->pTexture, pMat, rect, CIwSVec2(0,0), CIwSVec2(4096, 4096), c, false);
		}
		iter++;
	}
}
Exemple #3
0
void Unit::displayOnScreen(int x, int y){    
    
    CIwMaterial *mat = new CIwMaterial();
	mat->SetTexture((CIwTexture*)game->getSprites()->GetResHashed(getTextureName(), IW_GX_RESTYPE_TEXTURE));
    mat->SetModulateMode(CIwMaterial::MODULATE_NONE);
    mat->SetAlphaMode(CIwMaterial::ALPHA_DEFAULT);
    IwGxSetMaterial(mat);
    
	CIwSVec2 xy(x-45, y-45);
    CIwSVec2 duv(IW_FIXED(1.0/numFrames), IW_GEOM_ONE);
    
	static CIwSVec2 wh(90, 90);
	static CIwSVec2 uv(IW_FIXED(0), IW_FIXED(0));	
    
    IwGxSetScreenSpaceSlot(1);
    IwGxDrawRectScreenSpace(&xy, &wh, &uv, &duv);
    
    delete mat;
}
Exemple #4
0
void renderCamera() {

	IwGxLightingOff();

    // Refresh dynamic texture
    if (g_CameraTexture != NULL)
        g_CameraTexture->ChangeTexels((uint8*)g_pCameraTexelsRGB565, CIwImage::RGB_565);

    CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
    pMat->SetModulateMode(CIwMaterial::MODULATE_NONE);
    pMat->SetTexture(g_CameraTexture);

    IwGxSetMaterial(pMat);

	IwGxSetScreenSpaceSlot(-1);

    IwGxSetUVStream(cameraUvs);
    IwGxSetVertStreamScreenSpace(cameraVert, 4);

    IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4);
}
Exemple #5
0
void doMain() {
    if(s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE)){
        s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, (s3eCallback)MultiTouchButtonCB, NULL);
        s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, (s3eCallback)MultiTouchMotionCB, NULL);
    } else {
        s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)SingleTouchButtonCB, NULL);
        s3ePointerRegister(S3E_POINTER_MOTION_EVENT, (s3eCallback)SingleTouchMotionCB, NULL);
    }


    IwGetResManager()->LoadGroup("resource_groups/palate.group");
    
    palateGroup = IwGetResManager()->GetGroupNamed("Palate");

    std::vector<int> ui_texture_hashes;
	uint background_hash = IwHashString("background_clean");
	CIwResList* resources = palateGroup->GetListHashed(IwHashString("CIwTexture"));
	for(CIwManaged** itr = resources->m_Resources.GetBegin(); itr != resources->m_Resources.GetEnd(); ++itr) {
		if(background_hash != (*itr)->m_Hash) {
			ui_texture_hashes.push_back((*itr)->m_Hash);
		}
	}
    
    CIwMaterial* background = new CIwMaterial();
    background->SetTexture((CIwTexture*)palateGroup->GetResNamed("background_clean", IW_GX_RESTYPE_TEXTURE));
    background->SetModulateMode(CIwMaterial::MODULATE_NONE);
    background->SetAlphaMode(CIwMaterial::ALPHA_DEFAULT);

	unit_ui = new CIwMaterial();
    unit_ui->SetModulateMode(CIwMaterial::MODULATE_NONE);
    unit_ui->SetAlphaMode(CIwMaterial::ALPHA_DEFAULT);
    unit_ui->SetTexture((CIwTexture*)palateGroup->GetResNamed("TAKE2", IW_GX_RESTYPE_TEXTURE));
    
    CIwSVec2 bg_wh(320, 480);
	CIwSVec2 ui_wh(80, 480);
	CIwSVec2 ui_offset(240, 0);
	CIwSVec2 uv(0, 0);
	CIwSVec2 duv(IW_GEOM_ONE, IW_GEOM_ONE);

    init();
    
	IwGxLightingOff();
    IwGxSetColClear(255, 255, 255, 255);
    
    float worldScrollMultiplier = 0.75;
    
    if(s3eDeviceGetInt(S3E_DEVICE_OS) == S3E_OS_ID_IPHONE) {
        worldScrollMultiplier = 0.925;
    }

	while (1) {
        
        int64 start = s3eTimerGetMs();
	
		s3eDeviceYield(0);
		s3eKeyboardUpdate();
		s3ePointerUpdate();
		
		if ((s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN)
				|| (s3eKeyboardGetState(s3eKeyAbsBSK) & S3E_KEY_STATE_DOWN)       
				|| (s3eDeviceCheckQuitRequest())) {
			
		    break;
		}
	
        switch(currentState) {

        case MAIN_MENU:
            if(s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED) {
                currentState = IN_GAME;
            }
            if(frameCount % FRAMES_PER_UPDATE == 0) {
			    mainMenu->tick();
		    }
            mainMenu->render();
            break;
        case IN_GAME:
            IwGxSetMaterial(background);
            IwGxSetScreenSpaceSlot(-1);
            IwGxDrawRectScreenSpace(&CIwSVec2::g_Zero, &bg_wh, &uv, &duv);

		    IwGxSetMaterial(unit_ui);
            IwGxSetScreenSpaceSlot(1); 
            IwGxDrawRectScreenSpace(&ui_offset, &ui_wh, &uv, &duv);
        
		    if (worldScrollSpeed > .0005 || worldScrollSpeed < -.0005) {
			    game->rotate(worldScrollSpeed);
			    worldScrollSpeed *= worldScrollMultiplier;
		    }
            if(frameCount % FRAMES_PER_UPDATE == 0) {
			    game->tick();
		    }
		
		    game->render();
		    if(!renderTouches()) {
                break;
            }

            break;
        }
        		
        IwGxFlush();
        
        IwGxSwapBuffers();
		
		// Attempt frame rate
		while ((s3eTimerGetMs() - start) < MS_PER_FRAME){
			int32 yield = (MS_PER_FRAME - (s3eTimerGetMs() - start));
			if (yield < 0) {
				break;
			}
				
			s3eDeviceYield(yield);
		}
		
		frameCount++;

        
        IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F);
	}
    
	delete game;
    delete mainMenu;
	delete localPlayer;
	delete opponentPlayer;
    delete background;
	delete unit_ui;
    palateGroup->Finalise();
    
    for(int i = 0; i < MAX_TOUCHES; ++i)
        if(touches[i].unit)
            delete touches[i].unit;
}
void MapBackground::RenderBackgroundOnSurface(CIw2DSurface* pSurface)
{
	std::list<MapTile*>::iterator iter = gVectorImageUrls.begin();

	// Set up a view matrix to rotate what we are viewing about the z-axis
	// This normalizes the center of the screen to (0,0), so we need to offset
	// our coordinates.
	// We also need to scale in our X and Y directions.

	CIwColour colClear;
	colClear = IwGxGetColClear();

	if (g_dAlpha < 0xFF)
	{
		IwGxSetColClear(0, 0, 0, 0);
	}

	CIwColour* cols = IW_GX_ALLOC(CIwColour, 4);
	for (int i = 0; i < 4; ++i)
	{
		cols[i].r = cols[i].g = cols[i].b = 0xff;
		cols[i].a = (uint8)g_dAlpha;
	}
	//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) + 1, (0 << 12) + 1),
		CIwSVec2((0 << 12) + 1, (1 << 12) - 1),
		CIwSVec2((1 << 12) - 1, (1 << 12) - 1),
		CIwSVec2((1 << 12) - 1, (0 << 12) + 1),
	};

	static CIwSVec2 uvsRot[4] =
	{
		CIwSVec2((0 << 12) + 20, (0 << 12) + 20),
		CIwSVec2((0 << 12) + 20, (1 << 12) - 20),
		CIwSVec2((1 << 12) - 20, (1 << 12) - 20),
		CIwSVec2((1 << 12) - 20, (0 << 12) + 20),
	};

	while (iter != gVectorImageUrls.end())
	{
		MapTile* pTile = *iter;
		
		CIwTexture* pTexture = pTile->pTexture;

		if (pTexture)
		{
			//Calculate the top left of the map image
			CIwSVec2 topLeft = pTile->location;

			CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
			pMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND);
			pMat->SetModulateMode(CIwMaterial::MODULATE_RGB);

			// Use Texture on Material
			pMat->SetTexture(pTexture);
			IwGxSetMaterial(pMat);

			int xOffset = IwGxGetScreenWidth() / 2;
			int yOffset = IwGxGetScreenHeight() / 2;

			CIwSVec3* pWSCoords= IW_GX_ALLOC(CIwSVec3, 4);
 			pWSCoords[0].x = topLeft.x; pWSCoords[0].y = topLeft.y;
			pWSCoords[1].x = topLeft.x; pWSCoords[1].y = topLeft.y + 256;
			pWSCoords[2].x = topLeft.x + 256; pWSCoords[2].y = topLeft.y + 256;
			pWSCoords[3].x = topLeft.x + 256; pWSCoords[3].y = topLeft.y;
			pWSCoords[0].z = pWSCoords[1].z = pWSCoords[2].z = pWSCoords[3].z = 0;

			// Scale the coordinates by offsetting, scaling and rendering
			for (int i = 0; i < 4; ++i)
			{
				pWSCoords[i].x -= xOffset;
				pWSCoords[i].y -= yOffset;
			}

			IwGxSetVertStreamWorldSpace(pWSCoords, 4);

			if (g_bScaledMode)
			{
				IwGxSetUVStream(uvsRot);
			}
			else
			{
				IwGxSetUVStream(uvs);
			}
			IwGxSetColStream(cols);
			IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4);
		}
		iter++;
	}
	IwGxSetColStream(NULL);
	//IwGxSetColClear(colClear.r, colClear.g, colClear.b, colClear.a);
}
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++;
	}
}
Exemple #8
0
void GhostCollision::RenderEctoplasmaBar(float ectoPercent, double ghostRotation)
{
	CIwFMat ectoMatrix = CIwFMat();
	ectoMatrix.CopyRot(*modelMatrix);
	ectoMatrix.CopyTrans(*modelMatrix);
	ectoMatrix.PostRotateY(PI-ghostRotation);

	IwGxSetModelMatrix(&ectoMatrix);
	IwGxSetScreenSpaceSlot(1);

	if (ghostW < 0 || ghostX < 0 || ghostY < 0) ResolveLocation();

	const int16 w = 180;
	const int16 border_x1 = ghostX+ghostW/2 - (float)w*ectobarScale;
	const int16 border_x2 = ghostX+ghostW/2 + (float)w*ectobarScale;

	const float border_y1 = ghostY+0x20;
	const float border_y2 = ghostY+0x20 + (float)0x10*ectobarScale;
	const int16 z = 0x6;

	{
		CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
		pMat->SetModulateMode(CIwMaterial::MODULATE_RGB);
		pMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND);
		pMat->SetTexture(borderTexture);

		int16 x1 = border_x1, x2 = border_x2; 
		float y1 = border_y1, y2 = border_y2;
		border_Verts[0] = CIwFVec3(x1, y2, -z);
		border_Verts[1] = CIwFVec3(x2, y2, -z);
		border_Verts[2] = CIwFVec3(x2, y1, -z);
		border_Verts[3] = CIwFVec3(x1, y1, -z);
		border_Verts[4] = CIwFVec3(x1, y2,  z);
		border_Verts[5] = CIwFVec3(x2, y2,  z);
		border_Verts[6] = CIwFVec3(x2, y1,  z);
		border_Verts[7] = CIwFVec3(x1, y1,  z);

		IwGxSetMaterial(pMat);
		IwGxSetVertStream(border_Verts, 8);
		//IwGxSetColStream(s_Cols, 8);
		IwGxSetUVStream(s_UVs);
		IwGxDrawPrims(IW_GX_QUAD_STRIP, s_QuadStrip, 4);
	}

	float start_y1 = border_y1 + fabs((float)(border_y2 - border_y1)*0.200);
	float start_y2 = start_y1  + fabs((float)(border_y2 - border_y1)*0.720);
	float startWhScale = (float)((double)startTexture->GetWidth() / startTexture->GetHeight());
	int16 startW = (start_y2 - start_y1) * startWhScale;
	int16 start_x1 = border_x1 + abs((float)(border_x2 - border_x1)*0.0097);
	int16 start_x2 = start_x1 + startW;
	
	{
		CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
		pMat->SetModulateMode(CIwMaterial::MODULATE_RGB);
		pMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND);
		pMat->SetTexture(startTexture);

		int16 x1 = start_x1, x2 = start_x2;
		float y1 = start_y1, y2 = start_y2;
		start_Verts[0] = CIwFVec3(x1, y2, -z);
		start_Verts[1] = CIwFVec3(x2, y2, -z);
		start_Verts[2] = CIwFVec3(x2, y1, -z);
		start_Verts[3] = CIwFVec3(x1, y1, -z);
		start_Verts[4] = CIwFVec3(x1, y2,  z);
		start_Verts[5] = CIwFVec3(x2, y2,  z);
		start_Verts[6] = CIwFVec3(x2, y1,  z);
		start_Verts[7] = CIwFVec3(x1, y1,  z);

		IwGxSetMaterial(pMat);
		IwGxSetVertStream(start_Verts, 8);
		//IwGxSetColStream(s_Cols, 8);
		IwGxSetUVStream(s_UVs);
		IwGxDrawPrims(IW_GX_QUAD_STRIP, s_QuadStrip, 4);
	}

	float end_y1 = start_y1;
	float end_y2 = start_y2;
	float endWhScale = (float)((double)endTexture->GetWidth() / endTexture->GetHeight());
	int16 endW = (end_y2 - end_y1) * endWhScale;

	int endMaxX = border_x2 - abs((float)(border_x2 - border_x1)*0.0097) - endW;
	int endMinX = start_x2;
	int16 end_x1 = (double)(endMaxX - endMinX)*ectoPercent + endMinX;
	int16 end_x2 = end_x1 + endW;
	
	{
		CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
		pMat->SetModulateMode(CIwMaterial::MODULATE_RGB);
		pMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND);
		pMat->SetTexture(endTexture);

		int16 x1 = end_x1, x2 = end_x2;
		float y1 = end_y1, y2 = end_y2;
		end_Verts[0] = CIwFVec3(x1, y2, -z);
		end_Verts[1] = CIwFVec3(x2, y2, -z);
		end_Verts[2] = CIwFVec3(x2, y1, -z);
		end_Verts[3] = CIwFVec3(x1, y1, -z);
		end_Verts[4] = CIwFVec3(x1, y2,  z);
		end_Verts[5] = CIwFVec3(x2, y2,  z);
		end_Verts[6] = CIwFVec3(x2, y1,  z);
		end_Verts[7] = CIwFVec3(x1, y1,  z);

		IwGxSetMaterial(pMat);
		IwGxSetVertStream(end_Verts, 8);
		//IwGxSetColStream(s_Cols, 8);
		IwGxSetUVStream(s_UVs);
		IwGxDrawPrims(IW_GX_QUAD_STRIP, s_QuadStrip, 4);
	}
	
	float center_y1 = start_y1;
	float center_y2 = start_y2;
	int16 center_x1 = start_x2 - 1;
	int16 center_x2 = end_x1 + 1;
	
	{
		CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
		pMat->SetModulateMode(CIwMaterial::MODULATE_RGB);
		pMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND);
		pMat->SetTexture(centerTexture);

		int16 x1 = center_x1, x2 = center_x2; 
		float y1 = center_y1, y2 = center_y2;
		center_Verts[0] = CIwFVec3(x1, y2, -z);
		center_Verts[1] = CIwFVec3(x2, y2, -z);
		center_Verts[2] = CIwFVec3(x2, y1, -z);
		center_Verts[3] = CIwFVec3(x1, y1, -z);
		center_Verts[4] = CIwFVec3(x1, y2,  z);
		center_Verts[5] = CIwFVec3(x2, y2,  z);
		center_Verts[6] = CIwFVec3(x2, y1,  z);
		center_Verts[7] = CIwFVec3(x1, y1,  z);

		IwGxSetMaterial(pMat);
		IwGxSetVertStream(center_Verts, 8);
		//IwGxSetColStream(s_Cols, 8);
		IwGxSetUVStream(s_UVs);
		IwGxDrawPrims(IW_GX_QUAD_STRIP, s_QuadStrip, 4);
	}
	
}