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.


Topics - BruceJohnJennerLawso

Pages: [1]
1
Graphics / What else do I need to call besides sf::Texture::Bind() ?
« on: March 05, 2015, 12:32:34 am »
Okay, so I am trying to create a program with a textured openGL cube,

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>

#define cameraMove 6


void Draw_cube(float size, sf::Image &sideFace);
void Draw_cube_texed(float size, sf::Texture &sideFace);
void Draw_point(float x, float y, float z);
void Draw_pyramid();

int main()
{
    // create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
    window.setVerticalSyncEnabled(true);

    // load resources, initialize the OpenGL states, ...

        glClearDepth(1.0f);
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        // ummm just transparent apparently
       
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_TEXTURE_2D);  
        glDepthMask(GL_TRUE);
       
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(90.0f, 1.0f, 1.0f, 500.0f);

        float cubeSize = 20;

        float cameraDistance = -200;

        sf::RectangleShape rect(sf::Vector2f(1500, 50));
        rect.setFillColor(sf::Color(0, 255, 0, 128));
       
        sf::Texture cubeFace;
        if(!cubeFace.loadFromFile("./crate.png"))
        {       std::cout << "Unable to load image from file" << std::endl;
                return -1;
        }
       

        sf::Clock clock;
    // run the main loop
    bool running = true;
    while (running)
    {
        // handle events
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                // end the program
                running = false;
            }
            else if (event.type == sf::Event::Resized)
            {
                // adjust the viewport when the window is resized
                glViewport(0, 0, event.size.width, event.size.height);
                // this would be better done with forcing the window size back
                // to some constant values
           
                                // or at least forced to a specific scale, as if you change the
                                // width/height ratio, the image ends up being distorted
            }
            if(event.type == sf::Event::KeyPressed)
                        {       if(event.key.code = sf::Keyboard::Up)
                                {       cubeSize += 1;
                                }
                                if(event.key.code = sf::Keyboard::Down)
                                {       cubeSize -= 1;
                                }
                        }
                        if(event.type == sf::Event::MouseWheelMoved)
                        {       cameraDistance += event.mouseWheel.delta*cameraMove;
                        }
                       
                       
        }

        // clear the buffers
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        // erases any previously drawn stuff...
       
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        // beats me...
        glTranslatef(0.0f, 0.0f, cameraDistance);
        // what the, why does it translate every frame
               
                // ohhh, so we can be 200 units back from wherever the
               
                glRotatef(20*cos((clock.getElapsedTime().asSeconds()*0.5)), 1.f, 0.f, 0.f);
                glRotatef((clock.getElapsedTime().asSeconds()*30), 0.f, 1.f, 0.f);
                //glRotatef((clock.getElapsedTime().asSeconds()*90), 0.f, 0.f, 1.f);
                // rotate the camera view a wee bit

                // lets just try with the z axis rotate
                // okay, no
               
                // that does not work

        // draw...
                Draw_cube_texed(cubeSize, cubeFace);
                //Draw_pyramid();
               

               
               
                Draw_point(25, 25, 25);
                window.pushGLStates();

                window.draw(rect);

                window.popGLStates();
               
                int points = std::rand()%10 + 1;
                for(int cy = 0; cy != points; ++cy)
                {       Draw_point((20 + std::rand()%10),(20 + std::rand()%10),(20 + std::rand()%10));
                }
                // kewl

        // end the current frame (internally swaps the front and back buffers)
        window.display();
    }

    // release resources...

    return 0;
}

void Draw_cube(float size, sf::Texture &sideFace)
{       glBegin(GL_QUADS);

        glColor3f(0,0,255);
        // lancelots favourite cube
       
        // I dont care if the joke is old by now dammit!

        glVertex3f(-size, -size, -size);
        glVertex3f(-size,  size, -size);
        glVertex3f( size,  size, -size);
        glVertex3f( size, -size, -size);
        // I guess we define them one at a time in sets of four, hence the quads
        // part...
               
        // and each set of four defines a face...


        sf::Texture::bind(&sideFace);  
        //glTexture
        //glColor3f(255,255,255);
        glNormal3f(0.0, 0.0, 1.0f);
        glTexCoord2f(0,0);
        glVertex3f(-size, -size, size);
        glTexCoord2f(1,0);
        glVertex3f(-size,  size, size);
        glTexCoord2f(1, 1);
        glVertex3f( size,  size, size);
        glTexCoord2f(0,1);
        glVertex3f( size, -size, size);
        //sf::Texture::bind(NULL);     
       
       
        glColor3f(128,128,0);
       
        glVertex3f(-size, -size, -size);
        glVertex3f(-size,  size, -size);
        glVertex3f(-size,  size,  size);
        glVertex3f(-size, -size,  size);

        glColor3f(255,0,0);

        glVertex3f(size, -size, -size);
        glVertex3f(size,  size, -size);
        glVertex3f(size,  size,  size);
        glVertex3f(size, -size,  size);

        glColor3f(128,0,128);

        glVertex3f(-size, -size,  size);
        glVertex3f(-size, -size, -size);
        glVertex3f( size, -size, -size);
        glVertex3f( size, -size,  size);

        glColor3f(0,0,255);

        glVertex3f(-size, size,  size);
        glVertex3f(-size, size, -size);
        glVertex3f( size, size, -size);
        glVertex3f( size, size,  size);



        glEnd();
}

void Draw_point(float x, float y, float z)
{       glBegin(GL_POINTS);
        glColor3f(255,0,0);
        // aha, that works nicely
        glVertex3f(x, y, z);
        glEnd();
}

