how do I rotate draw2dpolygon ()

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.

how do I rotate draw2dpolygon ()

Postby Mars_999 » Sat May 25, 2013 2:14 pm

I need to rotate the object that is drawn with the draw2dpolygon () call on the z axis. Is this possible?
Mars_999
 
Posts: 134
Joined: Sat Dec 08, 2012 7:59 pm

Re: how do I rotate draw2dpolygon ()

Postby smso » Mon May 27, 2013 4:36 pm

Please make the question clearer.

Regards,
smso
smso
 
Posts: 241
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: how do I rotate draw2dpolygon ()

Postby Mars_999 » Mon May 27, 2013 5:22 pm

I want to rotate the 2d image in a 360 degree circle. think pinwheel.
Mars_999
 
Posts: 134
Joined: Sat Dec 08, 2012 7:59 pm

Re: how do I rotate draw2dpolygon ()

Postby Mars_999 » Mon May 27, 2013 7:58 pm

cpp 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!
Mars_999
 
Posts: 134
Joined: Sat Dec 08, 2012 7:59 pm


Return to Beginners Help

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest