Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6112615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:45:55+00:00 2026-05-23T14:45:55+00:00

Hey so i’ve made a ‘body’ class, which inherits from sf::drawable in SFML that

  • 0

Hey so i’ve made a ‘body’ class, which inherits from sf::drawable in SFML that holds shapes together so i can form more complicated shapes and figures. I found i had to do a few updates on each individual member shape at render time, based on what’s happened to the body over-all since last render.

This included:

  • Rotation
  • Translations
  • Scaling

I thought i would have to manually write the code to factor in these changes that could have occured to the overall body, so the shape positions turned out right. However when coding the Rotation part, i found after writing the manual code that even though i made Bodies Render() function only iterate through and render each shape without changing them, they somehow came out with the right orientation anyway. HOW CAN THIS BE?

I commented out the code i wrote and apparently didn’t need, and i use the Draw() function to render. Please explain to me my own code! (God i feel retarded).

here’s the class:

class Body : public sf::Drawable{ 

    public:
        Body(const sf::Vector2f& Position = sf::Vector2f(0, 0), const sf::Vector2f& Scale = sf::Vector2f(1, 1), float Rotation = 0.f, const sf::Color& Col = sf::Color(255, 255, 255, 255)){
            SetPosition(Position);
            SetScale(Scale);
            SetRotation(Rotation);
            SetColor(Col);
            RotVal=0;};

////////////////// Drawable Functions   ////////////////////
        void SetX(float X){
            MoveVal.x += X - GetPosition().x;
            Drawable::SetX(X);};

        void SetY(float Y){
            MoveVal.y += Y - GetPosition().y;
            Drawable::SetY(Y);};

        void SetRotation(float Rotation){
            RotVal+= Rotation-GetRotation();
            Drawable::SetRotation(Rotation);};
////////////////////////////////////////////////////////////

        bool AddShape(sf::Shape& S){
            Shapes.push_back(S); return true;};
        bool AddSprite(sf::Sprite& S){
            Sprites.push_back(S); return true;};

        void Draw(sf::RenderTarget& target){
            for(unsigned short I=0; I<Shapes.size(); I++){
                //Body offset
                Shapes[I].SetPosition( 
                    Shapes[I].GetPosition().x + MoveVal.x,
                    Shapes[I].GetPosition().y + MoveVal.y);

                // Aparrently Body shapes rotate on their own...
                //WWTFFFF>>>>??????????

                //Body Rotation
                //float px= GetPosition().x,
                //    py= GetPosition().y,
                //    x=  Shapes[I].GetPosition().x,
                //    y=  Shapes[I].GetPosition().y,
                //   rot= ConvToRad(RotVal);

                /*Shapes[I].SetPosition( 
                    px + ((x-px)*cos(rot)) - ((y-py)*sin(rot)),
                    py - ((x-px)*sin(rot)) + ((y-py)*cos(rot)));*/ //TODO: put this in a math header
                //Shapes[I].Rotate(RotVal);
            }

            target.Draw(*this); // draws each individual shape

            //Reset all the Change Values
            RotVal=0;
            MoveVal.x=0;
            MoveVal.y=0;
        };

    private:
        sf::Vector2f MoveVal;
        float         RotVal;
        std::vector<sf::Shape> Shapes;
        std::vector<sf::Sprite> Sprites;

        virtual void Render(sf::RenderTarget& target) const{                
            for(unsigned short I=0; I<Shapes.size(); I++){
                target.Draw(Shapes[I]);}
            for(unsigned short I=0; I<Sprites.size(); I++){
                target.Draw(Sprites[I]);}
        };
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:45:55+00:00Added an answer on May 23, 2026 at 2:45 pm

    My guess was confirmed by the SFML source code.

    When you call target.Draw(*this) it eventually calls Drawable::Draw(RenderTarget& Target) const, which sets up a render matrix which has the rotation that you gave it with the Drawable::SetRotation call. Your virtual Render function is then called, with that rotation environment set up. This means that your body-parts get rotated.

    Have a look at the source yourself to get a better understanding. (;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey i got a contnet type that i made and i want to twweak
Hey I'm building an app that will allow a user to log into a
Hey all I want to reseed my IDENTITY COLUMN values starting from 1 I
Hey I thought about writing a function that prompts me in certain situations (perl
Hey everyone I have a basic search function here that allows me to search
Hey all i have an XML file that i am trying to loop though.
Hey guys I am struggling to create a query which gives schedule of a
Hey I am getting index out of bounds error in my code. From Activity:
Hey can we hide/show tab layout on button click which will be placed below
Hey I'm trying to creare a link that passes the link's text directly to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.