Esempio n. 1
0
extern "C" void RenderCursorskeys()
{
    int height = 20;
    int width = 45;

    int lefty = IwGxGetScreenHeight() - (height * 2);
    int leftx = (IwGxGetScreenWidth() - 220) / 2;
    int upy = IwGxGetScreenHeight() - (height * 3);
    int upx = leftx+width + (width/2);
    int downy = IwGxGetScreenHeight() - height;
    int downx = upx;
    int righty = IwGxGetScreenHeight() - (height * 2);
    int rightx = downx + width + (width/2);

    CIwMaterial *fadeMat = IW_GX_ALLOC_MATERIAL();
    fadeMat->SetAlphaMode(CIwMaterial::SUB);
    IwGxSetMaterial(fadeMat);

    g_Cursorkey = EXCURSOR_NONE;

    if ( (s3eKeyboardGetState(s3eKeyLeft) & S3E_KEY_STATE_DOWN) )
        g_Cursorkey = EXCURSOR_LEFT;
    if ( (s3eKeyboardGetState(s3eKeyRight) & S3E_KEY_STATE_DOWN) )
        g_Cursorkey = EXCURSOR_RIGHT;
    if ( (s3eKeyboardGetState(s3eKeyUp) & S3E_KEY_STATE_DOWN) )
        g_Cursorkey = EXCURSOR_UP;
    if ( (s3eKeyboardGetState(s3eKeyDown) & S3E_KEY_STATE_DOWN) )
        g_Cursorkey = EXCURSOR_DOWN;

    if(s3ePointerGetInt(S3E_POINTER_AVAILABLE))
    {
        if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN)
        {
            int pointerx = s3ePointerGetX();
            int pointery = s3ePointerGetY();
            // Check left
            if (pointerx >= leftx && pointerx <= leftx+width && pointery >=lefty && pointery <= lefty+height)
                g_Cursorkey = EXCURSOR_LEFT;
            // Check right
            if (pointerx >= rightx && pointerx <= rightx+width && pointery >=righty && pointery <= righty+height)
                g_Cursorkey = EXCURSOR_RIGHT;
            // Check up
            if (pointerx >= upx && pointerx <= upx+width && pointery >=upy && pointery <= upy+height)
                g_Cursorkey = EXCURSOR_UP;
            // Check down
            if (pointerx >= downx && pointerx <= downx+width && pointery >=downy && pointery <= downy+height)
                g_Cursorkey = EXCURSOR_DOWN;
        }

        CIwColour* cols = IW_GX_ALLOC(CIwColour, 4);
        if((s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN) && (g_Cursorkey != EXCURSOR_NONE))
            memset(cols, 10, sizeof(CIwColour)*4);
        else
            memset(cols, 50, sizeof(CIwColour)*4);

        // draw black rect covering screen
        CIwSVec2 rectdim(width, height);

        CIwSVec2 uXY(upx, upy-2);
        IwGxDrawRectScreenSpace(&uXY, &rectdim, cols);
        IwGxPrintString(upx + 10, upy + 5, "Up", false);

        CIwSVec2 dXY(downx, downy-2);
        IwGxDrawRectScreenSpace(&dXY, &rectdim, cols);
        IwGxPrintString(downx + 10, downy + 5, "Down", false);

        CIwSVec2 lXY(leftx, lefty-2);
        IwGxDrawRectScreenSpace(&lXY, &rectdim, cols);
        IwGxPrintString(leftx + 10, lefty + 5, "Left", false);

        CIwSVec2 rXY(rightx, righty-2);
        IwGxDrawRectScreenSpace(&rXY, &rectdim, cols);
        IwGxPrintString(rightx + 10, righty + 5, "Right", false);
    }
}
Esempio n. 2
0
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);
}
Esempio n. 3
0
Scene::Scene() : m_NameHash(0), m_IsActive(true), m_IsInputActive(false)
{
	m_X = -(float)IwGxGetScreenWidth();
}
Esempio n. 4
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;
}
Esempio n. 5
0
//-----------------------------------------------------------------------------
int32 GhostCollision::GetFaceUnderCursor(int32 x, int32 y)
{
    //Calculate pos/dir of cursor from camera
    CIwFVec3 pos = IwGxGetViewMatrix().t;
    CIwFVec3 dir(x, y, IwGxGetPerspMul());
    dir.x -= IwGxGetScreenWidth()/2;
    dir.y -= IwGxGetScreenHeight()/2;

    //Extend to the far plane
    dir *= IW_FIXED_DIV(IwGxGetFarZ(), IwGxGetPerspMul());

    //Transform pos/dir into model space
    dir = IwGxGetViewMatrix().RotateVec(dir);
    dir = modelMatrix->TransposeRotateVec(dir);

    //Use more accurate normalise
    dir.Normalise();

    // Scale to touch far plane
    dir *= IwGxGetFarZ();

    pos = modelMatrix->TransposeTransformVec(pos);

    //find first face intersection
    int32 minf = INT32_MAX; //nearest intersection distance
    uint32 nearest = 0; //nearest intersection index

    for (uint32 i = 0; i < m_Points.size(); i += 3)
    {
        CIwFVec3 v1 = (CIwFVec3)GetVert(i);
        CIwFVec3 v2 = (CIwFVec3)GetVert(i+1);
        CIwFVec3 v3 = (CIwFVec3)GetVert(i+2);

        float f = 0;
        if (IwIntersectLineTriNorm(pos, dir, v1, v2, v3, m_Norms[i/3], f)) {
            if (f < minf)
            {
                minf = f;
                nearest = i;
            }
        }

		/*{ // Draw the custom resource. Kills fps but helps debugging.
			CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL();
			pMat->SetColAmbient(0xff0000ff);
			pMat->SetCullMode(CIwMaterial::CULL_NONE);
			IwGxSetMaterial(pMat);

			CIwFVec3* verts = IW_GX_ALLOC(CIwFVec3, 3);
			verts[0] = v1;
			verts[1] = v2;
			verts[2] = v3;
			IwGxSetVertStreamModelSpace(verts, 3);
			IwGxDrawPrims(IW_GX_TRI_LIST, NULL, 3);
		}*/
    }

    if (minf != INT32_MAX)
    {
        return nearest;
    }

    return -1;
}