Project

General

Profile

How to scale() by using WTransform matrix

Added by Edward Hill over 14 years ago

Hi all,

I am want to try using WTransform::scale() function to scale object but seems to it's not works.

I use this code:

WTransform transform;
 transform = painter.worldTransform();
 transform.scale(size_,size_);
 painter.setWorldTransform(transform);
 painter.scale(size_, size_);
 DrawObject();

Can anybody help me?

// how it's works on example in WidgetGalary i know, but for me interesting use WTransform

Thanks.


Replies (9)

RE: How to scale() by using WTransform matrix - Added by Mohammed Rashad over 14 years ago

Hi Edward,

I dont understand what you are trying to do.

To scale an image you can use

painter.scale(size_,size)

this will scale the image by scaling the WTransform associated with painter

ans is same as

scaling you WTransform and setting the WTransform of painter using painter.setWorldTransform(transform)

you have scale the transform and sets it using setWorldTransform() but the statement painter.scale() is not understood.

PS: sorry my english is not good :)

Can you be more precise?

RE: How to scale() by using WTransform matrix - Added by Edward Hill over 14 years ago

Hi Mohammed,

transformation need for be able dragging my object. When i am try use just painter.scale() it works fine, but can't move my object. This is the reason why i should transform matrix.

RE: How to scale() by using WTransform matrix - Added by Mohammed Rashad over 14 years ago

If you want to drag an image within a viewport I will provide you full source..

RE: How to scale() by using WTransform matrix - Added by Edward Hill over 14 years ago

Thanks, but i using canvas for dragging and don't use image(

RE: How to scale() by using WTransform matrix - Added by Mohammed Rashad over 14 years ago

why are you not using WPainter:Image?

RE: How to scale() by using WTransform matrix - Added by Edward Hill over 14 years ago

This is a long story) I can't using images because presented some specific reason.

RE: How to scale() by using WTransform matrix - Added by Mohammed Rashad over 14 years ago

Take a look at this. It not good coding. But I think it will help you. This code uses some global variables which should not happen. If you have any problem in this code please feel free to ask.

This drags the image over a viewport.

RE: How to scale() by using WTransform matrix - Added by Edward Hill over 14 years ago

Thank you, I will take a look on it.

RE: How to scale() by using WTransform matrix - Added by Wim Dumon over 14 years ago

Edward,

If it's your aim to manipulate (move/rotate/scale) an object, I'd recommend to use the following order for your transformations:

void drawMyObject()
{
  painter.save();
  // transformations to be applied for this object
  painter.translate(...);
  painter.rotate(...);
  painter.scale(...);

  // Draw object here
  painter.moveTo(...);
  painter.lineTo(...);
  ...

  painter.restore();
}

The order of translate/rotate/scale matters! E.g. if you rotate first and then translate, your object will not be rotated around it's own (0,0) coordinate, but will describe a circular motion around the world's (0,0) with a radius equal to the translated distance.

Likewise, if you first scale your axis system (let's say with a factor 3) and then call translate, your object will be moved 3 times as far as you'd expect.

Mixing up rotate and scale (with different x and y scalings) will cause skewed results.

You did not mention what was wrong with the result, but if you see one of these things, you should verify the order of your transformations. Google will help you to find excellent tutorials on 2D transformations.

Best regards,

Wim.

    (1-9/9)