Add first person view.
This commit is contained in:
parent
2c06859473
commit
787b25239e
39
firstperson.cpp
Normal file
39
firstperson.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "firstperson.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "maths.h"
|
||||
|
||||
static sf::RenderTexture renderTexture;
|
||||
static sf::Vector2f renderTexturePosition;
|
||||
|
||||
static bool init = false;
|
||||
static unsigned int width;
|
||||
static unsigned int height;
|
||||
|
||||
int firstperson_init(unsigned int _width, unsigned int _height)
|
||||
{
|
||||
printf("firstperson_init()\n");
|
||||
if (!renderTexture.create(_width, _height)) return 0;
|
||||
width = _width;
|
||||
height = _height;
|
||||
init = true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void firstperson_update(sf::RenderTarget* renderTarget)
|
||||
{
|
||||
renderTexture.clear();
|
||||
sf::CircleShape shape(50);
|
||||
renderTexture.draw(shape);
|
||||
renderTexture.display();
|
||||
|
||||
sf::Sprite sprite(renderTexture.getTexture());
|
||||
sprite.setPosition(renderTexturePosition);
|
||||
renderTarget->draw(sprite);
|
||||
}
|
||||
|
||||
void firstperson_setTexturePosition(float x, float y)
|
||||
{
|
||||
renderTexturePosition.x = x;
|
||||
renderTexturePosition.y = y;
|
||||
}
|
10
firstperson.h
Normal file
10
firstperson.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef FIRSTPERSON_H
|
||||
#define FIRSTPERSON_H
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
int firstperson_init(unsigned int width, unsigned int height);
|
||||
void firstperson_update(sf::RenderTarget* renderTarget);
|
||||
void firstperson_setTexturePosition(float x, float y);
|
||||
|
||||
#endif
|
4
view.cpp
4
view.cpp
@ -5,6 +5,7 @@
|
||||
#include "maths.h"
|
||||
#include "camera.h"
|
||||
#include "minimap.h"
|
||||
#include "firstperson.h"
|
||||
|
||||
#define MINIMAP_SIZE 460
|
||||
#define VIEW_SIZE MINIMAP_SIZE*2
|
||||
@ -22,8 +23,10 @@ int view_init()
|
||||
printf("view_init()\n");
|
||||
if (!camera_init(&camera, sf::Vector2f(5.f/2.f, 5.f/2.f), 0.f, 100, 0.5f*PI)) return 0;
|
||||
if (!minimap_init(MINIMAP_SIZE)) return 0;
|
||||
if (!firstperson_init(VIEW_SIZE, MINIMAP_SIZE)) return 0;
|
||||
|
||||
minimap_setTexturePosition(0.f, 0.f);
|
||||
firstperson_setTexturePosition(MINIMAP_SIZE, 0.f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -50,6 +53,7 @@ int view_update()
|
||||
|
||||
window.clear();
|
||||
minimap_update(&window, &camera);
|
||||
firstperson_update(&window);
|
||||
window.display();
|
||||
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user