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

Author Topic: making a new drawable to be able control movement of each pixel.  (Read 1395 times)

0 Members and 1 Guest are viewing this topic.

ankitpaudel20

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
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?

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: making a new drawable to be able control movement of each pixel.
« Reply #1 on: January 21, 2020, 12:26:23 am »
Make sf::Drawable a public inheritance and draw a public function.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: making a new drawable to be able control movement of each pixel.
« Reply #2 on: January 21, 2020, 07:59:05 am »
And don't name that std::map<sf::Vertex, bool> member 'draw' too.
Laurent Gomila - SFML developer

 

anything