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 - Power

Pages: 1 2 [3] 4 5
31
Quote
Yes! I feel like all classe using Vertices will be inheriting from the transformable class at some point. Maybe there is a purpose having it separated from the other "shape" classes?
sf::VertexArray is a lower level class. It is not the final entity, but it is generally used by those to store their geometry. Making them inherit from sf::Transformable would make this base class redundant in every other drawable class.
The idiom is really to wrap this class (typically with a texture, shader, or whatever) in a higher level drawable / transformable class.
I can only imagine.
Quote
Quote
Humm really? i don't know i don't think so, it seemed like the tutorial said an example or an explantion on how to use the setOrigin to make a shape rotate around its center or other points
So you were talking about explanations on setOrigin itself? Not how to use multiple origins (one for each transformation)?
Both, because both points collide, making it rotate around itself = changing its origin, and giving it multiple origins for multiple transformations, means before every transformation go back the approriate Origin?
Anyway the tutorial says : "read the next chapters", was it referring to the advanced 3x3 matrix transform? Where are these "next chapters?"  ;D

32
Haha yes it's insane how i went astray, but happy to have found the road.
Quote
Do you mean sf::VertexArray?
Yes! I feel like all classe using Vertices will be inheriting from the transformable class at some point. Maybe there is a purpose having it separated from the other "shape" classes?
Quote
Nop. What error did you get?
I remember having a problem at some time, i definitely had, but i just tried again and no error;).

Quote
That was probably referring to sf::Transform.
Humm really? i don't know i don't think so, it seemed like the tutorial said an example or an explantion on how to use the setOrigin to make a shape rotate around its center or other points, will be given. But there were none. (But you know your tutorials better than me:p)

___

Finally, yes i understand that you can't teach C++ here, after all its not called "C++ tutorials" it's all about SFML.

Quote
Thanks for taking the time to do so, that's appreciated ;)
My pleasure ;D

33
Graphics / Re: Splitting the screen with sf::View
« on: April 19, 2020, 03:57:29 pm »
Found the solution !   :P
The draw function had to be written after the clear function, so i took them outside the "window.pollEvent" thing, and it worked

window.clear(sf::Color::White);


                                    window.setView(view3b);
                                    window.draw(RS);
                                    window.setView(view3bSave);
                                    window.draw(RS);



        window.display();

34
Graphics / (Solved) Splitting the screen with sf::View
« on: April 19, 2020, 03:51:03 pm »
Hello,
The non spiltted window shows as this :


The entity that is drawn is the grid, it is a rectangur shape called RS, you will see it mentioned at the end of post.

I try to split the screen in half by having 2 views in the same window like this  (view3b is the main view)
if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::D) // Double view
                  {
                                    sf::View view3bSave=view3b; // i save a copy of the main view)
                                   //   player 1 (left side of the screen)
                                    view3b.setViewport(sf::FloatRect(0.f, 0.f, 0.5f, 1.f));
                                    window.setView(view3b);
                                    // player 2 (right side of the screen)
                                    view3bSave.setViewport(sf::FloatRect(0.5f, 0.f, 0.5f, 1.f));
                                    window.setView(view3bSave);
                  }
 
And i get only the right part :


Then i read this post : https://en.sfml-dev.org/forums/index.php?topic=11526.0
Where it is expalained the "window.draw(world);" has to be done following each "setView".
I tried to draw the rectangular shape (the grid) RD, as following.

                  if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::D) // Double view
                  {
                                    sf::View view3bSave=view3b;
                                   //   player 1 (left side of the screen)
                                    view3b.setViewport(sf::FloatRect(0.f, 0.f, 0.5f, 1.f));
                                    window.setView(view3b);
                                    window.draw(RS);
                                    // player 2 (right side of the screen)
                                    view3bSave.setViewport(sf::FloatRect(0.5f, 0.f, 0.5f, 1.f));
                                    window.setView(view3bSave);
                                    window.draw(RS);

                  }

It did not work ! By the way here is the declaration of the main View :
sf::View view3b;
    view3b.reset(sf::FloatRect(0.f, 0.f, 800.f, 800.f));
// its the size of the window.
What am i missing?

35
Graphics / Re: Expanding size of rotated quads vertices - my method
« on: April 19, 2020, 03:35:21 pm »
Thanks for all the help, i have finally done it.
Here is vertex class :
class VertexFun : public sf::Drawable, public sf::Transformable
{
   private:

