Пример #1
0
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;

}
Пример #2
0
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();
}
Пример #3
0
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;
}
Пример #4
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;
}
Пример #5
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++;
	}
}
Пример #6
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;
}
Пример #7
0
bool HexMapTest::UpdateKey() {
	CIwMat   rotation;
    CIwVec3  lookFrom(0,0,0);

	if (KeyPressed(s3eKeyPageUp)) {
		if (KeyAltDown()) {
			rotation.SetAxisAngle(
				s_viewMatrix.RotateVec(s_left),
				IW_ANGLE_FROM_DEGREES(0));
			lookFrom = (s_viewMatrix * rotation).RotateVec(
				s_cameraPos);
			updateLookAt(lookFrom);
		} else {
			s_viewMatrix.t[2] -= 0x010;
			if (s_cameraPos.z<-0x40)
				s_cameraPos.z += 0x40;
		}
	}

	if (KeyPressed(s3eKeyPageDown))
	{
		if (KeyAltDown()) {
			s_cameraPos.z -= 0x40;
			rotation.SetAxisAngle(
				s_viewMatrix.RotateVec(s_left),
				IW_ANGLE_FROM_DEGREES(0));
			lookFrom = (s_viewMatrix * rotation).RotateVec(
				s_cameraPos);
			updateLookAt(lookFrom);
		} else {
			s_viewMatrix.t[2] += 0x010;
		}
	}

    // Up, Down, Left, Right keys
    //

    if (KeyPressed(s3eKeyUp))
    {
		if (KeyAltDown()) {
			rotation.SetAxisAngle(
				s_viewMatrix.RotateVec(s_left),
				IW_ANGLE_FROM_DEGREES(-5));
			lookFrom = (s_viewMatrix * rotation).RotateVec(
				s_cameraPos);
			updateLookAt(lookFrom);
		} else {
			s_viewMatrix.t[1] -= 0x010;
		}
    }

    if (KeyPressed(s3eKeyDown))
    {
		if (KeyAltDown()) {
			rotation.SetAxisAngle(
				s_viewMatrix.RotateVec(s_left),
				IW_ANGLE_FROM_DEGREES(5));
			lookFrom = (s_viewMatrix * rotation).RotateVec(
				s_cameraPos);
			updateLookAt(lookFrom);
		} else {
			s_viewMatrix.t[1] += 0x010;
		}
    }

    if (KeyPressed(s3eKeyRight))
    {
		if (KeyAltDown()) {
			rotation.SetAxisAngle(
				s_viewMatrix.TransformVec(s_up),
				IW_ANGLE_FROM_DEGREES(5));
			lookFrom = (s_viewMatrix * rotation).RotateVec(
				s_cameraPos);
			updateLookAt(lookFrom);
		} else {
			s_viewMatrix.t[0] += 0x010;
		}
    }

	if (KeyPressed(s3eKeyLeft))
    {
		if (KeyAltDown()) {
			rotation.SetAxisAngle(
				s_viewMatrix.TransformVec(s_up),
				IW_ANGLE_FROM_DEGREES(-5));
			lookFrom = (s_viewMatrix * rotation).RotateVec(
				s_cameraPos);
			updateLookAt(lookFrom);
		} else {
			s_viewMatrix.t[0] -= 0x010;
		}
    }
	return true;
}
Пример #8
0
//-----------------------------------------------------------------------------
void    CIwBeMotionCamFree::Update()
{
    IW_CALLSTACK("CIwBeMotionCamFree::Update")

    CIwCamera*  pCam = (CIwCamera*)GetEnt();
    CIwMat*     pMat = pCam->ExposeMatLocal();

#if defined I3D_OS_WINDOWS || defined I3D_OS_S3E
    const s3eKey    kLeft           = s3eKeyLeft;
    const s3eKey    kRight          = s3eKeyRight;
    const s3eKey    kUp             = s3eKeyUp;
    const s3eKey    kDown           = s3eKeyDown;
    const s3eKey    kZRotUp         = s3eKeyNumPadPlus;
    const s3eKey    kZRotDown       = s3eKeyNumPadMinus;

    const s3eKey    kFore           = s3eKeyNumPad4;
    const s3eKey    kBack           = s3eKeyNumPad1;
    const s3eKey    kRise           = s3eKeyNumPad2;
    const s3eKey    kFall           = s3eKeyNumPad5;

    const s3eKey    kStrafeLeft     = s3eKeyNumPad7;
    const s3eKey    kStrafeRight    = s3eKeyNumPad8;

    const s3eKey    kFast           = s3eKeyShift;
#else
    const s3eKey    kLeft           = s3eKey4;
    const s3eKey    kRight          = s3eKey6;
    const s3eKey    kUp             = s3eKey2;
    const s3eKey    kDown           = s3eKey8;
    const s3eKey    kZRotUp         = s3eKeyLSK;
    const s3eKey    kZRotDown       = s3eKeyRSK;

    const s3eKey    kFore           = s3eKey1;
    const s3eKey    kBack           = s3eKey7;
    const s3eKey    kRise           = s3eKey3;
    const s3eKey    kFall           = s3eKey9;

    const s3eKey    kStrafeLeft     = s3eKey0;
    const s3eKey    kStrafeRight    = s3eKeyHash;

    const s3eKey    kFast           = s3eKeyStar;
#endif

    bool    shift       = (s3eKeyboardGetState(kFast) & S3E_KEY_STATE_DOWN) != 0;
    int32   maxAngVel   = shift ? m_MaxAngVel : m_MaxAngVel/2;
    int32   maxSpeed    = shift ? m_MaxSpeed : m_MaxSpeed/4;
    int32   angAcc      = maxAngVel >> 3;
    int32   acc         = maxSpeed >> 1;
#ifdef HALF_SPEED
    maxAngVel >>= 1;
    maxSpeed >>= 1;
#endif

    // Rotate Y
    if (s3eKeyboardGetState(kLeft) & S3E_KEY_STATE_DOWN)
        m_AngVel.y  = MAX(-maxAngVel, m_AngVel.y + angAcc);
    else
    if (s3eKeyboardGetState(kRight) & S3E_KEY_STATE_DOWN)
        m_AngVel.y  = MIN(maxAngVel, m_AngVel.y - angAcc);
    else
        m_AngVel.y  = 0;

    // Rotate X
    if (s3eKeyboardGetState(kUp) & S3E_KEY_STATE_DOWN)
        m_AngVel.x  = MAX(-maxAngVel, m_AngVel.x - angAcc);
    else
    if (s3eKeyboardGetState(kDown) & S3E_KEY_STATE_DOWN)
        m_AngVel.x  = MIN(maxAngVel, m_AngVel.x + angAcc);
    else
        m_AngVel.x  = 0;

    m_AngVel.z  = 0;
    if ((s3eKeyboardGetState(s3eKeyV) & S3E_KEY_STATE_DOWN))
    {
        // Rotate Z
        if (s3eKeyboardGetState(kZRotUp) & S3E_KEY_STATE_DOWN)
            m_AngVel.z  = MAX(-maxAngVel, m_AngVel.z - angAcc);
        else
        if (s3eKeyboardGetState(kZRotDown) & S3E_KEY_STATE_DOWN)
            m_AngVel.z  = MIN(maxAngVel, m_AngVel.z + angAcc);
        else
            m_AngVel.z  = 0;
    }

    if (m_AngVel.x || m_AngVel.y || m_AngVel.z)
    {
        // Back up translation of matrix, and zero it so that the
        // rotations don't change the current position of the camera
        const CIwVec3 origTranslation = pMat->t;
        pMat->t = CIwVec3::g_Zero;

        // Apply required rotation
        CIwMat  mat;

        if (m_AngVel.x)
        {
            mat.SetAxisAngle(pMat->VecX(), m_AngVel.x);
            *pMat *= mat;
        }
        if (m_AngVel.y)
        {
            if (m_UseWorldY)
                mat.SetRotY(-m_AngVel.y);
            else
                mat.SetAxisAngle(pMat->VecY(), m_AngVel.y);
            *pMat *= mat;
        }
        if (m_AngVel.z)
        {
            mat.SetAxisAngle(pMat->VecZ(), m_AngVel.z);
            *pMat *= mat;
        }

        // Normalise matrix and copy back the original position
        pMat->Normalise();
        pMat->t = origTranslation;
    }

    // Move forward/back
    if (s3eKeyboardGetState(kFore) & S3E_KEY_STATE_DOWN)
        m_Vel.z = MIN(maxSpeed, m_Vel.z + acc);
    else
    if (s3eKeyboardGetState(kBack) & S3E_KEY_STATE_DOWN)
        m_Vel.z = MAX(-maxSpeed, m_Vel.z - acc);
    else
        m_Vel.z = 0;

    pMat->t += pMat->VecZ() * m_Vel.z;

    // Move up/down
    if (s3eKeyboardGetState(kRise) & S3E_KEY_STATE_DOWN)
        m_Vel.y = MIN(maxSpeed, m_Vel.y + acc);
    else
    if (s3eKeyboardGetState(kFall) & S3E_KEY_STATE_DOWN)
        m_Vel.y = MAX(-maxSpeed, m_Vel.y - acc);
    else
        m_Vel.y = 0;

    pMat->t += pMat->VecY() * m_Vel.y;

    // Strafe left/right
    if (s3eKeyboardGetState(kStrafeRight) & S3E_KEY_STATE_DOWN)
        m_Vel.x = MIN(maxSpeed, m_Vel.x + acc);
    else
    if (s3eKeyboardGetState(kStrafeLeft) & S3E_KEY_STATE_DOWN)
        m_Vel.x = MAX(-maxSpeed, m_Vel.x - acc);
    else
        m_Vel.x = 0;

    pMat->t += pMat->VecX() * m_Vel.x;

    // Change perspmul
    if (s3eKeyboardGetState(s3eKeyV) & S3E_KEY_STATE_DOWN)
    {
        if (s3eKeyboardGetState(s3eKeyNumPadPlus) & S3E_KEY_STATE_DOWN)     pCam->m_PerspMul += 0x8;
        if (s3eKeyboardGetState(s3eKeyNumPadMinus) & S3E_KEY_STATE_DOWN)    pCam->m_PerspMul = MAX(0x8, pCam->m_PerspMul - 0x8);
    }
}