示例#1
0
void ExampleInit()
{
    IW_PROFILE_INIT();

    // Initialise
    IwGxInit();

    // Set screen clear colour
    IwGxSetColClear(0x40, 0x40, 0x40, 0x00);

    // Turn all lighting off
    IwGxLightingOff();

    // Set field of view
    IwGxSetPerspMul(0xa0);

    // Set near and far planes
    IwGxSetFarZNearZ(0x1000, 0x10);

    // Set the view matrix along the -ve z axis
    CIwMat view = CIwMat::g_Identity;
    view.t.z = -0x200;
    IwGxSetViewMatrix(&view);
    //IwGxSetScreenOrient(IW_GX_ORIENT_NONE);

    s_Accelerometer = (S3E_RESULT_SUCCESS == s3eAccelerometerStart());

    m_pAnimator = new CSplineAnimator();
    m_pAnimator->Init();

    m_pSplinePoly2Tri = new CSplinePoly2Tri(m_pAnimator->GetCurrentSpline());

    // ball
    m_pBall = new CBall();
}
示例#2
0
//-----------------------------------------------------------------------------
void HexMapTest::Init()
{
	zoom = 1.0f;
	rotation = 0.0f;
	screenTranslationX = 0;
	screenTranslationY = 0;

	// Initialise the input system
	g_Input.Init();

    // Initialise vectors
    s_left      =  CIwVec3::g_AxisX;
    s_up        = -CIwVec3::g_AxisY;
    s_Angles = CIwSVec3::g_Zero;
    s_cameraPos =  CIwVec3(0, 0, -0x80);

    // Initialise view matrix
    s_viewMatrix = CIwMat::g_Identity;

    s_viewMatrix.SetTrans(s_cameraPos);
    s_viewMatrix.LookAt(
        s_viewMatrix.GetTrans(),
         CIwVec3::g_Zero,
        -CIwVec3::g_AxisY);

	// Initialise
    IwGxInit();
	IwResManagerInit();
    // Set screen clear colour
    IwGxSetColClear(0x40, 0x40, 0x40, 0x00);

    // Turn all lighting off
    IwGxLightingOff();

    // Set field of view
    IwGxSetPerspMul(0xa0);

    // Set near and far planes
    IwGxSetFarZNearZ(0x1000, 0x10);

    // Create empty texture object
    s_BitMapTexture = new CIwTexture;

    // Load image data from disk into texture
    s_BitMapTexture->LoadFromFile("./textures/testTexture_8bit.bmp");

    // "Upload" texture to VRAM
    s_BitMapTexture->Upload();


    // Set the view matrix along the -ve z axis
    CIwMat view = CIwMat::g_Identity;
    view.t.z = -0x100;
    IwGxSetViewMatrix(&view);
	IwGetResManager()->LoadGroup("TileRes.group"); 
	pGroup = IwGetResManager()->GetGroupNamed("TileRes");
	hexGrid = new HexGrid(hexGridMaxX, hexGridMaxY, textureMaxX, textureMaxY);
	hexGrid->setTexture(IW_TEXTURE(pGroup,"grid"),textureMaxX,textureMaxY);
	s_ModelMatrix.SetIdentity();
}
示例#3
0
void MapBackground::ClearScaledCorners()
{
	g_dAlpha = 0xFF;
	g_bScaledMode = false;
	g_viewMatrix.SetIdentity();
	g_viewMatrix.t.z = -0x200;

	IwGxSetViewMatrix(&g_viewMatrix);

	delete gScaledModeScaler;
	gScaledModeScaler = new CoordinateScaler(Iw2DGetSurfaceWidth(), Iw2DGetSurfaceHeight(), NULL, 0, true);

	Update(true);
}
示例#4
0
void setupPlayer() {
	Player *player = getGameState()->getPlayer();

	if (!player->isReady()) {
		return;
	}

    // Set viewing position with the Y axis as upright.
    viewMatrix.SetIdentity();
    viewMatrix.LookAt(CIwFVec3(0,-11,0), CIwFVec3(0,0,100), CIwFVec3(0,-1,0));

    // Rotate according to compass heading
	viewMatrix.PostRotateY(rad(player->getHeading()));
    IwGxSetViewMatrix(&viewMatrix);
}
示例#5
0
void CzPlatformRender::SetViewMatrix(CzMatrix4* mat)
{
	CIwFMat m;
	m.SetIdentity();
	m.m[0][0] = mat->m[0][0];
	m.m[1][0] = mat->m[1][0];
	m.m[2][0] = mat->m[2][0];
	m.m[0][1] = mat->m[0][1];
	m.m[1][1] = mat->m[1][1];
	m.m[2][1] = mat->m[2][1];
	m.m[0][2] = mat->m[0][2];
	m.m[1][2] = mat->m[1][2];
	m.m[2][2] = mat->m[2][2];
	m.t.x = mat->m[0][3];
	m.t.y = mat->m[1][3];
	m.t.z = mat->m[2][3];

	IwGxSetViewMatrix(&m);
}
示例#6
0
//-----------------------------------------------------------------------------
// CIwRenderSlotBegin
//-----------------------------------------------------------------------------
void    CIwRenderSlotBegin::Render()
{
    IW_CALLSTACK("CIwRenderSlotBegin::Render")

    // Set view matrix from current world camera
    CIwCamera* pCam = IwGetRenderManager()->GetCamera();
    if  (
        (pCam) &&
        (pCam->GetFrame())
        )
        IwGxSetViewMatrix(IwGetRenderManager()->GetCamera()->GetMatLocal());

    // Perspective
    if (pCam)
    {
        IwGxSetPerspMul(pCam->m_PerspMul);
        IwGxSetFarNear(pCam->m_FarZ, pCam->m_NearZ);
    }

#ifdef IW_DEBUG
//  IwGetRenderManager()->m_DebugTextNext = IwGetRenderManager()->m_DebugText;
#endif
}
示例#7
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++;
	}
}
示例#8
0
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;
}
示例#9
0
//-----------------------------------------------------------------------------
bool HexMapTest::Update()
{
	int16 sprite1_pos_x,sprite1_pos_y;
	int16 sprite2_pos_x,sprite2_pos_y;
	if (mouse_mode == MOUSE_MODE_CHECKING)
		mouse_mode  = MOUSE_MODE_DOWN;

	// UI processing
	if (((s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED)) && mouse_mode == MOUSE_MODE_IDLE)
		mouse_mode = MOUSE_MODE_IDLE;
	if ((s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_RELEASED))
		mouse_mode = MOUSE_MODE_CHECKING;

//	UpdateKey();

	IwGxSetViewMatrix(&s_viewMatrix);

    // Generate a ray pointing to the view plane from the camera
    CIwVec3 dir(s3ePointerGetX() - IwGxGetScreenWidth()/2, 
        s3ePointerGetY() - IwGxGetScreenHeight()/2, 
        IwGxGetPerspMul());
    
    // Rotate into camera space
    dir = s_viewMatrix.RotateVec(dir);

	// Update pointer system
	g_Input.Update();
	if (g_Input.finger1IsDown()) {
		if (g_Input.overThreshold()) {
			if (!g_Input.finger1Continuing()) {
				s_ModelMatrix_initial = s_ModelMatrix;
				CIwVec3 vectCenter = getWorldCoords(0, 0);
				zoom_initial = zoom;
				rotation_initial = rotation;
				screenTranslationX_initial = screenTranslationX;
				screenTranslationY_initial = screenTranslationY;
				if (!g_Input.isMultiTouch()) {
					if (g_Input.finger1MovedTo(sprite1_pos_x, sprite1_pos_y)) {
						if (sprite1_pos_x > int(IwGxGetScreenWidth()) - SCREEN_MARGIN) {
							zooming = true;
						}
						if (sprite1_pos_y > int(IwGxGetScreenHeight()) - SCREEN_MARGIN) {
							rotating = true;
						}
					}
				}
			}
			if (!g_Input.finger2IsDown() && g_Input.finger1MovedTo(sprite1_pos_x, sprite1_pos_y)) {
				if (g_Input.finger1Continuing()) {
					if (zooming) {
						if (sprite1_pos_x > int(IwGxGetScreenWidth()) - SCREEN_MARGIN) {
							int16 dsprite1_pos_x, dsprite1_pos_y;
							if (g_Input.finger1MovementDelta(dsprite1_pos_x, dsprite1_pos_y)) {
								float deltaZoom = 1.0f - 1.0f*(dsprite1_pos_y)/IwGxGetScreenHeight();
								SetZoom(deltaZoom, 8);
							}
						}
					} else if (rotating) {
						if (sprite1_pos_y > int(IwGxGetScreenHeight()) - SCREEN_MARGIN) {
							int16 dsprite1_pos_x, dsprite1_pos_y;
							if (g_Input.finger1MovementDelta(dsprite1_pos_x, dsprite1_pos_y)) {
								float deltaRotation = 360.0f*(dsprite1_pos_x)/IwGxGetScreenWidth();
								SetRotation(deltaRotation);
							}
						}
					} else {
						SetTranslation();
					}
				}
			} else {
				if (g_Input.finger1MovedTo(sprite1_pos_x, sprite1_pos_y)) {
					if (g_Input.finger2MovedTo(sprite2_pos_x, sprite2_pos_y)) {
						if (!g_Input.finger2Continuing()) {
							screenTranslationX_initial = screenTranslationX;
							screenTranslationY_initial = screenTranslationY;
							g_Input.resetInitial(0);
						} else {
							int16 sprite1_pos_x_initial,sprite1_pos_y_initial,sprite2_pos_x_initial,sprite2_pos_y_initial;
							g_Input.finger1Initial(sprite1_pos_x_initial,sprite1_pos_y_initial);
							g_Input.finger2Initial(sprite2_pos_x_initial,sprite2_pos_y_initial);
							int d12x=sprite1_pos_x-sprite2_pos_x;
							int d12y=sprite1_pos_y-sprite2_pos_y;
							int d12x_initial=sprite1_pos_x_initial-sprite2_pos_x_initial;
							int d12y_initial=sprite1_pos_y_initial-sprite2_pos_y_initial;
							int Delta_initial = d12x_initial*d12x_initial+d12y_initial*d12y_initial;
							int Delta = d12x*d12x+d12y*d12y;
							float newZoom = float(sqrt(1.0*Delta)/sqrt(Delta_initial));
							SetZoom(newZoom, 1);
							float oldRotation = float(atan2(float(d12y_initial), float(d12x_initial)));
							float newRotation = float(atan2(float(d12y), float(d12x)));
							SetRotation(180.0f*(oldRotation-newRotation)/PI);
							{
								char string[256];
								//sprintf(string, "`1`a  del %04d, %04d",d1x,d2x);
								//IwGxPrintString(2, 96, string);
								sprintf(string, "`1`a  zoo %5.2f, %5.2f, %5.2f",newZoom,oldRotation,newRotation);
								IwGxPrintString(2, 96, string);
							}
						}
					}
				}
			}
		}
	} else {
		zooming = false;
		rotating = false;
		//		s_ModelMatrix = CIwMat::g_Identity;
	}
	return true;
}