       sf::VertexArray V;
       sf::Texture Tex;
    virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const    {
        states.transform *= getTransform();

        // apply the tileset texture
        states.texture = &Tex;
        //states.texture = nullptr;

        // draw the vertex array
        target.draw(V, states);
        }

   public:



        bool VertexShapeContruction3(const std::string& address,sf::Vector2f v0,sf::Vector2f v1,sf::Vector2f v2 )
        {
            if (!Tex.loadFromFile(address)) // load the tileset texture
            {return false;}

              V.setPrimitiveType(sf::Triangles);
              V.resize(3);
              sf::Vertex* quad = &V[0];

                // define its 4 corners
                quad[0].position = v0;
                quad[1].position = v1;
                quad[2].position = v2;
                quad[0].texCoords = v0;
                quad[1].texCoords = v1;
                quad[2].texCoords = v2;
//                 sf::Vertex vertexTab[4] = /// METHODE 3 (Tab)
//                        {
//                            sf::Vertex(sf::Vector2f(400,400),sf::Color::Black),
//                            sf::Vertex(sf::Vector2f(460,450),sf::Color::Yellow),
//                            sf::Vertex(sf::Vector2f(460,500),sf::Color::Blue),
//                            sf::Vertex(sf::Vector2f(400,400),sf::Color::Red)
//                        };
        return true;
        }


        bool VertexShapeContruction4(const std::string& address,sf::Vector2f v0,sf::Vector2f v1,sf::Vector2f v2,sf::Vector2f v3 )
        {
            if (!Tex.loadFromFile(address)) // load the tileset texture
            {return false;}

            V.setPrimitiveType(sf::Quads);
              V.resize(4);
              sf::Vertex* quad = &V[0];

                quad[0].position = v0;
                quad[1].position = v1;
                quad[2].position = v2;
                quad[3].position = v3;
                quad[0].texCoords = v0;
                quad[1].texCoords = v1;
                quad[2].texCoords = v2;
                quad[3].texCoords = v3;
        return true;
        }


};
 