void Draw_pyramid()
{
       
                glBegin(GL_TRIANGLES);                                                          // Start Drawing A Triangle
                glColor3f(10.0f,0.0f,0.0f);                                             // Red
                glVertex3f( 0.0f, 10.0f, 0.0f);                                 // Top Of Triangle (Front)
                glColor3f(0.0f,10.0f,0.0f);                                             // Green
                glVertex3f(-10.0f,-10.0f, 10.0f);                                       // Left Of Triangle (Front)
                glColor3f(0.0f,0.0f,10.0f);                                             // Blue
                glVertex3f( 10.0f,-10.0f, 10.0f);                                       // Right Of Triangle (Front)
                glColor3f(10.0f,0.0f,0.0f);                                             // Red
                glVertex3f( 0.0f, 10.0f, 0.0f);                                 // Top Of Triangle (Right)
                glColor3f(0.0f,0.0f,10.0f);                                             // Blue
                glVertex3f( 10.0f,-10.0f, 10.0f);                                       // Left Of Triangle (Right)
                glColor3f(0.0f,10.0f,0.0f);                                             // Green
                glVertex3f( 10.0f,-10.0f, -10.0f);                                      // Right Of Triangle (Right)
                glColor3f(10.0f,0.0f,0.0f);                                             // Red
                glVertex3f( 0.0f, 10.0f, 0.0f);                                 // Top Of Triangle (Back)
                glColor3f(0.0f,10.0f,0.0f);                                             // Green
                glVertex3f( 10.0f,-10.0f, -10.0f);                                      // Left Of Triangle (Back)
                glColor3f(0.0f,0.0f,10.0f);                                             // Blue
                glVertex3f(-10.0f,-10.0f, -10.0f);                                      // Right Of Triangle (Back)
                glColor3f(10.0f,0.0f,0.0f);                                             // Red
                glVertex3f( 0.0f, 10.0f, 0.0f);                                 // Top Of Triangle (Left)
                glColor3f(0.0f,0.0f,10.0f);                                             // Blue
                glVertex3f(-10.0f,-10.0f,-10.0f);                                       // Left Of Triangle (Left)
                glColor3f(0.0f,10.0f,0.0f);                                             // Green
                glVertex3f(-10.0f,-10.0f, 10.0f);                                       // Right Of Triangle (Left)
        glEnd();                                                                                        // Done Drawing The Pyramid

}


void Draw_cube_texed(float size, sf::Texture &sideFace)
{       glBegin(GL_QUADS);                          // Start Drawing Quads
    // Front Face
   
        sf::Texture::bind(&sideFace);  
   
    glNormal3f( 0.0f, 0.0f, 1.0f);                  // Normal Pointing Towards Viewer
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 1 (Front)
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 2 (Front)
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Front)
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 4 (Front)
    // Back Face
    glNormal3f( 0.0f, 0.0f,-1.0f);                  // Normal Pointing Away From Viewer
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Back)
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 2 (Back)
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 3 (Back)
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 4 (Back)
    // Top Face
    glNormal3f( 0.0f, 1.0f, 0.0f);                  // Normal Pointing Up
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 1 (Top)
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 2 (Top)
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Top)
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 4 (Top)
    // Bottom Face
    glNormal3f( 0.0f,-1.0f, 0.0f);                  // Normal Pointing Down
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Bottom)
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 2 (Bottom)
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 3 (Bottom)
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 4 (Bottom)
    // Right face
    glNormal3f( 1.0f, 0.0f, 0.0f);                  // Normal Pointing Right
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 1 (Right)
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 2 (Right)
    glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Right)
    glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 4 (Right)
    // Left Face
    glNormal3f(-1.0f, 0.0f, 0.0f);                  // Normal Pointing Left
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Left)
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 2 (Left)
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 3 (Left)
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 4 (Left)
        glEnd();                                // Done Drawing Quads
}

But when I run the function void Draw_cube_texed(float size, sf::Texture &sideFace) in my event loop with a properly loaded texture the cube appears without being textured. What else do I need to include in the function call for the texture to be mapped to the sides of the cube?

2
Okay, so I am working on a space simulator type project in 2D. The Vessels are rendered as flat sprites, which is simple enough, but for the planets and moons I would like to be able to render them as 3d spheres with a rectangular texture mapped to their surfaces. Obviously, the most direct way of doing this would be to use OpenGL, but I would rather not devote all of that time & add another dependency to my project just to do one very simple thing involving 3d graphics.

So my question was, has anyone ever developed any sort of sf::Drawable child class that can take a rectangular texture as input and draw it onscreen as a textured sphere? Or are there any other options that I am missing here that I could try instead?

3
General / Trying to adapt the TileMap example to a class
« on: February 15, 2015, 08:52:30 pm »
Okay, so I am trying to adapt the TileMap example class found here:

http://www.sfml-dev.org/tutorials/2.2/graphics-vertex-array.php

for use in my own project.

I created a quick tileset png file:



And quickly rewrote the class in a header and cpp file:

class Planetary_surface: public sf::Drawable, public sf::Transformable
{       public:
        bool load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height);
        private:
        virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;

    sf::VertexArray m_vertices;
    sf::Texture m_tileset;
};

and cpp

bool Planetary_surface::load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height)
{       // load the tileset texture
        if(!m_tileset.loadFromFile(tileset))
        {       return false;
        }
        // resize the vertex array to fit the level size
        m_vertices.setPrimitiveType(sf::Quads);
        m_vertices.resize(width * height * 4);
        // populate the vertex array, with one quad per tile
        // why is it 4 though...
        for(unsigned int i = 0; i < width; ++i)
        {       for(unsigned int j = 0; j < height; ++j)
                {       // get the current tile number
                        int tileNumber = tiles[i+(j*width)];
                        // find its position in the tileset texture
                        int tu = tileNumber % (m_tileset.getSize().x / tileSize.x);
                        int tv = tileNumber / (m_tileset.getSize().x / tileSize.x);
                        // get a pointer to the current tile's quad
                        sf::Vertex* quad = &m_vertices[(i + j * width) * 4];
                        // define its 4 corners
                        quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
                        quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
                        quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
                        quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);
                        // define its 4 texture coordinates
                        quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
                        quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
                        quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
                        quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
                }
                return true;
        }
}


void Planetary_surface::draw(sf::RenderTarget& target, sf::RenderStates states) const
{       // apply the transform
        states.transform *= getTransform();
        // apply the tileset texture
        states.texture = &m_tileset;
        // draw the vertex array
        target.draw(m_vertices, states);
}

which seems true to the original code

But when I run it, I get this as an output:



Which has the first column drawn properly, but not the rest.

When I copy the example class as it was defined in the original document (just one big class declaration) into the main cpp and use it, it renders everything properly as expected, but when I use the class that I defined in the header/cpp file pair, I keep getting the issue with only the first column being drawn. I cant figure out how the heck that is happening.

4
General / Trying an unusual idea with audio feedback
« on: November 08, 2014, 09:42:29 pm »
Okay, so my current project is very simple, just this:

// typewriter.cpp //////////////////////////////////////////////////////////////
// An SFML program that runs in the background /////////////////////////////////
// playing audio feedback with each keypress ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//#include <std_files>
//#include "Headers.h"
//#include "Headers.hpp"
//#include "Source.cpp"
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>

