I wanted to write class just like sf::shape but when i try to do so by implementing virtual function draw at sf::drawable i cant what am i missing here??
#pragma once
#include<SFML/Graphics.hpp>
class terrain : sf::Drawable
{
private:
sf::Vector2u window_size;
const sf::Texture* m_texture;
sf::IntRect m_textureRect;
sf::Color m_fillColor;
std::vector<sf::VertexArray> fills;
std::map<sf::Vertex, bool> draw;
sf::VertexArray m_vertices;
sf::FloatRect m_bounds;
bool need_update;
sf::Vector2f computeNormal(const sf::Vector2f& p1, const sf::Vector2f& p2);
float dotProduct(const sf::Vector2f& p1, const sf::Vector2f& p2);
void draw(sf::RenderTarget& target, sf::RenderStates states) const;
};
defination:
#include "terrain.h"
sf::Vector2f terrain::computeNormal(const sf::Vector2f& p1, const sf::Vector2f& p2)
{
sf::Vector2f normal(p1.y - p2.y, p2.x - p1.x);
float length = std::sqrt(normal.x * normal.x + normal.y * normal.y);
if (length != 0.f)
normal /= length;
return normal;
}
float terrain::dotProduct(const sf::Vector2f& p1, const sf::Vector2f& p2)
{
return p1.x * p2.x + p1.y * p2.y;
}
void terrain::draw(sf::RenderTarget &target, sf::RenderStates states) const{
states.texture = m_texture;
target.draw(m_vertices, states);
}
it says
Error C2063 'terrain::draw': not a function
Error C2365 'terrain::draw': redefinition; previous definition was 'data member'
how do i fix this?