And here is the the use of it :
 VertexFun vertexFun1,vertexFun2,vertexFun3,vertexFun4,vertexFun5;
    vertexFun1.VertexShapeContruction3("data/Thing.png",sf::Vector2f(100,9),sf::Vector2f(123,75),sf::Vector2f(78,75));
    vertexFun2.VertexShapeContruction3("data/Thing.png",sf::Vector2f(190,97),sf::Vector2f(123,122),sf::Vector2f(123,75));
    vertexFun3.VertexShapeContruction3("data/Thing.png",sf::Vector2f(100,186),sf::Vector2f(78,122),sf::Vector2f(123,122));
    vertexFun4.VertexShapeContruction3("data/Thing.png",sf::Vector2f(11,97),sf::Vector2f(78,122),sf::Vector2f(78,75));
    vertexFun5.VertexShapeContruction4("data/Thing.png",sf::Vector2f(123,122),sf::Vector2f(123,75),sf::Vector2f(78,75),sf::Vector2f(78,122));
    ///
    sf::Transform tr;
    vertexFun1.setPosition(100,100); // 100/100 is the center of the original "thing" texture?
    vertexFun2.setPosition(100,100);
    vertexFun3.setPosition(100,100);
    vertexFun4.setPosition(100,100);
    vertexFun5.setPosition(100,100);
    vertexFun1.setOrigin(100,100);
    vertexFun2.setOrigin(100,100);
    vertexFun3.setOrigin(100,100);
    vertexFun4.setOrigin(100,100);
    vertexFun5.setOrigin(100,100);

    float scl=1;
    bool rot=0,lef=0,rig=0,up=0,dow=0,ex=0,con=0;

    while (window.isOpen())
    {


        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed||event.key.code == sf::Keyboard::Escape)
                window.close();

             if (sf::Keyboard::isKeyPressed(sf::Keyboard::R)) ///
                {rot=1;}
               if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::R)
                {rot=0;}
               if(event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left)
              {
                 cout << " The coordinates : " << sf::Mouse::getPosition(window).x << " " << sf::Mouse::getPosition(window).y << endl;

              }
              if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) ///
                {rig=1;}
               if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Right)
                {rig=0;}
              if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) ///
                {lef=1;}
               if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Left)
                {lef=0;}
              if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) ///
                {up=1;}
               if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Up)
                {up=0;}
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) ///
                {dow=1;}
               if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Down)
                {dow=0;}
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::E)) ///
                {ex=1;}
               if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::E)
                {ex=0;}
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::C)) ///
                {con=1;}
               if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::C)
                {con=0;}
        }

        if(rot==1)
        {
                vertexFun5.rotate(15);
                vertexFun4.rotate(15);
                vertexFun3.rotate(15);
                vertexFun2.rotate(15);
                vertexFun1.rotate(15);
        }
        if(rig==1)
        {
                vertexFun5.move(sf::Vector2f(10,0));
                vertexFun4.move(10,0);
                vertexFun3.move(10,0);
                vertexFun2.move(10,0);
                vertexFun1.move(10,0);
        }
        if(rig==1)
        {
                vertexFun5.move(sf::Vector2f(10,0));
                vertexFun4.move(10,0);
                vertexFun3.move(10,0);
                vertexFun2.move(10,0);
                vertexFun1.move(10,0);
        }
        if(lef==1)
        {
                vertexFun5.move(sf::Vector2f(-10,0));
                vertexFun4.move(-10,0);
                vertexFun3.move(-10,0);
                vertexFun2.move(-10,0);
                vertexFun1.move(-10,0);
        }
        if(up==1)
        {
                vertexFun5.move(sf::Vector2f(0,-10));
                vertexFun4.move(0,-10);
                vertexFun3.move(0,-10);
                vertexFun2.move(0,-10);
                vertexFun1.move(0,-10);
        }
        if(dow==1)
        {
                vertexFun5.move(sf::Vector2f(0,10));
                vertexFun4.move(0,10);
                vertexFun3.move(0,10);
                vertexFun2.move(0,10);
                vertexFun1.move(0,10);
        }
        if(ex==1)
        {
                 if(scl<=1.5)
                 {
                     scl=scl+0.1;
                    vertexFun5.setScale(scl,scl);
                    vertexFun4.setScale(scl,scl);
                    vertexFun3.setScale(scl,scl);
                    vertexFun2.setScale(scl,scl);
                    vertexFun1.setScale(scl,scl);
                    cout << " current scale : " << scl << endl;
                  }
        }
        if(con==1)
        {
                if(scl>=0.1)
                  {
                      scl=scl-0.1;


                    vertexFun5.setScale(scl,scl);
                    vertexFun4.setScale(scl,scl);
                    vertexFun3.setScale(scl,scl);
                    vertexFun2.setScale(scl,scl);
                    vertexFun1.setScale(scl,scl);
                    cout << " current scale : " << scl << endl;
                  }
        }


        window.clear(sf::Color::White);
        window.draw(vertexFun1);
        window.draw(vertexFun2);
        window.draw(vertexFun3);
        window.draw(vertexFun4);
        window.draw(vertexFun5);

        window.display();
    }
 

I can finally do what i wanted from the beginning.
Be able to rotate/scale/move a vertex shape any way i want. Here is my feedback :

__________
1) I feel i have been disoriented by 2 things since the beginning :
A) https://en.sfml-dev.org/forums/index.php?topic=26984.0 in this post someone suggested me to use the matrix :
[cos(A)     -sin(A)]
[sin(A)      cos(A)]
And then i continued here https://en.sfml-dev.org/forums/index.php?topic=27070.0
And nobody told to not bother with this kind of matrix to focus on the transformable inhertence possibility, at that moment.

B) Why is the Vertex class, not a transformable from the beginning ??

2) Is it mondatory to have the inheritence from the Drawable class first :
class VertexFun : public sf::Drawable, public sf::Transformable
I am asking because this form
class VertexFun :  public sf::Transformable, public sf::Drawable
Gave me an error message.

3) The gap between the skills required to "ingurgitate" the first first 80% part from the tutorial on transformations is huge between it and and the last examples (Tilemap example). I mean inside that example, there are "resize" functions that a 2 month C++ newcomer would not expect to be part of C++ and not part of the class transformable, also there are useless variables such as the "tv" variable, etc..
Maybe put a simpler example, more graduate.

4) While reading the transformation tutorial : https://www.sfml-dev.org/tutorials/2.5/graphics-transform.php
I read :
Quote
To keep things simple, there's only a single origin for all three transformation components. This means that you can't position an entity relative to its top-left corner while rotating it around its center for example. If you need to do such things, have a look at the next chapters.

I looked inside this chapter and inside the following tutorials, i could find it and still don't. I figured out how it works thogh (i think).

Trying to give a constructive feedback ofcourse, i respect a lot this whole work that has beed done and i,..myself would never be able to bring ou such an awesome website/tool/tutorial(s) to the world (right now).
So thanks again for the great tool that SFML is, and thanks for the help.

