Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Best Way to get the position of an indexed pixel  (Read 2736 times)

0 Members and 1 Guest are viewing this topic.

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Best Way to get the position of an indexed pixel
« on: February 01, 2013, 02:29:44 am »
I guess a noob question, but I was wondering if sf::Sprite.GetMatrix() returns (X.x, X.y, 0, Y.x, Y.y,0,0,0,0), since it was claiming to be a Matrix3 (I assume SFML equiv of a Matrix3x3)? and if it does, is this data relevant to a sf::Sprite that has been rotated and scaled? or will it be relevant to its rotation, but have scaled vectors? and can I request that SFML will in the future have options to edit the Matrix directly, and that it will have a Matrix2.

or would it be wiser to construct the matrix myself, including the data I require? I want to know so that I can write a per-pixel collision function
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Best Way to get the position of an indexed pixel
« Reply #1 on: February 01, 2013, 08:14:01 am »
You're not supposed to use GetMatrix() directly, or know anything about the Matrix class of SFML. What are you trying to do?

SFML 2 has the sf::Transform public class, which wraps a 3x3 matrix. You can use it to transform any SFML entity.
Laurent Gomila - SFML developer

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Re: Best Way to get the position of an indexed pixel
« Reply #2 on: February 01, 2013, 05:26:59 pm »
I want to get the current orientation of my Sprite as it looks on the screen, with  scale, and rotation, after I get its orientation, its all easy from there, I want to multiply a pixel array to it, (the pixel array is an outline of my Sprite), then do a pixel-pixel colision detect, instead of an AABB (eww  ??? ), so I naturally faded to my mathematic roots by looking for a GetMatrix(),  ;) looked at sf::Transform, and I'm not comprehending how to use it to get an orientation? and a raw matrix would be alot easier for me to work with, thanks!  ;D
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Best Way to get the position of an indexed pixel
« Reply #3 on: February 01, 2013, 10:49:44 pm »
Is that what you need?

sf::Transform transform = sprite.getTransform();
sf::Vector2f p = transform.transformPoint(sf::Vector2f(x, y));

sf::Transform is a matrix.
Laurent Gomila - SFML developer

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Re: Best Way to get the position of an indexed pixel
« Reply #4 on: February 01, 2013, 10:57:10 pm »
Yes, ty ;D that's exactly what I wanted to do, and I've decided each time I make some topics on the forum, to do some forum crawling to try to help give back to the community :)
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Re: Best Way to get the position of an indexed pixel
« Reply #5 on: February 03, 2013, 05:14:16 am »
Ok.. so not exactly what I needed, I was using SFML 1.6, so I tried to use TransformToLocal(), but it kept having really odd results, I'm in the middle of switching to 2.0 right now, so that I can use Laurent's code snippet.. lowerCamelCase functions... Lord help me! :'( I knew it would come to this eventually.

On a side note, did you change the image being stored to a vector in 2.0, or is it still an array? :-)
« Last Edit: February 03, 2013, 05:21:07 am by Weeve »
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Best Way to get the position of an indexed pixel
« Reply #6 on: February 03, 2013, 11:19:56 am »
Quote
I was using SFML 1.6, so I tried to use TransformToLocal(), but it kept having really odd results
Don't you need TransformToGlobal instead?

Quote
On a side note, did you change the image being stored to a vector in 2.0, or is it still an array?
Sorry, what are you talking about? And what's the difference between an array and a vector?
Laurent Gomila - SFML developer

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Re: Best Way to get the position of an indexed pixel
« Reply #7 on: February 05, 2013, 09:39:52 pm »
tried transformToGlobal, but got similar problems, so I just made the switch :D

awhile back, I made mention that a sf::Image could only load an image up to a certain size, so I said it was probably being stored as an array, instead of a vector, and it was(I think) you that said you were going to change it in the update. the difference of an array and a vector, is that an array can't rescale, and it grabs the entire amount of ram (for a 32x32 image, for example, would still eat up whatever your max size in pixels is).
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Best Way to get the position of an indexed pixel
« Reply #8 on: February 05, 2013, 10:30:48 pm »
Hmm... no. The image limit is the maximum texture size of the graphics card, and there's nothing I can do about it.

Array or vector, it's the same. The first is raw and requires a lot of code, the second is a wrapper and is easier to reallocate and to get correctly released. There's nothing you can do with one that you can't do with the other.
Laurent Gomila - SFML developer

 

anything