Page 1 of 1

how do I rotate draw2dpolygon ()

Posted: Sat May 25, 2013 2:14 pm
by Mars_999
I need to rotate the object that is drawn with the draw2dpolygon () call on the z axis. Is this possible?

Re: how do I rotate draw2dpolygon ()

Posted: Mon May 27, 2013 4:36 pm
by smso
Please make the question clearer.

Regards,
smso

Re: how do I rotate draw2dpolygon ()

Posted: Mon May 27, 2013 5:22 pm
by Mars_999
I want to rotate the 2d image in a 360 degree circle. think pinwheel.

Re: how do I rotate draw2dpolygon ()

Posted: Mon May 27, 2013 7:58 pm
by Mars_999

Code: Select all

 
static void Draw2DImage(irr::video::IVideoDriver *driver, irr::video::ITexture* texture,
                        irr::core::rect<irr::s32> sourceRect, 
                        irr::core::position2d<irr::s32> position,
                        irr::core::position2d<irr::s32> rotationPoint, 
                        irr::f32 rotation, irr::core::vector2df scale,
                        bool useAlphaChannel, irr::video::SColor color, 
                        irr::s32 level, float radius, const irr::video::SColor& objectColor)
{
    irr::core::matrix4 oldProjMat = driver->getTransform(irr::video::ETS_PROJECTION);
    driver->setTransform(irr::video::ETS_PROJECTION, irr::core::matrix4());
    irr::core::matrix4 oldViewMat = driver->getTransform(irr::video::ETS_VIEW);
    driver->setTransform(irr::video::ETS_VIEW, irr::core::matrix4());
 
    irr::core::vector2df corner[4];
    corner[0] = irr::core::vector2df((irr::f32)position.X, (irr::f32)position.Y);
    corner[1] = irr::core::vector2df((irr::f32)position.X + sourceRect.getWidth() * scale.X, (irr::f32)position.Y);
    corner[2] = irr::core::vector2df((irr::f32)position.X, (irr::f32)position.Y + sourceRect.getHeight() * scale.Y);
    corner[3] = irr::core::vector2df((irr::f32)position.X + sourceRect.getWidth()* scale.X, (irr::f32)position.Y + sourceRect.getHeight() * scale.Y);
 
    for(int x = 0; x < 4; ++x)
        corner[x].rotateBy(rotation, irr::core::vector2df((irr::f32)rotationPoint.X, (irr::f32)rotationPoint.Y));
 
    irr::core::vector2df uvCorner[4];   
    uvCorner[0] = irr::core::vector2df(0,0);
    uvCorner[1] = irr::core::vector2df(0,1);
    uvCorner[2] = irr::core::vector2df(1,0);
    uvCorner[3] = irr::core::vector2df(1,1);
 
    irr::video::S3DVertex vertices[4];
    static irr::u16 indices[6] = {0, 1, 2, 3 ,2 ,1};
 
    float screenWidth  = (irr::f32)driver->getScreenSize().Width;
    float screenHeight = (irr::f32)driver->getScreenSize().Height;
    for(int x = 0; x < 4; ++x)
    {
        float screenPosX = ((corner[x].X/screenWidth)-0.5f)*2.0f;
        float screenPosY = ((corner[x].Y/screenHeight)-0.5f)*-2.0f;
        vertices[x].Pos = irr::core::vector3df(screenPosX,screenPosY,1);
        vertices[x].TCoords = uvCorner[x];
        vertices[x].Color = color;
    }
 
    driver->getMaterial2D().AntiAliasing = irr::video::EAAM_FULL_BASIC;
    driver->draw2DPolygon(irr::core::position2d<irr::s32>(position.X + (radius*.5f), 
                                                          position.Y + (radius*.5f)), 
                          radius, objectColor, level);
 
    irr::video::SMaterial material;
    material.Lighting     = false;
    material.ZWriteEnable = false;
    material.AntiAliasing = irr::video::EAAM_FULL_BASIC;
    material.UseMipMaps   = true;
    material.TextureLayer[0].Texture = texture;
    material.TextureLayer[0].AnisotropicFilter = 16;
    material.TextureLayer[0].TrilinearFilter = true;
    material.TextureLayer[0].TextureWrapU = irr::video::ETC_CLAMP;
    material.TextureLayer[0].TextureWrapV = irr::video::ETC_CLAMP;
    
    if(useAlphaChannel)
        material.MaterialType = irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL;
    else
        material.MaterialType = irr::video::EMT_SOLID;
 
    driver->setMaterial(material);
    driver->drawIndexedTriangleList(&vertices[0], 4, &indices[0], 2);
 
    driver->setTransform(irr::video::ETS_PROJECTION, oldProjMat);
    driver->setTransform(irr::video::ETS_VIEW, oldViewMat);
}
 
I have two issues, the first is the draw2DPolygon() I want to rotate that image on the Z axis like I said a pin wheel or a spinner.

the other is...

the drawIndexedTriangleList() I am trying to put a texture over the image with alpha and wanted to increase it's size by 2. So how can I modify that? Do I need to use setTransform() and make a scaled matrix? or can I modify the texture matrix in the material properties? I am not sure on how this is supposed to be done correctly.

Thanks!