36
Graphics / Re: Expanding size of rotated quads vertices - my method
« on: April 18, 2020, 02:34:23 pm »
I think i know what's the problem,
It's because draw derives from the "states" variable which takes an empty texture (&tileset), the question now is :

Is there a way to enforce the colors of the vertex i made (quad[0].color = sf::Color::Red; ..etc) to the state variable, and thus to the final result?

37
Graphics / Re: Expanding size of rotated quads vertices - my method
« on: April 18, 2020, 12:52:03 pm »
Ok so i tried to inherit a class from the "drawable" and "transformable" classes, i named : VertexClass
class VertexClass : public sf::Drawable, public sf::Transformable
{
private:
 virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const    {
 states.transform *= getTransform();
 states.texture = &m_tileset;
 target.draw(m_vertices, states);
}
sf::VertexArray m_vertices; // https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1VertexArray.php
sf::Texture m_tileset;

 public:

    bool construction()
{
 m_vertices.setPrimitiveType(sf::Quads);
 sf::Vertex* quad = &m_vertices[0];
                // define its 4 corners
 quad[0].position = sf::Vector2f(100,100);
 quad[1].position = sf::Vector2f(150,100);
 quad[2].position = sf::Vector2f(150,150);
 quad[3].position = sf::Vector2f(100,150);
 quad[0].color = sf::Color::Red;
 quad[1].color = sf::Color::Yellow;
 quad[2].color = sf::Color::Black;
 quad[3].color = sf::Color::Blue;

return true;
}
};
 

Just for the sake of experimentation, i did not try any rotation or transformation, i just wanted to test the draw function, following the TILEMAP example,
int main()
{
 sf::ContextSettings contextSettings;
 contextSettings.depthBits = 24;
 contextSettings.stencilBits = 8;
 contextSettings.antialiasingLevel = 0;
 contextSettings.majorVersion = 3;
 contextSettings.minorVersion = 3;
sf::RenderWindow window(sf::VideoMode(width, height), "It Works!", sf::Style::Close, contextSettings);
window.setFramerateLimit(30);
VertexClass VC; // class

while (window.isOpen())
{
 sf::Event event;
 while (window.pollEvent(event))
 {
  if (event.type == sf::Event::Closed)
  window.close();
        }
 window.clear(sf::Color::Black);
 window.draw(VC);
 window.display();
    }
    return 0;
}
 

I get a black screen. Why is that?

38
In case any person find this post by doing a research, i will explain how best the code should be done to allow fluid actions :

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
 if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                {u=1;}
 if(event.type == sf::Event::KeyReleased && event.key.code == sf::Keyboard::Up)
                {u=0;}
}

/// outside of window.isOpen
if(u==1){
shiftVertex(CenterObj,10,'d',4);initialPositionY=initialPositionY-10;
shiftVertex(RightObj,10,'d',3);
shiftVertex(LeftObj,10,'d',3);
shiftVertex(UpperObj,10,'d',3);
shiftVertex(BottomObj,10,'d',3);}
}
 

Do this for every action.
It works great.

39
Graphics / Re: Expanding size of rotated quads vertices - my method
« on: April 11, 2020, 10:19:49 am »
Yes indeed, it was really fun to rewrite everything on paper and try hard to find the relation between all the available angles and finally be able to find how to expand the shape.. the way i wanted.
It was also.. painful, painfully good but painful, because it takes some time.

The irony here, is that this is the only way i know of, that achieves this result, and i was hoping by writing all of this, that someone would be encouraged enough to show me how it is done with  "sf::Transformable or sf::Transform" as you say.

I don't wish to continue like that for future crazy interactions i plan for my entities on my future projects, i must learn  the way you do it.


I would like to see just an example using my quad vertices :
sf::VertexArray CenterObj(sf::Quads,4);
    CenterObj[0].position=sf::Vector2f(300,300);
    CenterObj[1].position=sf::Vector2f(400,300);
    CenterObj[2].position=sf::Vector2f(400,400);
    CenterObj[3].position=sf::Vector2f(300,400);
 
( this is the same one from the OP)
And see :
1) How would you inherit it from transformable class.
2) How would you rotate it ... around its center or around any point of the window (not interested in the classical rotation around upper left point of an "item")
3) how to scale it....


