Hi, I'm interesting by this project, then, I'm developping something similar for 2D and 3D games.
Here is an exemple of code witch display a cube in a view.
#include "myRenderWindow.h"
#include <SFML/Window/Event.hpp>
using namespace sf3;
MyRenderWindow::MyRenderWindow (Vec2f size, std::string title) :
RenderWindow(sf::VideoMode(size.x, size.y), title, Style::Default, ContextSettings(32)),
//In perspective projection the x and y coordinates of the view are always between -1 and 1 with opengl.
cube(Vec3f(-1, 1, 1), 2, 2, 2, Color(255, 0, 0)) {
//Rotate the cube around a vector.
cube.rotate(45,Vec3f(0, 1, 0));
view = getDefaultView();
//The default view have a perspective projection, but you can set another view with the setView function.
view->move(0, 0, 10);
speed = 10.f;
sensivity = 0.2f;
oldX = Mouse::getPosition(*this).x;
oldY = Mouse::getPosition(*this).y;
verticalMotionActive = false;
verticalMotionDirection = 0;
}
void MyRenderWindow::show () {
while(isOpen()) {
sf::Event event;
while (pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
close();
}
else if (event.type == sf::Event::Resized)
{
// Ajust the viewport size when the window is resized.
view->reset(FloatRect(0, 0, event.size.width, event.size.height));
} else if (event.type == sf::Event::MouseMoved && sf::Mouse::isButtonPressed(Mouse::Right)) {
int relX = event.mouseMove.x - oldX;
int relY = event.mouseMove.y - oldY;
int teta = view->getTeta() - relX;
int phi = view->getPhi() - relY;
//Rotate the view, (Polar coordinates) but you can also use the lookAt function to look at a point.
view->rotate(teta, phi);
oldX = event.mouseMove.x;
oldY = event.mouseMove.y;
} else if (event.type == sf::Event::MouseWheelMoved) {
if (event.mouseWheel.delta > 0) {
verticalMotionActive = true;
verticalMotionDirection = 1;
timeBeforeStoppingVerticalMotion = milliseconds(250);
clock2.restart();
} else if (event.mouseWheel.delta < 0) {
verticalMotionActive = true;
verticalMotionDirection = -1;
timeBeforeStoppingVerticalMotion = milliseconds(250);
clock2.restart();
}
}
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
//Move the view along a vector, but you case also move the view at a point.
view->move(view->getForward(), speed * clock.getElapsedTime().asSeconds());
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
view->move(view->getForward(), -speed * clock.getElapsedTime().asSeconds());
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
view->move(view->getLeft(), -speed * clock.getElapsedTime().asSeconds());
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
view->move(view->getLeft(), speed * clock.getElapsedTime().asSeconds());
}
oldX = Mouse::getPosition(*this).x;
oldY = Mouse::getPosition(*this).y;
if (clock2.getElapsedTime() > timeBeforeStoppingVerticalMotion) {
verticalMotionActive = false;
verticalMotionDirection = 0;
} else {
timeBeforeStoppingVerticalMotion -= clock2.getElapsedTime();
}
view->move(0, verticalMotionDirection * speed * clock2.getElapsedTime().asSeconds(), 0);
clear(Color::Black);
draw(cube);
display();
clock.restart();
}
}
The library use 3 kinds of matrix : the projection matrix (for perspective or orthographic projection), the view matrix (for the moving of the view in the world), and the transformation matrix. (for entity's transformations)
The user can create any kind of entities has he wants, and he can also create a scene graph and combine transformations, he just have to herit from certain classes and redefines some methods.
This methods are used by the container to store entities (animations, lights, shadows, etc...) with the best performances to render only entities who are visible at the screen.
The library also contains a resource holder to store sounds, images, etc..., and maybe later a special format to load maps.
But actually I'm finishing the 2D part so..., there is not a lot of things that are implemented for 3D games, but, it's coming.
I think I'll look at the source code of this project and try to take it over.
I don't want to use other libraries excepts SFML because I want to use the newest features of the c++11 and make it the most simpliest and fastest library.