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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - mashedtatoes

Pages: 1 [2]
16
Curves would be a neat feature. That actually gives me another idea though. Maybe you can split Shape up even more into a group of Line(s). A line would be a set of continuous points with no curve greater than 180o. A shape is a set of lines chained together (each line shares an endpoint with only two other line). Then you could have curved lines and straight lines on a single shape and make some real funky shapes. So a circle shape would be made with 2 lines. Both of them are 180o curves and they are linked together by their endpoints. A rectangle would be just four lines linked together...

17
CircleShape, RectangleShape, ConvexShape, and Sprite do very similar things. They all apply a texture to some shape. What I am suggesting is to remove the functionality that allows the shapes to be drawable and add the ability to apply a shape to a sprite. Then you create the shape first and pass that shape into the constructor for the sprite. So rather than creating just a CircleShape, you would create a CircleShape then create a sprite using that CircleShape. When you apply the texture to the sprite, it will only give you a circular cutout of the texture.

This does add an extra line of code but, to me, nothing about CircleShape seems like it should be anything more than a shape (just a bunch of points in some space). You shouldn't be able to apply a texture to this shape and draw it because it is just a shape. It shouldn't be able to represent an image. That is where Sprite and Image should be used.

It just seems a lot more intuitive to me if the process of creating a shaped drawable was
  • Create a shape
  • Create a container (sprite) using that shape
  • Apply the texture to the container

Box2D creates shaped objects in a similar way so if I did not explain it very good and you would like some code to look at, you can look at Box2D's b2Fixture.

18
Graphics / Re: sf::Shader::CurrentTexture and texture rects
« on: October 25, 2014, 02:50:21 am »
Now i have to either figure out how to make my shader work on just part of the texture or scrap the big texture and generate new textures as my objects are created. Thanks for the info :).

19
Graphics / sf::Shader::CurrentTexture and texture rects
« on: October 23, 2014, 11:42:36 pm »
For example take a sprite sheet. It is not exactly what I am doing but similar. Lets say you set the texture rect  to the first frame in the animation. When you use sf::Shader::CurrentTexture to set the parameter in the shader code, is this current texture the entire sprite sheet or is it just the part of the texture within the texture rect?

20
Graphics / Re: [Solved] Help with rotating a texture rect around a point
« on: October 15, 2014, 03:40:09 am »
I got it working now here's a gif. There is only one other problem with the texture rect not ending up in the same spot after it rotates 360 degrees but i should be able to figure that out. Now I just need to add a shader to make it look more spherical!  :D

21
Graphics / Re: Help with rotating a texture rect around a point
« on: October 13, 2014, 09:11:31 am »
OOOOOHHHH, i'm using the point in the world coordinates and not the texture coordinates. Thanks for helping me realize that.

22
Graphics / Re: Help with rotating a texture rect around a point
« on: October 13, 2014, 03:45:44 am »
int main(){
                //create window
                sf::RenderWindow window;
                sf::VideoMode mode;
                mode.height = 480;
                mode.width = 360;
                window.create(mode, "spinning planet");
                window.setVerticalSyncEnabled(true);
                window.setFramerateLimit(60);
               
                //create planet
                sf::CircleShape planet;
                sf::Texture map;
                map.loadFromFile("resources/PerlinNoise.png");
                planet.setRadius(40);
                planet.setOrigin(planet.getRadius(), planet.getRadius());
                planet.setPosition(window.getSize().x / 2, window.getSize().y / 2);
                planet.setTexture(&map);
                //pick the middle of the texture
                sf::Vector2i rect = sf::Vector2i(map.getSize().x / 2 - planet.getRadius(), map.getSize().y / 2 - planet.getRadius());
                planet.setTextureRect(sf::IntRect(rect.x, rect.y, 2 * planet.getRadius(), 2 * planet.getRadius()));
                float bigRadius = (std::sqrt(2.0) + 1) * planet.getRadius() - planet.getRadius();
                float angle = 0;
                sf::Vector2f point = planet.getPosition();
                sf::Vector2f centerPoint = sf::Vector2f(planet.getPosition().x, planet.getPosition().y + bigRadius);

                //main loop
                bool play = true;
                while(play){
                        sf::Event event;
                        while(window.pollEvent(event)){
                                if(event.type == sf::Event::Closed){
                                        play = false;
                                }
                        }
                        window.clear();
                        //update planet
                        angle += .1;
                        float s = std::sin(angle * DEGTORAD);
                        float c = std::cos(angle * DEGTORAD);
                        point.x = centerPoint.x * c - centerPoint.y * s;
                        point.y = centerPoint.x * s + centerPoint.y * c;
                        planet.setTextureRect(sf::IntRect(point.x - planet.getRadius(), point.y - planet.getRadius(), planet.getTextureRect().width, planet.getTextureRect().height));
                       
                        //draw/display
                        window.draw(planet);
                        window.display();
                }

                if(window.isOpen()){
                        window.close();
                }
                return 0;
        }

Here is a minimal example. You can pretty much use any large image as the texture. Just change the name in the code. I am still having the same problems after doing this though :(

23
Graphics / [Solved] Help with rotating a texture rect around a point
« on: October 13, 2014, 12:36:48 am »
I am trying to make a planet appear to be rotating on an axis parallel to the plane of the screen (2d game). I have a 5000 x 5000 pixel texture of randomly generated continents/oceans (here is a smaller example. imgur wont let me upload the big one. For each planet I choose a random point on this texture and set the texture rect at this position and the width/height to the diameter of the planet. Here is a drawing to help visualize what I am trying to do and here is a gif of what I have achieved so far but it isn't quite right. In the image, I want the texture rect to translate around the larger circle in a small amount each frame. As for the gif, I honestly have no clue what is causing that stretching stuff as there is nothing like that in the texture. It is possible that it is going out of the bounds of the texture because i don't check for that yet. Any help is appreciated.

Here is the code after setting the texture rect and radius of the circle,

    //this is the radius of the larger circle that the texture rect will move along
        bigRadius = (std::sqrt(2.0) + 1) * circle.getRadius() - circle.getRadius();
    //origin of the circle is set to the center of the circle. this is the point we want to translate (circle is the planets circleshape)
        point = circle.getPosition();
        //point we want to translate around
        centerPoint.x = circle.getPosition().x;
        centerPoint.y = circle.getPosition().y + bigRadius;

Here is my update function (angle is initialized to 0)
        angle += .1;
        float sin = std::sin(angle * DEGTORAD);
        float cos = std::cos(angle * DEGTORAD);
        point.x = centerPoint.x * cos - centerPoint.y * sin;
        point.y = centerPoint.x * sin + centerPoint.y * cos;
        circle.setTextureRect(sf::IntRect(point.x - circle.getRadius(), point.y - circle.getRadius(), circle.getTextureRect().width, circle.getTextureRect().height));

If you watch the gif closely, you can see that the translation is kind of working but I don't know what to do to make it work completely. I also know this is not exactly parallel to the plane of the screen but this is the best I could come up with. Anybody have any ideas?

Pages: 1 [2]