int main()
{       sf::SoundBuffer buffer;
        if (!buffer.loadFromFile("./chime.ogg"))
        {       return -1;
        }
        else
        {       sf::Sound chime;
                chime.setBuffer(buffer);
                sf::RenderWindow window(sf::VideoMode(300, 20), "typewriter 1.0");
       
                while (window.isOpen())
                {       sf::Event event;
                        while (window.pollEvent(event))
                        {       if(event.type == sf::Event::Closed)
                                {       window.close();
                                }
                                if (event.type == sf::Event::KeyPressed)
                                {       if (event.key.code == sf::Keyboard::K)
                                        {       chime.play();
                                        }
                                }
                        }
                        window.clear();
                        // eventually this can be some sort of logo
                        window.display();
                }
        }
        return 0;
}
 

The goal of the program is to create a cross-platform app that can provide audio feedback while typing, ie playing the sound of a typewriter click every time a key is pressed, so that the user can have feedback while typing beyond just seeing the output on the screen (also keys could be assigned to a specific pitched sound, but thats obviously more complex.

The goal with this project is to create an app that users can start, and run in the background while working on other tasks. The fairly obvious problem is that the program only works when its window is the focus, not useful when working in another application like a text editor or browser. Is there any way that the program could be set up to receive key inputs in the background, so that the sound will play even when another program is the focus?

5
General / Question about 2d sidescroller design
« on: July 25, 2014, 07:19:12 am »
Im currently thinking about creating a simple sidescroller game in C++, have gathered a few useful assets, but Im unsure about a particular design decision with regards to handling game objects.

When I create a character in game, they will need a sprite sheet covering all of the animations they can go through. Once this is loaded into memory, the image can then be assigned pose by pose to individual sprites which can be drawn individually case-by case. (ie the main loop just calls a draw function, which gets the right sf::Sprite based on the current animation state & draws it

The thing I'm not sure about is how best to handle the positioning of the sprites origin, ie should it be located at wherever the characters center of mass is at each image, or should it be at the very bottom of the sprite (at the characters feet)

The gist of my question is whether its easiest in this case to model a character as a physical object with their position denoted at their center of mass, or simply at the characters feet.

6
General / Trying to compile a large project in g++
« on: May 18, 2014, 06:57:45 pm »
This isn't specifically an SFML thing, but it is somewhat involved with how SFML compilation is done on linux g++, so I thought this would be a good place to start.

Im developing a game engine to simulate basic newtonian mechanics in 2d spaceflight games (ie like lunar lander)

https://github.com/BruceJohnJennerLawso/Ignition_Engine/releases/tag/0.01

The above link is to a zip package containing the relevant source that Im trying to compile for the first time. I have SFML 2.1 set up and working properly on Crunchbang Linux. I spent a great deal of time rooting out bugs in my code, but once I got it to compile properly, it gave me some errors at link time:

Final_frontier.o: In function `Inertia_moment::Inertia_moment()':
Final_frontier.cpp:(.text+0x3e91): undefined reference to `vtable for Inertia_moment'
Final_frontier.o: In function `Inertia_moment::~Inertia_moment()':
Final_frontier.cpp:(.text+0x3ebb): undefined reference to `vtable for Inertia_moment'
Final_frontier.o: In function `CSimulation_Object::CSimulation_Object()':
Final_frontier.cpp:(.text+0x5985): undefined reference to `vtable for CSimulation_Object'
Final_frontier.o: In function `CSimulation_Object::~CSimulation_Object()':
Final_frontier.cpp:(.text+0x5a57): undefined reference to `vtable for CSimulation_Object'
Final_frontier.o: In function `Resource_type::Resource_type()':
Final_frontier.cpp:(.text+0x64e5): undefined reference to `vtable for Resource_type'
Final_frontier.o: In function `Resource_type::~Resource_type()':
Final_frontier.cpp:(.text+0x64fb): undefined reference to `vtable for Resource_type'
Final_frontier.o: In function `Resource_hydrogen::Resource_hydrogen()':
Final_frontier.cpp:(.text+0x6521): undefined reference to `vtable for Resource_hydrogen'
Final_frontier.cpp:(.text+0x6532): undefined reference to `Resource_type::R'
Final_frontier.cpp:(.text+0x6615): undefined reference to `Resource_hydrogen::Hydrogen_properties'
Final_frontier.o: In function `Resource_hydrogen::~Resource_hydrogen()':
Final_frontier.cpp:(.text+0x6633): undefined reference to `vtable for Resource_hydrogen'
Final_frontier.o: In function `Resource_oxygen::Resource_oxygen()':
Final_frontier.cpp:(.text+0x6673): undefined reference to `vtable for Resource_oxygen'
Final_frontier.cpp:(.text+0x6684): undefined reference to `Resource_type::R'
Final_frontier.cpp:(.text+0x6767): undefined reference to `Resource_oxygen::Oxygen_properties'
Final_frontier.o: In function `Resource_oxygen::~Resource_oxygen()':
Final_frontier.cpp:(.text+0x6785): undefined reference to `vtable for Resource_oxygen'
Final_frontier.o: In function `Resource_water::Resource_water()':
Final_frontier.cpp:(.text+0x67c5): undefined reference to `vtable for Resource_water'
Final_frontier.cpp:(.text+0x67d6): undefined reference to `Resource_type::R'
Final_frontier.cpp:(.text+0x68b9): undefined reference to `Resource_water::Water_properties'
Final_frontier.o: In function `Resource_water::~Resource_water()':
Final_frontier.cpp:(.text+0x68d7): undefined reference to `vtable for Resource_water'
Final_frontier.o: In function `Engine_type::Engine_type()':
Final_frontier.cpp:(.text+0x69cf): undefined reference to `vtable for Engine_type'
Final_frontier.o: In function `Engine_type::~Engine_type()':
Final_frontier.cpp:(.text+0x69f9): undefined reference to `vtable for Engine_type'
Final_frontier.o: In function `Engine_type_lox_lh2::Engine_type_lox_lh2()':
Final_frontier.cpp:(.text+0x6a66): undefined reference to `Engine_type_lox_lh2::Maximum_exhaust_velocity'
Final_frontier.cpp:(.text+0x6a77): undefined reference to `Engine_type_lox_lh2::Optimal_mix_ratio'
Final_frontier.cpp:(.text+0x6a88): undefined reference to `Engine_type_lox_lh2::Drop_off_constant'
Final_frontier.o: In function `Engine_type_lox_lh2::Get_maximum_exhaust_velocity()':
Final_frontier.cpp:(.text+0x6ae5): undefined reference to `Engine_type_lox_lh2::Maximum_exhaust_velocity'
Final_frontier.o: In function `Engine_type_lox_lh2::Get_optimal_mix_ratio()':
Final_frontier.cpp:(.text+0x6aff): undefined reference to `Engine_type_lox_lh2::Optimal_mix_ratio'
Final_frontier.o: In function `Engine_type_lox_lh2::Get_exhaust_velocity(double)':
Final_frontier.cpp:(.text+0x6b23): undefined reference to `Engine_type_lox_lh2::Optimal_mix_ratio'
Final_frontier.cpp:(.text+0x6b38): undefined reference to `Engine_type_lox_lh2::Maximum_exhaust_velocity'
Final_frontier.cpp:(.text+0x6b42): undefined reference to `Engine_type_lox_lh2::Optimal_mix_ratio'
Final_frontier.cpp:(.text+0x6b58): undefined reference to `Engine_type_lox_lh2::Drop_off_constant'
Final_frontier.cpp:(.text+0x6b75): undefined reference to `Engine_type_lox_lh2::Maximum_exhaust_velocity'
Final_frontier.o: In function `Engine_type_lh2_antimatter::Engine_type_lh2_antimatter()':
Final_frontier.cpp:(.text+0x6c1c): undefined reference to `Engine_type_lh2_antimatter::Maximum_exhaust_velocity'
Final_frontier.cpp:(.text+0x6c28): undefined reference to `Engine_type_lh2_antimatter::Optimal_mix_ratio'
Final_frontier.cpp:(.text+0x6c34): undefined reference to `Engine_type_lh2_antimatter::Drop_off_constant'
Final_frontier.o: In function `Engine_type_lh2_antimatter::Get_maximum_exhaust_velocity()':
Final_frontier.cpp:(.text+0x6c7d): undefined reference to `Engine_type_lh2_antimatter::Maximum_exhaust_velocity'
Final_frontier.o: In function `Engine_type_lh2_antimatter::Get_exhaust_velocity(double)':
Final_frontier.cpp:(.text+0x6cb4): undefined reference to `Engine_type_lh2_antimatter::Maximum_exhaust_velocity'
Final_frontier.o: In function `Vessel_component::Vessel_component()':
Final_frontier.cpp:(.text+0x6ebd): undefined reference to `vtable for Vessel_component'
Final_frontier.o: In function `Vessel_component::~Vessel_component()':
Final_frontier.cpp:(.text+0x6ef5): undefined reference to `vtable for Vessel_component'
Final_frontier.o: In function `Thruster::Set_throttle(double)':
Final_frontier.cpp:(.text+0x88f3): undefined reference to `Throttle::Set_throttle_value(long double)'
Final_frontier.o:(.rodata._ZTV15Armstrong_class[_ZTV15Armstrong_class]+0x58): undefined reference to `Vessel_I::Process_input_events(double, key_commands*)'
Final_frontier.o:(.rodata._ZTV8Vessel_I[_ZTV8Vessel_I]+0x58): undefined reference to `Vessel_I::Process_input_events(double, key_commands*)'
Final_frontier.o:(.rodata._ZTV17CNewtonian_Object[_ZTV17CNewtonian_Object]+0x50): undefined reference to `CSimulation_Object::Set_theta(long double)'
Final_frontier.o:(.rodata._ZTV17CNewtonian_Object[_ZTV17CNewtonian_Object]+0x58): undefined reference to `CSimulation_Object::Process_input_events(double, key_commands*)'
Final_frontier.o:(.rodata._ZTV17CNewtonian_Object[_ZTV17CNewtonian_Object]+0x68): undefined reference to `CSimulation_Object::Draw_object_image(SFML_Window*)'
Final_frontier.o:(.rodata._ZTV17CNewtonian_Object[_ZTV17CNewtonian_Object]+0x70): undefined reference to `CSimulation_Object::Draw_flag(SFML_Window*, int)'
Final_frontier.o:(.rodata._ZTV7TPlanet[_ZTV7TPlanet]+0x10): undefined reference to `TPlanet::Get_object_name()'
Final_frontier.o:(.rodata._ZTV7TPlanet[_ZTV7TPlanet]+0x20): undefined reference to `TPlanet::Get_mass()'
Final_frontier.o:(.rodata._ZTV7TPlanet[_ZTV7TPlanet]+0x28): undefined reference to `TPlanet::Get_x_position()'
Final_frontier.o:(.rodata._ZTV7TPlanet[_ZTV7TPlanet]+0x30): undefined reference to `TPlanet::Get_y_position()'
Final_frontier.o:(.rodata._ZTV7TPlanet[_ZTV7TPlanet]+0x38): undefined reference to `TPlanet::Get_theta()'
Final_frontier.o:(.rodata._ZTV7TPlanet[_ZTV7TPlanet]+0x40): undefined reference to `TPlanet::Set_x_position(long double)'
Final_frontier.o:(.rodata._ZTV7TPlanet[_ZTV7TPlanet]+0x48): undefined reference to `TPlanet::Set_y_position(long double)'
Final_frontier.o:(.rodata._ZTV7TPlanet[_ZTV7TPlanet]+0x50): undefined reference to `TPlanet::Set_theta(long double)'
Final_frontier.o:(.rodata._ZTV7TPlanet[_ZTV7TPlanet]+0x58): undefined reference to `CSimulation_Object::Process_input_events(double, key_commands*)'
Final_frontier.o:(.rodata._ZTV17CKeplerian_Object[_ZTV17CKeplerian_Object]+0x10): undefined reference to `CKeplerian_Object::Get_object_name()'
Final_frontier.o:(.rodata._ZTV17CKeplerian_Object[_ZTV17CKeplerian_Object]+0x50): undefined reference to `CSimulation_Object::Set_theta(long double)'
Final_frontier.o:(.rodata._ZTV17CKeplerian_Object[_ZTV17CKeplerian_Object]+0x58): undefined reference to `CSimulation_Object::Process_input_events(double, key_commands*)'
Final_frontier.o:(.rodata._ZTV17CKeplerian_Object[_ZTV17CKeplerian_Object]+0x68): undefined reference to `CSimulation_Object::Draw_object_image(SFML_Window*)'
Final_frontier.o:(.rodata._ZTV17CKeplerian_Object[_ZTV17CKeplerian_Object]+0x70): undefined reference to `CSimulation_Object::Draw_flag(SFML_Window*, int)'
Final_frontier.o:(.rodata._ZTV17CKeplerian_Object[_ZTV17CKeplerian_Object]+0x80): undefined reference to `CKeplerian_Object::Update_rotation(double)'
Final_frontier.o:(.rodata._ZTI17CNewtonian_Object[_ZTI17CNewtonian_Object]+0x10): undefined reference to `typeinfo for CSimulation_Object'
Final_frontier.o:(.rodata._ZTI8Thruster[_ZTI8Thruster]+0x10): undefined reference to `typeinfo for Vessel_component'
Final_frontier.o:(.rodata._ZTI13Resource_Tank[_ZTI13Resource_Tank]+0x10): undefined reference to `typeinfo for Vessel_component'
Final_frontier.o:(.rodata._ZTI4Hull[_ZTI4Hull]+0x10): undefined reference to `typeinfo for Vessel_component'
Final_frontier.o:(.rodata._ZTI26Engine_type_lh2_antimatter[_ZTI26Engine_type_lh2_antimatter]+0x10): undefined reference to `typeinfo for Engine_type'
Final_frontier.o:(.rodata._ZTI19Engine_type_lox_lh2[_ZTI19Engine_type_lox_lh2]+0x10): undefined reference to `typeinfo for Engine_type'
Final_frontier.o:(.rodata._ZTI17CKeplerian_Object[_ZTI17CKeplerian_Object]+0x10): undefined reference to `typeinfo for CSimulation_Object'
Final_frontier.o:(.rodata._ZTI11Inertia_box[_ZTI11Inertia_box]+0x10): undefined reference to `typeinfo for Inertia_moment'
Final_frontier.o:(.rodata._ZTI14Inertia_sphere[_ZTI14Inertia_sphere]+0x10): undefined reference to `typeinfo for Inertia_moment'
Final_frontier.o:(.rodata._ZTI16Inertia_cylinder[_ZTI16Inertia_cylinder]+0x10): undefined reference to `typeinfo for Inertia_moment'
Final_frontier.o:(.rodata._ZTI15Inertia_complex[_ZTI15Inertia_complex]+0x10): undefined reference to `typeinfo for Inertia_moment'
collect2: error: ld returned 1 exit status
 

I checked the undefined reference to vtable error, but it doesnt appear to make sense in this context. If the cpp files include each other one by one, all of the code should be properly included in the Final_frontier.o object, but the compiler appears to not be able to find the code needed in the code produced by the compiler.

my scripts for compiling and linking are as follows:

#!/bin/bash

g++ -c -std=c++0x Final_frontier.cpp

exit 0

#!/bin/bash

g++ Final_frontier.o  -o Final_frontier -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio

exit 0

Where am I going wrong here? Is there just something stupid that I have done in my code, or am I not understanding the compilation & linking process?

7
Window / undefined reference to sf::Window::setSize()
« on: March 30, 2014, 11:39:08 pm »
Okay,

so I finally figured out how to link SFML on crunchbang linux properly!!!  ;D

I compiled one of my basic SFML programs, specifically this one:

https://github.com/BruceJohnJennerLawso/xkcd-Now

Which works fine except for one function call, specifically sf::Window::setSize(sf::Vector2<unsigned int> const&)

If the line in question for that call is commented out, the program works fine, but when uncommented it causes an error at linking time, when it spits out this:

Now.cpp:(.text+0x455): undefined reference to `sf::Window::setSize(sf::Vector2<unsigned int> const&)'
 

After doing a little research, it sounds as if this problem could be caused by different function prototypes & definitions.

In the SFML header files that I am using, I have

    ////////////////////////////////////////////////////////////
    /// \brief Change the size of the rendering region of the window
    ///
    /// \param size New size, in pixels
    ///
    /// \see getSize
    ///
    ////////////////////////////////////////////////////////////
    void setSize(const Vector2u& size);

I did compile SFML from scratch, so maybe its possible that this function was inadvertently changed at some point? (without updating the header file to match?)

8
General / Linux setup troubles
« on: March 10, 2014, 11:11:23 pm »
Hey everybody,

So I'm trying to get my C++ development projects set up on Crunchbang Linux. I've downloaded the SFML libraries needed, and I'm trying to run the basic functionality test, ie

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}
 

I then go to the terminal & try

g++ -c Testrun.cpp

as the tutorial says, but I get

Testrun.cpp: In function ‘int main()’:
Testrun.cpp:6:5: error: ‘CircleShape’ is not a member of ‘sf’
Testrun.cpp:6:21: error: expected ‘;’ before ‘shape’
Testrun.cpp:7:5: error: ‘shape’ was not declared in this scope
Testrun.cpp:9:19: error: ‘class sf::RenderWindow’ has no member named ‘isOpen’
Testrun.cpp:12:23: error: ‘class sf::RenderWindow’ has no member named ‘pollEvent’
Testrun.cpp:14:23: error: ‘class sf::Event’ has no member named ‘type’
Testrun.cpp:15:24: error: ‘class sf::RenderWindow’ has no member named ‘close’
Testrun.cpp:18:16: error: ‘class sf::RenderWindow’ has no member named ‘clear’
Testrun.cpp:19:16: error: ‘class sf::RenderWindow’ has no member named ‘draw’
Testrun.cpp:20:16: error: ‘class sf::RenderWindow’ has no member named ‘display’
 

Which appears to indicate that the hierarchy of #includes has screwed up somewhere? Ive also noticed that g++ needs cpp files included explicitly (which was not necessary in MSVC++ 2010, oddly enough), maybe I need to do something similar here?

Thanks for any help in getting this running. :)


9
SFML projects / Countdown-Alert release
« on: February 16, 2014, 12:10:33 am »
Greetings fellow developers,

After my first try at developing a game engine in SFML, I decided to undertake a much smaller project to get my feet wet in SFML, as well as replacing a pair of heavily outdated C++ programs, which I used as an alarm clock & notification timer, respectively.

The project was hacked together in a relatively short time, but appears to work quite well for me. Hopefully someone else will find it useful as well. The project can be found at:

https://github.com/BruceJohnJennerLawso/Countdown-Alert/tree/master

Release 1.00 available here:

https://github.com/BruceJohnJennerLawso/Countdown-Alert/releases/tag/1.00

Any criticism/comments are welcome.

10
Audio / Trouble with sf::Sound
« on: February 01, 2014, 09:02:02 pm »
Im trying to set up my program so that it will play a small ogg file through a function as follows:

void Timer_Alarm()
{       sf::SoundBuffer buffer;
        if (!buffer.loadFromFile("C:\\Users\\Development\\Documents\\Visual Studio 2010\\Projects\\Countdown\\Release\\Countdown\\Audio\\ElapsedTimer.ogg"))
        {       Cmd_dashdash::Newline();
                Cmd_dashdash::Print_line("Unable to Load Audio");
        }
        else
        {       sf::Sound output;
                output.setBuffer(buffer);
                output.play();
                Cmd_dashdash::Print_line("Able to Load Audio");
        }
}

The perplexing thing is that the program gives me the "Able to load Audio" feedback, but never plays the sound. (and yes, I do have the volume on  ::))

The ogg file otherwise seems fine, but I did create it in audacity. Is it possible that there might be some issue with the way it was created?

11
SFML projects / Ignition Engine
« on: January 08, 2014, 10:29:38 pm »
Hello!

I'm new to this forums, and a little green to SFML, but I wanted to post what I have so far in terms of a SFML engine. A lot of the code is from scratch, but a few parts like the camera class are based off of a tutorial I found on dreamincode:

Ignition engine:

#pragma once
#include <SFML\Graphics.hpp>
#include <exception>

////////////////////////////////////////////////////////////////////////////////////////////////
// Ignition 2D Engine v 1.01 ///////////////////////////////////////////////////////////////////
// Written in C++ & SFML by John Lawson ////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////


namespace Ignition
{       class Texture_Manager
        {       public:
                Texture_Manager();
                private:
                std::vector<sf::Texture*> Texture_list;
                public:
                void Add_texture(sf::Texture * iTexture);
                void Smooth_texture(unsigned int index, bool smooth);
            sf::Texture * Get_texture(unsigned int index);
                ~Texture_Manager();
        };

        class CSprite
        {       public:
                CSprite(sf::Texture * texture, float iox, float ioy);
                CSprite(sf::Texture * texture, float iox, float ioy, unsigned int a, unsigned int b, unsigned int c, unsigned int d);
                protected:
                sf::Sprite * Object_sprite;
                virtual void Frame(float dt);                           // Frame updater to be defined in derived classes.
                public:                                                                         // Similar virtual for checking whether the object is in       
                virtual bool In_render(sf::IntRect rBounds);    // the area to be drawn
                float Get_theta();
                sf::Vector2i Get_pos();
                float Get_x();
                float Get_y();
                void Set_theta(float itheta);
                void Set_position(float ix, float iy);
                void Colour_sprite(int red, int green, int blue, int alpha);
                void Colour_sprite(int red, int green, int blue);
                void Draw_sprite(int x, int y, sf::RenderWindow * rwindow);
                void Draw_sprite(sf::RenderWindow * rwindow);
                ~CSprite();    
        };

        class Camera
        {       public:
                Camera(unsigned int h, unsigned int w, unsigned int pofs_x, unsigned int pofs_y);
                Camera(unsigned int h, unsigned int w, unsigned int pofs_x, unsigned int pofs_y, CSprite * iTgt);
                Camera(unsigned int h, unsigned int w, float ispeed, unsigned int pofs_x, unsigned int pofs_y);
                Camera(unsigned int h, unsigned int w, float ispeed, unsigned int pofs_x, unsigned int pofs_y, CSprite * iTgt);
                void Translate_camera(int x,int y);
                void Translate_camera_center(int x, int y);
                void Camera_goto(int x,int y);                                                  // dont worry, not that kind of goto
                void Camera_center_goto(int x, int y);                                  // Sends the camera to a coordinate in "the world"
                void Update_camera();
                void Set_cam_tgt(sf::Vector2i iPos);
                sf::Vector2i* Get_cam_pos();
                sf::Vector2i* Get_cam_size();
                sf::Vector2i* Get_Cam_port_ofs();
                sf::IntRect Get_cam_window();
                CSprite * this_cTgt;
                private:
                sf::Vector2f * Cam_pos;
                sf::Vector2i * Cam_size;
                sf::Vector2f * Cam_tgt;
                sf::Vector2i * Cam_port_ofs;    // Offset from standard render position in the portal window
                float speed;                            // Not strictly necessary, but I may want the camera to have a "lag" motion behind the target, probably great for ConquerSpace
                public:                                         // velocity, speed, dammit. Must respect physics, augh!!!
                friend class Ignition_Engine;
                ~Camera();
        };

        class Portal
        {       public:
                Portal(unsigned int h, unsigned int w, int bpp, std::string wTitle);    // The cake is a lie, apparently.
                void Add_camera_view(Camera * iCam);    // Least, nobody ever gave me any for coding anything.
                sf::RenderWindow * pPortal;    
                std::vector<Camera*> Cam_views;
                public:
                ~Portal();                      // But this is a triumph :)
        };
       
        struct Portal_arg
        {       unsigned int h, w;
                int bpp;
                std::string ptitle;
        };

        class Ignition_Engine
        {       public:
                Ignition_Engine(void (*function)(Ignition_Engine* ithis));
                void Ignition(std::vector<std::string> Load_paths, unsigned int h, unsigned int w, int bpp, std::string wTitle);
                void Ignition(std::vector<std::string> Load_paths, std::vector<Portal_arg> Portal_args, unsigned int h, unsigned int w, int bpp, std::string wTitle);
            Texture_Manager Manager;
                std::vector<Camera*> Engine_cams;
                Portal * Main_portal;
                std::vector<Portal*> Sub_portals;
            void Load_texture(std::string file_path);
                void Register_sprite(CSprite * iSprite);             
                std::vector<CSprite*> Sprite_Objects;
                CSprite * eTgt;                 // The primary engine target (ie, usually the current player input that we want to follow);
                private:
                bool Start(unsigned int h, unsigned int w, int bpp, std::string wTitle);                                // Engine Start (The Engines are on!)          
                void Loop();                            // Main Loop()
                void Render_frame();            // {    Renders the graphical output
                void Process_input();           //              Handle user input
                void Update();                          //              Update program internals
                public:                                         // }
                ~Ignition_Engine(void);
        };
       
        void Construct_portal(unsigned int h, unsigned int w, int bpp, std::string wTitle, Ignition_Engine * this_engine);
}

#include "Ignition_Engine.h"
#include <math.h>
#include <vector>


// Ignition Engine ///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

Ignition::Ignition_Engine::Ignition_Engine(void (*function)(Ignition_Engine* ithis))
{       (*function)(this);      // Pass in the new arguments to the engine starting up
}

void Ignition::Ignition_Engine::Ignition(std::vector<std::string> Load_paths, unsigned int h, unsigned int w, int bpp, std::string wTitle)
{       if (!Start(h, w, bpp, wTitle))
        {       throw "Ignition_Failure";
        }
        else
        {       for (std::vector<std::string>::iterator it = Load_paths.begin(); it != Load_paths.end(); ++it)
                {       Load_texture(*it);
                }      
                Loop();
        }
}       // Lights this candle. Yeah baby. Yeah.

void Ignition::Ignition_Engine::Ignition(std::vector<std::string> Load_paths, std::vector<Portal_arg> Portal_args, unsigned int h, unsigned int w, int bpp, std::string wTitle)
{       if (!Start(h, w, bpp, wTitle))
        {       throw "Ignition_Failure";
        }
        else
        {       for (std::vector<std::string>::iterator it = Load_paths.begin(); it != Load_paths.end(); ++it)
                {       Load_texture(*it);
                }
                for (std::vector<Portal_arg>::iterator itArg = Portal_args.begin(); itArg != Portal_args.end(); ++itArg)
                {       Construct_portal(itArg->h, itArg->w, itArg->bpp, itArg->ptitle);
                }
                Loop();
        }
}       // Lights this candle. Yeah baby. Yeah.

void Ignition::Ignition_Engine::Load_texture(std::string file_path)
{       sf::Texture * Tex;      // Trustworthy files of course
        Tex = new sf::Texture();
        Tex->loadFromFile(file_path);
        Manager.Add_texture(Tex);
}       // Load a texture into the managed list

void Ignition::Ignition_Engine::Register_sprite(CSprite * iSprite)
{       Sprite_Objects.push_back(iSprite);
}       // Register a sprite... for iteration of members inheriting from parent class CSprite

bool Ignition::Ignition_Engine::Start(unsigned int h, unsigned int w, int bpp, std::string wTitle)
{       Main_portal = new Portal(Engine_cams, h, w, bpp, wTitle);
        if(!(Main_portal->pPortal))
        {       return false;
        }
        else
        {       return true;
        }
}

void Ignition::Ignition_Engine::Loop()
{       while(Main_portal->pPortal->isOpen())
        {       Process_input();
                Update();
                Render_frame();
        }
}

void Ignition::Ignition_Engine::Render_frame()
{       for (std::vector<Portal*>::iterator it = Sub_portals.begin(); it != Sub_portals.end(); ++it)
        {       (*it)->pPortal->clear();
        }       Main_portal->pPortal->clear();
        sf::Vector2i * rend_ofs;
        for (std::vector<Portal*>::iterator itPortal = Sub_portals.begin(); itPortal != Sub_portals.end(); ++itPortal)
        {       for (std::vector<Camera*>::iterator itCamera = (*itPortal)->Cam_views.begin(); itCamera != (*itPortal)->Cam_views.end(); ++itCamera)
                {       if(!((*itCamera)->Cam_tgt))
                        {       (*itCamera)->this_cTgt = eTgt;
                                (*itCamera)->Cam_tgt = new sf::Vector2f(eTgt->Get_pos());
                        }
                        for (std::vector<CSprite*>::iterator itSprites = Sprite_Objects.begin(); itSprites != Sprite_Objects.begin(); ++itSprites)
                        {       if ((*itSprites)->In_render((*(*itCamera)->Get_cam_window())) == true)
                                {       rend_ofs = new sf::Vector2i( *((*itCamera)->Get_Cam_port_ofs()) + ((*itSprites)->Get_pos()) );
                                        (*itSprites)->Draw_sprite((rend_ofs)->x, (rend_ofs)->y, (*itPortal)->pPortal);
                                        delete  rend_ofs;
                                }      
                        }
                }
        }
}

void Ignition::Ignition_Engine::Process_input()
{       sf::Event Input_Events;
        while(Main_portal->pPortal->pollEvent(Input_Events))
        {       if (Input_Events.type == sf::Event::Closed)
                {       this->~Ignition_Engine();
                }
        }
}

void Ignition::Ignition_Engine::Update()
{
}

Ignition::Ignition_Engine::~Ignition_Engine(void)
{       for (std::vector<CSprite*>::iterator it = Sprite_Objects.begin(); it != Sprite_Objects.end(); ++it)
        {       delete *it;
        }       Sprite_Objects.clear();
        Manager.~Texture_Manager();
        for (std::vector<Portal*>::iterator itPortal = Sub_portals.begin(); itPortal != Sub_portals.end(); ++itPortal)
        {       delete (*itPortal);
        }       delete Main_portal;
}




// Ignition::Texture manager class ///////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

Ignition::Texture_Manager::Texture_Manager()
{
}

void Ignition::Texture_Manager::Add_texture(sf::Texture * iTexture)
{       Texture_list.push_back(iTexture);
}

void Ignition::Texture_Manager::Smooth_texture(unsigned int index, bool smooth)
{       Texture_list[index]->setSmooth(smooth);
}

sf::Texture * Ignition::Texture_Manager::Get_texture(unsigned int index)
{       return Texture_list[index];    
}

Ignition::Texture_Manager::~Texture_Manager()
{       for(std::vector<sf::Texture*>::iterator it = Texture_list.begin(); it != Texture_list.end(); ++it)
        {       delete *it;
        }       Texture_list.clear();
}




// Ignition::Sprite parent class /////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

Ignition::CSprite::CSprite(sf::Texture * texture, float iox, float ioy)
{       Object_sprite = new sf::Sprite();
        Object_sprite->setTexture(*texture);
        Object_sprite->setOrigin(iox, ioy);     // Reset the origin by given coordinates
}       // Constructs the Tile object and assigns it the texture that it uses

Ignition::CSprite::CSprite(sf::Texture * texture, float iox, float ioy, unsigned int a, unsigned int b, unsigned int c, unsigned int d)
{       Object_sprite->setTexture(*texture);
        Object_sprite->setTextureRect(sf::IntRect(a, b, c, d)); // Explicitly defining the texture coordinates of the sprite in the given texture
        Object_sprite->setOrigin(iox, ioy);     // Reset the origin by given coordinates
}       // Constructs the Tile object and assigns it the texture that it uses

float Ignition::CSprite::Get_theta()
{       return (Object_sprite->getRotation());
}       // Get the rotation of the sprite as float.

sf::Vector2i Ignition::CSprite::Get_pos()
{       sf::Vector2i pos((int)Get_x(),(int)Get_y());
        return pos;
}

float Ignition::CSprite::Get_x()
{       return (Object_sprite->getPosition().x);
}

float Ignition::CSprite::Get_y()
{       return (Object_sprite->getPosition().y);
}

void Ignition::CSprite::Set_theta(float itheta)
{       Object_sprite->setRotation(itheta);
}

void Ignition::CSprite::Set_position(float ix, float iy)
{       Object_sprite->setPosition(ix, iy);
}

void Ignition::CSprite::Colour_sprite(int red, int green, int blue, int alpha)
{       Object_sprite->setColor(sf::Color(red, green, blue, alpha));
}

void Ignition::CSprite::Colour_sprite(int red, int green, int blue)
{       Object_sprite->setColor(sf::Color(red, green, blue));
}

void Ignition::CSprite::Draw_sprite(int x, int y, sf::RenderWindow * rwindow)
{       Object_sprite->setPosition(x, y);
    rwindow->draw(*Object_sprite);
}

void Ignition::CSprite::Draw_sprite(sf::RenderWindow * rwindow)
{       rwindow->draw(*Object_sprite);
}

Ignition::CSprite::~CSprite()
{       delete Object_sprite;
}



// Ignition::Portal class ////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

Ignition::Portal::Portal(unsigned int h, unsigned int w, int bpp, std::string wTitle)
{       pPortal = new sf::RenderWindow(sf::VideoMode(w, h, bpp), wTitle);
}

void Ignition::Portal::Add_camera_view(Camera * iCam)
{       Cam_views.push_back(iCam);
}

Ignition::Portal::~Portal()
{       Cam_views.clear();
        pPortal->close();
        delete pPortal;
}      




// Ignition::Camera class ////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

Ignition::Camera::Camera(unsigned int h, unsigned int w, unsigned int pofs_x, unsigned int pofs_y)
{       Cam_size = new sf::Vector2i(w, h);
        Cam_pos = new sf::Vector2f(0.000, 0.000);
        Cam_port_ofs = new sf::Vector2i(pofs_x, pofs_y);
        speed = 1.000;
}

Ignition::Camera::Camera(unsigned int h, unsigned int w, unsigned int pofs_x, unsigned int pofs_y, CSprite * iTgt)
{       Cam_size = new sf::Vector2i(w, h);
        Cam_pos = new sf::Vector2f(0.000, 0.000);
        Cam_port_ofs = new sf::Vector2i(pofs_x, pofs_y);
        speed = 1.000;
        this_cTgt = iTgt;
        Cam_tgt = new sf::Vector2f((this_cTgt->Get_pos()));
}

Ignition::Camera::Camera(unsigned int h, unsigned int w, float ispeed, unsigned int pofs_x, unsigned int pofs_y)
{       Cam_size = new sf::Vector2i(w, h);
        Cam_pos = new sf::Vector2f(0.000, 0.000);
        Cam_port_ofs = new sf::Vector2i(pofs_x, pofs_y);
        speed = ispeed;
}

Ignition::Camera::Camera(unsigned int h, unsigned int w, float ispeed, unsigned int pofs_x, unsigned int pofs_y, CSprite * iTgt)
{       Cam_size = new sf::Vector2i(w, h);
        Cam_pos = new sf::Vector2f(0.000, 0.000);
        Cam_port_ofs = new sf::Vector2i(pofs_x, pofs_y);
        speed = ispeed;
        this_cTgt = iTgt;
        Cam_tgt = new sf::Vector2f((this_cTgt->Get_pos()));
}

void Ignition::Camera::Translate_camera(int x, int y)
{       Cam_pos->x = (float)x;
        Cam_pos->y = (float)y;
        Cam_tgt = Cam_pos;
}

void Ignition::Camera::Translate_camera_center(int x, int y)
{       x -= ((Cam_size->x)/(2));
        y -= ((Cam_size->y)/(2));
        Cam_pos->x = (float)x;
        Cam_pos->y = (float)y;
        Cam_tgt = Cam_pos;
}

void Ignition::Camera::Camera_goto(int x, int y)
{       Cam_tgt->x = (float)x;
        Cam_tgt->y = (float)y;
}

void Ignition::Camera::Camera_center_goto(int x, int y)
{       x -= ((Cam_size->x)/(2));
        y -= ((Cam_size->y)/(2));
        Cam_tgt->x = x;
        Cam_tgt->y = y;
}

void Ignition::Camera::Update_camera()
{       struct coords
        {       float l, dl;
        }x, y, d;
        x.l = (float)(Cam_tgt->x - Cam_pos->x);
        y.l = (float)(Cam_tgt->y - Cam_pos->y);
        if (d.l <= 1)
        {       Cam_pos = Cam_tgt;
        }       // The snap-to case when the locations are close enough. Not really sure if this is worth it, but maybe overshooting is a problem otherwise
        else
        {       d.l = sqrt((pow(x.l, 2))+(pow(y.l, 2)));
                d.dl = (((d.l)*(speed))/60);
                if (d.dl < 1.0f)
                {       d.dl = 1.0f;
                }
                x.dl = ((x.l)*(d.dl/d.l));              // Similar triangles method
                y.dl = ((y.l)*(d.dl/d.l));              // to get v components
                Cam_pos->x += x.dl;
                Cam_pos->y += y.dl;
        }
}

void Ignition::Camera::Set_cam_tgt(sf::Vector2i iPos)
{       Cam_tgt->x = iPos.x;
        Cam_tgt->y = iPos.y;
}

sf::Vector2i* Ignition::Camera::Get_cam_pos()
{       sf::Vector2i * output = new sf::Vector2i((int)((Cam_pos)->x),(int)((Cam_pos)->y));
        return output;
}

sf::Vector2i* Ignition::Camera::Get_cam_size()
{       return Cam_size;
}

sf::Vector2i* Ignition::Camera::Get_Cam_port_ofs()
{       return Cam_port_ofs;
}

sf::IntRect Ignition::Camera::Get_cam_window()
{       sf::IntRect cWindow((Cam_pos->x),(Cam_pos->y),(Cam_size->x),(Cam_size->y));
        return cWindow;
}

Ignition::Camera::~Camera()
{       delete Cam_tgt;
        delete Cam_size;
        delete Cam_pos;
        delete Cam_port_ofs;
}




// Ignition Engine - Functions() /////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

void Ignition::Construct_portal(unsigned int h, unsigned int w, int bpp, std::string wTitle, Ignition_Engine * this_engine)
{       Portal * iPort = new Portal(h, w, bpp, wTitle);
        this_engine->Sub_portals.push_back(iPort);
}

Any thoughts on the progress so far are welcome :)

Pages: [1]
anything