void Iw2DSprite::Render(CIwSVec2 pPosition) { if(m_Angle > 0 || m_Angle < 0) { CIwMat2D RotationMatrix; RotationMatrix.SetRot(m_Angle, CIwVec2(pPosition.x + m_Center.x , pPosition.y + m_Center.y) ); Iw2DSetTransformMatrix(RotationMatrix); } if( m_Flip.x > 0 && m_Flip.y > 0) Iw2DSetImageTransform(IW_2D_IMAGE_TRANSFORM_ROT180); else if( m_Flip.x > 0 && m_Flip.y <= 0) Iw2DSetImageTransform(IW_2D_IMAGE_TRANSFORM_FLIP_X); else if( m_Flip.y > 0 && m_Flip.x <= 0) Iw2DSetImageTransform(IW_2D_IMAGE_TRANSFORM_FLIP_Y); Iw2DDrawImageRegion(m_SpriteSheet, pPosition, m_FrameSize, m_DrawRect, m_FrameSize); if(m_Angle > 0 || m_Angle < 0) Iw2DSetTransformMatrix(CIwMat2D::g_Identity); if( m_Flip.x > 0 || m_Flip.y > 0) Iw2DSetImageTransform(IW_2D_IMAGE_TRANSFORM_NONE); }
CIwSVec2 Scythe::getRotatedCoords(CIwSVec2 pos) { IW_CALLSTACK("Scythe::getRotatedCoords"); // Transform matrix by rotation matrix and find what the suppplied position would // be in new post rotation coordinate system Iw2DSetTransformMatrix(mRot); CIwMat2D transformationMatrix = Iw2DGetTransformMatrix(); CIwVec2 transformedPosition = transformationMatrix.TransformVec(pos); Iw2DSetTransformMatrix(CIwMat2D::g_Identity); return CIwSVec2(transformedPosition); }
void renderMapHealth() { IwGxLightingOff(); Iw2DSetAlphaMode(IW_2D_ALPHA_NONE); Iw2DSetTransformMatrix(CIwFMat2D::g_Identity); int16 w = (double)IwGxGetScreenWidth() * 0.09f; if (w > (int16)healthTexture->GetWidth()) w = (int16)healthTexture->GetWidth(); float whScale = (float)((double)healthTexture->GetWidth() / healthTexture->GetHeight()); int16 h = w * 1/whScale; int leftPadding = IwGxGetScreenWidth() * 0.10f; int topPadding = IwGxGetScreenHeight() * 0.02f; int leftMargin = IwGxGetScreenWidth() * 0.03f; int topMargin = IwGxGetScreenHeight() * 0.05f; CIwFVec2 size = CIwFVec2(w, h); int vitality = getGameState()->getPlayer()->getVitality(); for (int i = 0; i < PLAYER_MAX_VITALITY; i++) { CIwFVec2 topLeft = CIwFVec2(leftPadding + (leftMargin+w)*i, topPadding); if (i < vitality) { Iw2DDrawImage(healthTexture, topLeft, size); } else { Iw2DDrawImage(healthLostTexture, topLeft, size); } } }
void Scythe::draw() { IW_CALLSTACK("Scythe::draw"); if(this->bDrawn) return; // TODO: Add some colors to ropes, if we want to keep the ropes like this at all this->DarkGreen.Set(0 , this->green, 127, 255 ); this->LightGreen.Set( 0, 255 - this->green, 127, 255); for(int i = -ROPETHICKNESS; i < ROPETHICKNESS; ++i) { if(i == -ROPETHICKNESS || i == ROPETHICKNESS || i == ROPETHICKNESS / 2) { Iw2DSetColour(this->LightGreen); } else Iw2DSetColour(this->DarkGreen); Iw2DDrawLine(this->getRotatedCoords(CIwSVec2(this->i2Position.x + this->i2Size.x/2, this->i2Position.y - i)), CIwSVec2(this->rotAxis.x, this->rotAxis.y - i/2)); } Iw2DSetColour(0xFFFFFFFF); if ( this->iTimePassed > 32) { if ( this->up ) { ++this->green; } else { --this->green; } if ( this->green >= 255 || this->green <= 0) { this->up = !this->up; } this->iTimePassed = 0; } Iw2DSetTransformMatrix(mRot); //pushmatrix Unit::draw(); Iw2DSetTransformMatrix(CIwMat2D::g_Identity); //popmatrix }
void TileSet::Render(int index,CIwSVec2 topLeft,int rotation) { int ind=index-m_firstGid; if(ind<0) return; int index_X=ind%_tilesPerRow; int index_Y=ind/_tilesPerRow; CIwSVec2 pos = CIwSVec2(index_X * _tilewidth,index_Y * _tileheight); if(rotation!=0) { iwangle angle =90*rotation;//90 degrees CIwSVec2 centre=CIwSVec2(iwsfixed(topLeft.x+(float)_tilewidth/2.0f),iwsfixed(topLeft.y+(float)_tileheight/2.0f)); CIwMat2D rot; rot.SetRot(IW_ANGLE_FROM_DEGREES(angle), CIwVec2(centre)); Iw2DSetTransformMatrix(rot); } Iw2DDrawImageRegion(_image, topLeft, pos, _tileSize); Iw2DSetTransformMatrix(CIwMat2D::g_Identity); }
void N2F::Iw3D::Image::draw(int64 delta, CIwFVec2 offset, float angle, float scale) { CIwFVec2 p = CIwFVec2( ((this->pos.x * this->scaleFactor.scale) + this->scaleFactor.offset.x + offset.x), ((this->pos.y * this->scaleFactor.scale) + this->scaleFactor.offset.y + offset.y) ); CIwFVec2 s = CIwFVec2( (this->size.x * scale), (this->size.y * scale) ); CIwFMat2D m = CIwFMat2D::g_Identity; m.Scale(scale); m.SetRot(angle); m.ScaleRot(scale); m.SetTrans(CIwFVec2((p.x + (s.x / 2)), (p.y + (s.y / 2)))); Iw2DSetTransformMatrix(m); Iw2DDrawImage(this->img, CIwFVec2(-(s.x / 2), -(s.y / 2)), s); Iw2DSetTransformMatrix(CIwFMat2D::g_Identity); return; }
void renderMapPlayer() { IwGxLightingOff(); int16 w = IwGxGetScreenWidth()*0.085f; float whScale = (float)((double)playerTexture->GetWidth() / playerTexture->GetHeight()); int16 h = w * 1/whScale; Iw2DSetAlphaMode(IW_2D_ALPHA_NONE); double angle = rad(getGameState()->getPlayer()->getHeading()); Iw2DSetTransformMatrix(CIwFMat2D::g_Identity); CIwFVec2 centre = CIwFVec2((int16)Iw2DGetSurfaceWidth()/2, (int16)Iw2DGetSurfaceHeight()/2); CIwFMat2D rot; rot.SetRot(angle, (CIwFVec2)centre); Iw2DSetTransformMatrix(rot); CIwFVec2 size = CIwFVec2(w, h); CIwFVec2 topLeft = CIwFVec2(centre.x-size.x/2, centre.y-size.y/2); Iw2DDrawImage(playerTexture, topLeft, size); }
void IGDistorter::set(float _designWidth, float _designHeight) { designWidth = _designWidth; designHeight = _designHeight; // make sure we're dealing with portrait or landscape if(designWidth > designHeight) { if(screenHeight > screenWidth) { float tmp = screenWidth; screenWidth = screenHeight; screenHeight = tmp; } } else { if(screenWidth > screenHeight) { float tmp = screenWidth; screenWidth = screenHeight; screenHeight = tmp; } } float designAspectRatio = designWidth / designHeight; float screenAspectRation = screenWidth / screenHeight; if(designAspectRatio == screenAspectRation) { multiply = screenHeight / designHeight; offsetX = 0; offsetY = 0; } else if(designAspectRatio < screenAspectRation) { multiply = screenHeight / designHeight; offsetX = ((screenWidth/multiply) - designWidth) / 2; offsetY = 0; } else { multiply = screenWidth / designWidth; offsetX = 0; offsetY = ((screenHeight/multiply) - designHeight) / 2; } char debugStr[200]; sprintf(debugStr, "design width: %i, height: %i", (int)designWidth, (int)designHeight); IGLog(debugStr); sprintf(debugStr, "offsetX: %.2f, offsetY: %.2f, multiply: %.2f", offsetX, offsetY, multiply); IGLog(debugStr); // set the scaling matrix matrix = new CIwMat2D(); matrix->SetIdentity(); matrix->Scale(IW_FIXED(multiply)); Iw2DSetTransformMatrix(*matrix); }
// Main entry point for the application int main() { // Initialise Iw2D Iw2DInit(); // Get surface width and height int surface_width = Iw2DGetSurfaceWidth(); int surface_height = Iw2DGetSurfaceHeight(); // Rotation angle of rectangle float angle = 0; // Wait for a quit request from the host OS while (!s3eDeviceCheckQuitRequest()) { // Clear background to blue Iw2DSurfaceClear(0xff8080); // Set up a transform CIwFMat2D mat; mat.SetRot(angle); mat.ScaleRot(2.0f); mat.SetTrans(CIwFVec2((float)surface_width / 2, (float)surface_height / 2)); Iw2DSetTransformMatrix(mat); angle += 0.01f; // Render filled rectangle Iw2DSetColour(0xff00ffff); Iw2DFillRect(CIwFVec2(-50.0f, -100.0f), CIwFVec2(100.0f, 200.0f)); // Render filled arc Iw2DSetColour(0xffff00ff); Iw2DFillArc(CIwFVec2(0, 0), CIwFVec2(100.0f, 100.0f), 0, 1.8 * PI); // Flip the surface buffer to screen Iw2DSurfaceShow(); // Sleep to allow the OS to process events etc. s3eDeviceYield(0); } // Shut down Iw2D Iw2DTerminate(); return 0; }
void CInventory::Draw() { // Only display inventory in certain game states if (g_Game.getGameState() == GS_Playing || g_Game.getGameState() == GS_Paused || g_Game.getGameState() == GS_LevelCompletedFailure || g_Game.getGameState() == GS_LevelCompletedSuccess) { // Set the current font Iw2DSetFont(g_Game.getFont()); // Reset the visual transform Iw2DSetTransformMatrix(CIwMat2D::g_Identity); // Set the texts colour to black //Iw2DSetColour(0xff000000); // HASAN - switched to white since there's a background now Iw2DSetColour(0xffffffff); // Convert the atom count number to text char str[32]; for (int i = 0; i < inventoryCount; i++) { // skip to the next if count is zero - and atom is hidden (i.e. - it was originally in the inventory, but now is fully used and no longer available) if (atomCount[i] <= 0) continue; snprintf(str, 32, "%d", atomCount[i]); // horizontal center, same as inventory graphic int posX = (Iw2DGetSurfaceWidth() / 2) - ( IMAGE_SIZE_WIDTH / 2 ) + 19; int posY = Iw2DGetSurfaceHeight() - ( IMAGE_SIZE_HEIGHT / 2); // offset inventory vertically to fit in the container posX = posX + (10 + (64 / 2)); // NOTE: 64 = atom size, 10 = border + spacing if (i > 0) { posX = posX + (i * (64 + 15)); // NOTE: 64 = atom size, 15 = spacing + border + spacing } // Draw the atom count in the appropriate location Iw2DDrawString(str, CIwSVec2(posX, posY), CIwSVec2(30, 30), IW_2D_FONT_ALIGN_LEFT, IW_2D_FONT_ALIGN_TOP); } } }
void renderMapXpBar() { IwGxLightingOff(); Iw2DSetAlphaMode(IW_2D_ALPHA_NONE); Iw2DSetTransformMatrix(CIwFMat2D::g_Identity); int16 w = (double)IwGxGetScreenWidth() * 0.40f; if (w > (double)xpBarTexture->GetWidth() * 1.80f) w = (double)xpBarTexture->GetWidth() * 1.80f; float whScale = (float)((double)xpBarTexture->GetWidth() / xpBarTexture->GetHeight()); int16 h = w * 1/whScale; int rightPadding = IwGxGetScreenWidth() * 0.10f; int topPadding = IwGxGetScreenHeight() * 0.015f; CIwFVec2 size = CIwFVec2(w, h); CIwFVec2 topLeft = CIwFVec2(IwGxGetScreenWidth() - rightPadding - w, topPadding); Iw2DDrawImage(xpBarTexture, topLeft, size); }
//----------------------------------------------------------------------------- void ExampleRender() { static const CIwSVec2 imageSize(g_Image->GetWidth() >> 3, g_Image->GetHeight() >> 3); static const CIwSVec2 halfImageSize = imageSize >> 1; const CIwSVec2 screenCentre = CIwSVec2((int16)Iw2DGetSurfaceWidth() >> 1, (int16)Iw2DGetSurfaceHeight() >> 1); const b2Transform t = g_body->GetTransform(); const CIwSVec2 pos = screenCentre + (CIwSVec2(int16(t.p.x*8), -int16(t.p.y*8))); const float angle = -t.q.GetAngle() * (180.0f/3.14159f); // reverse angle as our screen-Y coord is reversed CIwMat2D rot; rot.SetRot(iwangle(angle * 1024 / 90), CIwVec2(pos) << 3); Iw2DSetTransformMatrixSubPixel(rot); Iw2DDrawImage(g_Image, pos - halfImageSize, imageSize); // Iw2DSetTransformMatrix(CIwMat2D::g_Identity); Iw2DSurfaceShow(); }
void CameraDefend::Render() { if (defended) { IwGxLightingOff(); animMatSuccess->SetModulateMode(CIwMaterial::MODULATE_NONE); animMatSuccess->SetAlphaMode(CIwMaterial::ALPHA_BLEND); IwGxSetMaterial(animMatSuccess); IwGxSetUVStream(anim_uvs_success); IwGxSetVertStreamScreenSpace(animVertsLeftSuccess, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); IwGxSetVertStreamScreenSpace(animVertsRightSuccess, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); if (animMatSuccess->GetAnimCelID() == animMatSuccess->GetAnimCelNum() - 1) { defended = false; } } else { animMatSuccess->SetAnimCelID(0); } if (!isActive()) return; { Ghost* ghost = getGameState()->getGhost(); GhostAttack* attack = (ghost != NULL) ? ghost->getAttack() : NULL; if (attack != NULL && ((attack->getInterval() < 750 && attack->getInterval() > 600) || (attack->getInterval() < 400 && attack->getInterval() > 250))) { dotTexture = dotTextureRed; } else { dotTexture = dotTextureGreen; } } Iw2DSetAlphaMode(IW_2D_ALPHA_NONE); Iw2DSetTransformMatrix(CIwFMat2D::g_Identity); CIwFMat2D rot; rot.SetRot(rad(dotAngle), CIwFVec2( dotVertsTopLeftLeft.x + dotVertsSizeLeft.x/2, dotVertsTopLeftLeft.y + dotVertsSizeLeft.y/2)); Iw2DSetTransformMatrix(rot); Iw2DDrawImage(dotTexture, dotVertsTopLeftLeft, dotVertsSizeLeft); rot.SetRot(rad(dotAngle), CIwFVec2( dotVertsTopLeftRight.x + dotVertsSizeRight.x/2, dotVertsTopLeftRight.y + dotVertsSizeRight.y/2)); Iw2DSetTransformMatrix(rot); Iw2DDrawImage(dotTexture, dotVertsTopLeftRight, dotVertsSizeRight); bool isDrwaing = true; for (int i = 0; i < DEFEND_TOUCHES_MAX; i++) { // Is any touch drawing? if (touch[i]->drawing) break; if (i == DEFEND_TOUCHES_MAX - 1) { isDrwaing = false; animMat->SetAnimCelID(0); } } if (isDrwaing) { IwGxLightingOff(); animMat->SetModulateMode(CIwMaterial::MODULATE_NONE); animMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND); IwGxSetMaterial(animMat); IwGxSetUVStream(anim_uvs); IwGxSetVertStreamScreenSpace(animVertsLeft, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); IwGxSetVertStreamScreenSpace(animVertsRight, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); } }