___
While i am writing this, and by thinking about what you wrote yesterday, an idea popped in my head, maybe i understood what you meant :
so you guys make vertices shape, put it on a "sprite" and then only after that, you would apply the transform on the item resulted?
I'd rather see an example, i am pretty sure it's easy as cake for you other hero members. I kinda saturated my mind a bit briefly.



40
Hello,
I used a pretty long code to achieve what i wanted, meaning : being able to rotate, move AND expand an item made of vertices in any situation (whichever is value of the rotation angle).
I want first to explain the method i used, then i would like to ask hero members and non hero members, to show me how would they have achieved that with OTHER METHODS? Maybe some advanced methods/functions, or just different methods, i think discovering your methods for doing it might enlarge my understanding and offer a new view in programming, right now i just had to spend some with a paper and a pen to figure out how to achieve the expand item at any rotation angle, but i am pretty sure you guys know way faster methods to do it. So this is the purpose of this topic.
My method :

First of all, i made quad 4-vertices and made a function to rotate it.
sf::VertexArray CenterObj(sf::Quads,4);
    CenterObj[0].position=sf::Vector2f(300,300);
    CenterObj[1].position=sf::Vector2f(400,300);
    CenterObj[2].position=sf::Vector2f(400,400);
    CenterObj[3].position=sf::Vector2f(300,400);
 



Then i made a function that would "expand" it (increase the size of the quad vertices overall), it depends on the angle of rotation, the global rotation angle is saved in a global variables called (save) which grows any time the rotate function is called.
ang=0;
save=ang;
..
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q))
                {
                    ang=4;
                 pivot(CenterObj,ang,4,CenterObj);
                save=save+ang;
}
The rotation function (pivot) here is not important.

If the global rotation(save) is between 0 and 45, the expand function would behave in a certain manner, if the value of the global rotation (save) is between 45 and 90, it would behave in a different manner, same thing if it is between 90 and 135 and finally  between 135 and 180. if save is above 179 it will go back to 0 (using "%"). So we have many areas.. many "zones"
Last observation, all this regions are reversed if the "save" is between 180 and 360.

float zone=save%180;
So in each case i will calculate 2 variables i call "differenceX" and "differenceY", and these 2 variables are the ones that are used to change the values of vertices. This image show them, the algorithm is just below the picture :

