16
Graphics / Inhereting from Transformable+Drawable+VertexArray: getBounds/draw error
« on: April 24, 2020, 05:51:34 pm »
Hello,
I don't know if this should be in the "window help" section or here, but the problem i am presensting here, started when i wanted to get the Bounding boxes of my entities.
I made a class using vertices and wanted to get the bounding boxes through the function "getBounds" by inhereting the class from the "VertexArray" class, like this :
One problem when calling the "draw" function :
Error message is :
I searched on the internet and found these solutions : https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.1.0/com.ibm.zos.v2r1.cbclx01/cplr138.htm
Maybe i did not get it but i tried the following options :
1) So how do we solve this situation if anyone knows?
2) Is there a better method to get the bound box of my verticesClass? (This is way i choose to put the post in the graphics section of the forum).
I don't know if this should be in the "window help" section or here, but the problem i am presensting here, started when i wanted to get the Bounding boxes of my entities.
I made a class using vertices and wanted to get the bounding boxes through the function "getBounds" by inhereting the class from the "VertexArray" class, like this :
class VertexClass : public sf::VertexArray, public sf::Transformable , public sf::Drawable
{
private: /// ///////////////////////////////////////////
sf::VertexArray V;
sf::Texture Tex;
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const {
states.transform *= getTransform();
states.texture = &Tex;
//states.texture = nullptr;
target.draw(V, states);
}
public:/// ////////////////////////////////////////////////////////////////////////////////////////////////
bool VertexFunction(sf::Vector2f v0,sf::Vector2f v1,sf::Vector2f v2 ) //(...,PrimitiveType type)
{
V.setPrimitiveType(sf::Triangles);
V.resize(3);
V[0].position = v0;
V[1].position = v1;
V[2].position = v2;
V[0].texCoords = v0;
V[1].texCoords = v1;
V[2].texCoords = v2;
return true;
}
};
{
private: /// ///////////////////////////////////////////
sf::VertexArray V;
sf::Texture Tex;
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const {
states.transform *= getTransform();
states.texture = &Tex;
//states.texture = nullptr;
target.draw(V, states);
}
public:/// ////////////////////////////////////////////////////////////////////////////////////////////////
bool VertexFunction(sf::Vector2f v0,sf::Vector2f v1,sf::Vector2f v2 ) //(...,PrimitiveType type)
{
V.setPrimitiveType(sf::Triangles);
V.resize(3);
V[0].position = v0;
V[1].position = v1;
V[2].position = v2;
V[0].texCoords = v0;
V[1].texCoords = v1;
V[2].texCoords = v2;
return true;
}
};
One problem when calling the "draw" function :
//main
VertexClass VClass;
VClass.VertexFunction(sf::Vector2f(200,200),sf::Vector2f(400,200),sf::Vector2f(400,400));
....
window.draw(VClass);
VertexClass VClass;
VClass.VertexFunction(sf::Vector2f(200,200),sf::Vector2f(400,200),sf::Vector2f(400,400));
....
window.draw(VClass);
Error message is :
Quote
'sf::Drawable' is an ambiguous base of 'VertexClass'
I searched on the internet and found these solutions : https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.1.0/com.ibm.zos.v2r1.cbclx01/cplr138.htm
Maybe i did not get it but i tried the following options :
window.sf::Drawable::draw(VClass);
//or
window.sf::VertexClass::draw(VClass);
I tried then to modify the class declaration, and added "sf::Drawable" before the draw function declaration. Still have the problem..//or
window.sf::VertexClass::draw(VClass);
1) So how do we solve this situation if anyone knows?
2) Is there a better method to get the bound box of my verticesClass? (This is way i choose to put the post in the graphics section of the forum).