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

Author Topic: Drawable group / nested drawables  (Read 2032 times)

0 Members and 1 Guest are viewing this topic.

grymmjack

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Soundgasm Design
Drawable group / nested drawables
« on: June 18, 2013, 03:20:10 am »
Hi! I am currently learning C++ and stumbled into SFML. I really like it. I would love some help with this problem that I'm having though!

Here is the code (VS2010) ~4MB (also see note about sfml.h master include below please if you would be so kind)

I'm trying to render a cannon (like scorched earth kinda idea) with a rectangle for the barrel, and a circle shape for the hole. So far I can do it well, but my hole never lines up with the cannon barrel, even though I am pretty sure I have the right math to do it (I posted the source in the zip). I'm still learning C++ and

What I really want to do is "group" like in illustrator/inkscape the shapes together and then transform them all at once, rotate the angle to adjust the shot of the cannon, etc. and the barrel hole part seamlessly aligns with the barrel part.

I found this in the Wiki:
https://github.com/SFML/SFML/wiki/Tutorial%3A-Drawable-Group

But I have no idea how to implement this.

I have read on another thread that drawing in my own object parents things together?
http://en.sfml-dev.org/forums/index.php?topic=1140.msg7219#msg7219

I tried using the code located in this thread to create the nested drawable but it didn't work. Could someone provide a simple example?

Could someone please illuminate how to implement the DrawableGroup above? I don't know how to do it and would very much appreciate it.

Thanks in advance!





Section of code doing the math is in cannon.h function UpdateCannonAngle:
        float
                radius                  = _barrel_hole.getRadius(),
                angleRadians    = _angle * (float) M_PI / 180.f,
                base_x                  = barrelGb.left + holeOrigin.x + barrelOrigin.x,
                base_y                  = barrelGb.top + holeOrigin.y + barrelOrigin.y,
                x                               = base_x + _barrel.getSize().x * cos(angleRadians),
                y                               = base_y + _barrel.getSize().y * sin(angleRadians);
 
Many thanks!

P.S.

I have a sfml.h file from one of the recommendations here located in base of includes dir:
#pragma once
#ifndef SFMLFULL_INCLUDED
#define SFMLFULL_INCLUDED

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

#if defined(_DEBUG) || defined(DEBUG)
    #if defined(SFML_STATIC)
        #pragma comment(lib,"sfml-graphics-s-d.lib")
        #pragma comment(lib,"sfml-audio-s-d.lib")
        #pragma comment(lib,"sfml-network-s-d.lib")
        #pragma comment(lib,"sfml-window-s-d.lib")
        #pragma comment(lib,"sfml-system-s-d.lib")
        #pragma comment(lib,"sfml-main-d.lib")
    #else
        #pragma comment(lib,"sfml-graphics-d.lib")
        #pragma comment(lib,"sfml-audio-d.lib")
        #pragma comment(lib,"sfml-network-d.lib")
        #pragma comment(lib,"sfml-window-d.lib")
        #pragma comment(lib,"sfml-system-d.lib")
        #pragma comment(lib,"sfml-main-d.lib")
    #endif
#else
    #if defined(SFML_STATIC)
        #pragma comment(lib,"sfml-graphics-s.lib")
        #pragma comment(lib,"sfml-audio-s.lib")
        #pragma comment(lib,"sfml-network-s.lib")
        #pragma comment(lib,"sfml-window-s.lib")
        #pragma comment(lib,"sfml-system-s.lib")
        #pragma comment(lib,"sfml-main.lib")
    #else
        #pragma comment(lib,"sfml-graphics.lib")
        #pragma comment(lib,"sfml-audio.lib")
        #pragma comment(lib,"sfml-network.lib")
        #pragma comment(lib,"sfml-window.lib")
        #pragma comment(lib,"sfml-system.lib")
        #pragma comment(lib,"sfml-main.lib")
    #endif
#endif

#endif // SFMLFULL_INCLUDED

 

anything