void NewExpand(sf::VertexArray &V,float ExpandValue,char item,int NumberOfVertices)
{
    //save=ang;
    float zone=save%180;
//    cout << "save : " << save << endl;
    cout << " zone(real angle) : " << zone << endl;
  if (V.getVertexCount()==4)
  {
    if(zone==0)
    {
      V[0].position.x=V[0].position.x-ExpandValue; V[0].position.y=V[0].position.y-ExpandValue;
      V[1].position.x=V[1].position.x+ExpandValue; V[1].position.y=V[1].position.y-ExpandValue;
      V[2].position.x=V[2].position.x+ExpandValue; V[2].position.y=V[2].position.y+ExpandValue;
      V[3].position.x=V[3].position.x-ExpandValue; V[3].position.y=V[3].position.y+ExpandValue;
      float test = V[0].position.x;
//      cout << "value of of the quad vertices (case 0): " << test << " " << V[1].position.x << " " << V[2].position.x << " " << V[3].position.x << endl;
    }
   else if(zone>0&&zone<45){ Angle2=45-save; /// /zone A
        float PivotedSideRectangle = sqrt((V[1].position.y-V[0].position.y)*(V[1].position.y-V[0].position.y) + (V[1].position.x-V[0].position.x)*(V[1].position.x-V[0].position.x)) ;
        OldHypotenuse=COS(45)*PivotedSideRectangle;
        float NewHypotenuse=OldHypotenuse+ExpandValue;
//        float ExpandedSideNewRect=NewHypotenuse/COS(45); //Idk if this is useful
       float NewY=NewHypotenuse*COS(Angle2); // It's Y on the window eventhouth cosinus
       float NewX=NewHypotenuse*SIN(Angle2);
       float Ypart1=COS(Angle2)*OldHypotenuse;
       float Xpart1=SIN(Angle2)*OldHypotenuse;
       float differenceY=abs(NewY-Ypart1);
       float differenceX=abs(NewX-Xpart1);
    if(save%360>=180)
       {
       V[0].position.x=V[0].position.x+differenceX;
       V[0].position.y=V[0].position.y+differenceY;
       ///
       V[1].position.x=V[1].position.x-differenceY;
       V[1].position.y=V[1].position.y+differenceX;
       ///
       V[2].position.x=V[2].position.x-differenceX;
       V[2].position.y=V[2].position.y-differenceY;
       ///
       V[3].position.x=V[3].position.x+differenceY;
       V[3].position.y=V[3].position.y-differenceX;
       }
       else{
       V[0].position.x=V[0].position.x-differenceX;
       V[0].position.y=V[0].position.y-differenceY;
       ///
       V[1].position.x=V[1].position.x+differenceY;
       V[1].position.y=V[1].position.y-differenceX;
       ///
       V[2].position.x=V[2].position.x+differenceX;
       V[2].position.y=V[2].position.y+differenceY;
       ///
       V[3].position.x=V[3].position.x-differenceY;
       V[3].position.y=V[3].position.y+differenceX;
       }
//       cout << "value of of the quad vertices (case <45) : " << V[0].position.x << " " << V[1].position.x << " " << V[2].position.x << " " << V[3].position.x << endl;
}
 else if(zone==45)
        {
        if(save%360>=180)
       {
          V[0].position.y=V[0].position.y+ExpandValue;
          V[1].position.x=V[1].position.x-ExpandValue;
          V[2].position.y=V[2].position.y-ExpandValue;
          V[3].position.x=V[3].position.x+ExpandValue;
       }
       else
        {
       V[0].position.y=V[0].position.y-ExpandValue;
       V[1].position.x=V[1].position.x+ExpandValue;
       V[2].position.y=V[2].position.y+ExpandValue;
       V[3].position.x=V[3].position.x-ExpandValue;
    }}

 else if(zone>45&&zone<90) /// Zone A2
    {Angle2=save-45;
        double PivotedSideRectangle = sqrt((V[1].position.y-V[0].position.y)*(V[1].position.y-V[0].position.y) + (V[1].position.x-V[0].position.x)*(V[1].position.x-V[0].position.x)) ;
        OldHypotenuse=COS(45)*PivotedSideRectangle;
        float NewHypotenuse=OldHypotenuse+ExpandValue;
        float NewY=NewHypotenuse*COS(Angle2); // It's Y on the window eventhouth cosinus
        float NewX=NewHypotenuse*SIN(Angle2);
        float Ypart1=COS(Angle2)*OldHypotenuse;
        float Xpart1=SIN(Angle2)*OldHypotenuse;
        double differenceY=abs(NewY-Ypart1);
        double differenceX=abs(NewX-Xpart1);
//            cout << PivotedSideRectangle << endl;
//            cout << OldHypotenuse << endl;
        if(save%360>=180)
       {
       V[0].position.x=V[0].position.x-differenceX;
       V[0].position.y=V[0].position.y+differenceY;
       ///
       V[1].position.x=V[1].position.x-differenceY;
       V[1].position.y=V[1].position.y-differenceX;
       ///
       V[2].position.x=V[2].position.x+differenceX;
       V[2].position.y=V[2].position.y-differenceY;
       ///
       V[3].position.x=V[3].position.x+differenceY;
       V[3].position.y=V[3].position.y+differenceX;
       }
       else
       {
       V[0].position.x=V[0].position.x+differenceX;
       V[0].position.y=V[0].position.y-differenceY;
       ///
       V[1].position.x=V[1].position.x+differenceY;
       V[1].position.y=V[1].position.y+differenceX;
       ///
       V[2].position.x=V[2].position.x-differenceX;
       V[2].position.y=V[2].position.y+differenceY;
       ///
       V[3].position.x=V[3].position.x-differenceY;
       V[3].position.y=V[3].position.y-differenceX;
//       cout << "value of of the quad vertices (Case under 90) : " << V[0].position.x << " " << V[1].position.x << " " << V[2].position.x << " " << V[3].position.x << endl;
//       cout << "value of of the quad vertices.Y (Case under 90) : " << V[0].position.y << " " << V[1].position.y << " " << V[2].position.y << " " << V[3].position.y << endl;
}}
else if(zone==90)
        {
             if(save%360>=180)
       {
       V[0].position.x=V[0].position.x-ExpandValue;
       V[1].position.y=V[1].position.y-ExpandValue;
       V[2].position.x=V[2].position.x+ExpandValue;
       V[3].position.y=V[3].position.y+ExpandValue;
       }
       else
       {
       V[0].position.x=V[0].position.x+ExpandValue;
       V[1].position.y=V[1].position.y+ExpandValue;
       V[2].position.x=V[2].position.x-ExpandValue;
       V[3].position.y=V[3].position.y-ExpandValue;
    }}
else if(zone>90&&zone<135)
    {Angle2=90+45-save; /// //Zone B
            double PivotedSideRectangle = sqrt((V[1].position.y-V[2].position.y)*(V[1].position.y-V[2].position.y) + (V[1].position.x-V[2].position.x)*(V[1].position.x-V[2].position.x)) ;
            OldHypotenuse=COS(45)*PivotedSideRectangle;
        float NewHypotenuse=OldHypotenuse+ExpandValue;
        float ExpandedSideNewRect=NewHypotenuse/COS(45); //Idk if this is useful
       float NewY=NewHypotenuse*COS(Angle2); // It's Y on the window eventhouth cosinus
       float NewX=NewHypotenuse*SIN(Angle2);
       float Ypart1=COS(Angle2)*OldHypotenuse;
       float Xpart1=SIN(Angle2)*OldHypotenuse;
       float differenceY=abs(NewY-Ypart1);
       float differenceX=abs(NewX-Xpart1);
//        cout << "angle2 :" << Angle2 << endl;
     if(save%360>=180)
       {
       V[2].position.x=V[2].position.x+differenceY;
       V[2].position.y=V[2].position.y-differenceX;
       V[3].position.x=V[3].position.x+differenceX;
       V[3].position.y=V[3].position.y+differenceY;
       V[0].position.x=V[0].position.x-differenceY;
       V[0].position.y=V[0].position.y+differenceX;
       V[1].position.x=V[1].position.x-differenceX;
       V[1].position.y=V[1].position.y-differenceY;
       }
       else
       {
       V[2].position.x=V[2].position.x-differenceY;
       V[2].position.y=V[2].position.y+differenceX;
       V[3].position.x=V[3].position.x-differenceX;
       V[3].position.y=V[3].position.y-differenceY;
       V[0].position.x=V[0].position.x+differenceY;
       V[0].position.y=V[0].position.y-differenceX;
       V[1].position.x=V[1].position.x+differenceX;
       V[1].position.y=V[1].position.y+differenceY;
//          cout << "value of of the quad vertices (Case under 135) : " << V[0].position.x << " " << V[1].position.x << " " << V[2].position.x << " " << V[3].position.x << endl;
//          cout << "value of of the quad vertices.Y (Case under 135) : " << V[0].position.y << " " << V[1].position.y << " " << V[2].position.y << " " << V[3].position.y << endl;


}}
else if(zone==135)
        {
            if(save%360>=180)
       {
        V[0].position.y=V[0].position.y-ExpandValue;
       V[1].position.x=V[1].position.x+ExpandValue;
       V[2].position.y=V[2].position.y+ExpandValue;
       V[3].position.x=V[3].position.x-ExpandValue;
       }
       else
       {
       V[0].position.y=V[0].position.y+ExpandValue;
       V[1].position.x=V[1].position.x-ExpandValue;
       V[2].position.y=V[2].position.y-ExpandValue;
       V[3].position.x=V[3].position.x+ExpandValue;
    }}
else if(zone>135&&zone<180){Angle2=save-(45+90);
        float PivotedSideRectangle = sqrt((V[1].position.y-V[0].position.y)*(V[1].position.y-V[0].position.y) + (V[1].position.x-V[0].position.x)*(V[1].position.x-V[0].position.x)) ;
        OldHypotenuse=COS(45)*PivotedSideRectangle;
        float NewHypotenuse=OldHypotenuse+ExpandValue;
        float NewY=NewHypotenuse*COS(Angle2); // It's Y on the window eventhouth cosinus
        float NewX=NewHypotenuse*SIN(Angle2);
        float Ypart1=COS(Angle2)*OldHypotenuse;
        float Xpart1=SIN(Angle2)*OldHypotenuse;
        float differenceY=abs(NewY-Ypart1);
        float differenceX=abs(NewX-Xpart1);

        if(save%360>=180)
       {
       V[2].position.x=V[2].position.x+differenceY;
       V[2].position.y=V[2].position.y+differenceX;
       V[3].position.x=V[3].position.x-differenceX;
       V[3].position.y=V[3].position.y+differenceY;
       V[0].position.x=V[0].position.x-differenceY;
       V[0].position.y=V[0].position.y-differenceX;
       V[1].position.x=V[1].position.x+differenceX;
       V[1].position.y=V[1].position.y-differenceY;}
       else {
       V[2].position.x=V[2].position.x-differenceY;
       V[2].position.y=V[2].position.y-differenceX;
       V[3].position.x=V[3].position.x+differenceX;
       V[3].position.y=V[3].position.y-differenceY;
       V[0].position.x=V[0].position.x+differenceY;
       V[0].position.y=V[0].position.y+differenceX;
       V[1].position.x=V[1].position.x-differenceX;
       V[1].position.y=V[1].position.y+differenceY;
//        cout << "value of of the quad vertices (Case under 180) : " << V[0].position.x << " " << V[1].position.x << " " << V[2].position.x << " " << V[3].position.x << endl;
//        cout << "value of of the quad vertices.Y (Case under 180) : " << V[0].position.y << " " << V[1].position.y << " " << V[2].position.y << " " << V[3].position.y << endl;
           }
                             }
  } /// end of : if (V.getVertexCount()==4)
} /// end of function
 

