Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Amnesty2

Member Since 13 Mar 2007
Offline Last Active Mar 16 2013 01:48 AM
-----

Topics I've Started

Zooming about to a point (2D surface)

24 February 2013 - 04:20 AM

Tiger.jpg

 

 

Hello, I need some help with this math. I've been at this for hours now.

 

I have a large surface (the whole tiger) and a view in blue that is 700,400. Right now, i have it zooming and panning with bounds checking fine, but can't figure out how to zoom to the mouse cursor (red dots).

 

Say, im at 660, 300 local coordinates of view A and zoom in, how do I get what appears in view B? Currently, it just zooms into 0,0 and would get a close up of the ear instead. Basically, I want the functionality of Paint, or Paint.NET or any image editor.

This is all 2D math btw

 

    // x, and y are local coordinates
    void Canvas::setScale(float s, int x, int y) 
    {
        // m_x and m_y are are coordinates into the full canvas
        // the view treats them as 0,0
        // in view marked A, these would something like 200,100 and would be at the tip of the ear
        // after this function i want them to point right above the eye like in the view B example

        float oldscale = m_scale;
        m_scale = s;

        // TODO add the math 

        CheckBounds();
    }

 

Right now, i have some math filled in but it only kinda working.. Its more of a hack and is definately not fluid or percise.
I know there most be a standard way of doing this.
 
 
Thanks
 

Scaling Sprites trouble

05 June 2012 - 07:20 PM

I'm creating a 2D game with DX9 using sprites and want to make a hit point bar.
I created a image that with no scale would fill the hud's life bar to 100% because the bar is exactly the right size when drawn.

It works fine when the scale is 1.0 but at any other value it is not right.
It scales fine the problem is it is drawn in the wrong position.

instead of the it being drawn at
pos1.x = 12;
pos1.y = 768 - 48 + 24;

it looks like it is being drawn at this position
pos1.x = 6;

And then it over laps part of the HUD graphic.

I don't understand why its moving the sprite to the left.. It gets worse the more scale there is.



D3DXVECTOR3 pos1;

pos1.x = 12;

pos1.y = 768 - 48 + 24;

pos1.z = 0;



D3DXMATRIX scale_matrix;

D3DXVECTOR2 scale(0.5f,1.0f); // 50% scale in then x-direciton only

D3DXMATRIX original;



sprite_obj->GetTransform(&original);



D3DXMatrixTransformation2D(&scale_matrix,NULL,0,&scale,NULL,NULL,NULL);

sprite_obj->SetTransform(&scale_matrix);

window::sprite_obj->Draw( txt_manager.get_texture("hp"),NULL,NULL,&pos1, D3DCOLOR_XRGB(255,255,255));

sprite_obj->SetTransform(&original);



do i need to use a translation vector? If so how would i make it right every scale value?
Why is this happening?


Also how can i set the transparency of a sprite at run time before it is drawn?

PARTNERS