Inside the main, i will call the rotate function "pivot" and check the value of angle, so at each zone i will test the 'NewExpand" function and see if it works. (as shown in the second code of this post, using the letter "Q", check above). Well it does! :)



I am proud to have achieved it. Now i would be happy to see how you do it guys? I have no doubt there are much better and faster and more powerful methods to associate an expand function with a rotate and a movement one for a groupe of vertices or other, with a result expeceted similar to this one :


https://gfycat.com/poisedthinhartebeest

41
Graphics / Re: Using ::transform to rotate vertices
« on: April 11, 2020, 12:16:21 am »
Quote
1. sf::Transform is meant to be a wrapper around a mathematical matrix, so in most cases you don't have to know about matrices, nor about what sf::Transform does internally. Don't use the constructor that takes 9 matrix elements if you don't know what to do with it, just ignore (you can assume it's for "advanced" uses).

2. So, to build your custom transformation, create a sf::Transform instance and translate/rotate/scale it however you like.

3. Then, from it, you can either:
- transform full entites at draw time (ie. it's the GPU that does the job), using sf::RenderStates
Alright,
Quote
- transform single points, using sf::Transform::transformPoint
Interesting, this one i missed, i will explore it next on my to SFML to learn list.
Quote
4. If you want to transform a vertex (it's position), then just write v.position = transform.transformPoint(v.position). But if it's for rendering, use sf::RenderStates instead, when you draw the entity. Transforming points explicitly is rather for computations (collisions, etc.)
Noted, good to know.
Quote
Don't forget to mention what is the problem that you're actually trying to solve (what are you trying to transform? for what purpose?), because instead of focusing on matrices we may have more direct answers to your real problem
Alright, thank you.

42
Graphics / Re: Using ::transform to rotate vertices
« on: April 10, 2020, 10:15:25 am »

Quote
What do you think Transform::rotate does?
It works for shapes but not for vertices.


So i have to find how to use rotate with vertices?
I have to create a class that inherit from transform class, and for every vertix i would be able to apply the rotate thing.. something like that?

43
Java / Re: Android studio - java - sfml
« on: April 09, 2020, 11:37:34 pm »
You can write games in C++ for Android. You should be able to port your existing SFML code to Android or iOS with very little modifications.
Very promising. Thanks a lot.

44
General / Re: Hide the files of your "game" or "app"
« on: April 09, 2020, 11:12:43 pm »
Google has quite a few results when you look for resource compiler and similar keywords. ;)

Don't forget that a simple resource hack tool, will reveal all the images and sounds anyways, so if that's the only reason, it's not really worth it. The ones that want to look at the resource files will find a way regardless - all the AAA games are being reverse engineered to some extend.
True indeed.
I guess it wanted to hide them from random close contacts who would alpha test my game/app.
Okay i will try to search and find how to do it.thx

45
Graphics / Re: Using ::transform to rotate vertices
« on: April 09, 2020, 11:08:19 pm »
Ah, more detail about that is here:
https://en.wikipedia.org/wiki/Rotation_matrix

Scroll down to "In three dimensions".

Rotating in 2D is the same as rotating in 3D around the Z axis.
Aaah Finally thank good! It's been a month i am trying to do this. Now i get it thank youu. The answer was :

@Laurent, nevermind you were right, i just wasn't familiar with rotation matrix a lot in my life recently i guess. You would add just a small, few lines to know what could be inside "mygraphicalEntity" maybe.

The last thing i did not fully understand from the transormations tutorial is how to inherit vertices from transformable class and use these functions. I will probably figure it when analysing the game examples SFML provide.

Thanks again!

Pages: 1 2 [3] 4 5