Skip to content
Permalink
Browse files

Added SkyBox - i've made test for it and added to multicraft.

  • Loading branch information...
DrakonPL committed Feb 10, 2013
1 parent cb55d88 commit 18ce0fba40deecae3466e029c052131581a98adc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -4,11 +4,7 @@
#include <Aurora/Graphics/Camera.h>
#include <Aurora/Graphics/Image.h>
#include <Aurora/Graphics/Sprite.h>
#include <Aurora/Graphics/SpriteAnimation.h>
#include <Aurora/Graphics/Sprite3D.h>
#include <Aurora/Graphics/RenderTexture.h>
#include <Aurora/Graphics/TrueTypeFont.h>
//#include <Aurora/Graphics/ModelObj.h>

#include <Aurora/Math/Vector3.h>
#include <Aurora/Math/Vector2.h>
@@ -152,9 +148,12 @@ namespace Aurora
virtual void RotateMatrix(Vector3 rotation) = 0;
virtual void ScaleMatrix(Vector3 scale) = 0;

//mist stuff
virtual void SetColor(unsigned int col) = 0;
virtual void SetBlending(bool state) = 0;
virtual void SetFrontFace(FrontFace face) = 0;
virtual void SetDepthTest(bool state) = 0;
virtual void SetDepthMask(bool state) = 0;

virtual void* CreateVertexObject(VertexType vertexType,int size) = 0;
virtual void DrawVertexObject(void* vertexObject,int vertexCound,bool textured,VertexType vertexType,VertexPrimitive vertecPrimitive) = 0;
@@ -0,0 +1,199 @@
#include <Aurora/Graphics/SkyBox.h>
#include <Aurora/Graphics/RenderManager.h>
#include <Aurora/Graphics/TextureManager.h>

namespace Aurora
{
namespace Graphics
{
SkyBox::SkyBox()
{
_position.set(0.0f,0.0f,0.0f);
_size.set(1.0f,1.0f,1.0f);

_position = _position - _size / 2;

_front = 0;
_back = 0;
_left = 0;
_right = 0;
_up = 0;
_down = 0;
}

SkyBox::~SkyBox()
{
if (_front != 0)
{
delete _front;
}

if (_back != 0)
{
delete _back;
}

if (_left != 0)
{
delete _left;
}

if (_right != 0)
{
delete _right;
}

if (_up != 0)
{
delete _up;
}

if (_down != 0)
{
delete _down;
}
}

void SkyBox::LoadImage(const char* fileName,SkyFace skyFace)
{
switch (skyFace)
{
case Aurora::Graphics::Front:
{
_front = new Image();
_front = TextureManager::Instance()->loadImageFromFile(fileName);
}
break;
case Aurora::Graphics::Back:
{
_back = new Image();
_back = TextureManager::Instance()->loadImageFromFile(fileName);
}
break;
case Aurora::Graphics::Left:
{
_left = new Image();
_left = TextureManager::Instance()->loadImageFromFile(fileName);
}
break;
case Aurora::Graphics::Right:
{
_right = new Image();
_right = TextureManager::Instance()->loadImageFromFile(fileName);
}
break;
case Aurora::Graphics::Up:
{
_up = new Image();
_up = TextureManager::Instance()->loadImageFromFile(fileName);
}
break;
case Aurora::Graphics::Down:
{
_down = new Image();
_down = TextureManager::Instance()->loadImageFromFile(fileName);
}
break;
default:
break;
}
}

void SkyBox::SetPositionSize(Vector3 position,Vector3 size)
{
_position = position;
_size = size;

_position = _position - _size / 2;
}

void SkyBox::Draw()
{
RenderManager::Instance()->SetColor(0xffffffff);

RenderManager::Instance()->SetDepthTest(false);
RenderManager::Instance()->SetDepthMask(false);

//back
{
TexturedVertex* vertices = (TexturedVertex*)RenderManager::Instance()->CreateVertexObject(Textured,4);

vertices[0].u = 0.0f; vertices[0].v = 1.0f;vertices[0].x =_position.x ;vertices[0].y =_position.y ;vertices[0].z =_position.z;
vertices[1].u = 1.0f; vertices[1].v = 1.0f;vertices[1].x =_position.x + _size.x ;vertices[1].y =_position.y ;vertices[1].z =_position.z;
vertices[2].u = 0.0f; vertices[2].v = 0.0f;vertices[2].x =_position.x ;vertices[2].y =_position.y + _size.y ;vertices[2].z =_position.z;
vertices[3].u = 1.0f; vertices[3].v = 0.0f;vertices[3].x =_position.x + _size.x ;vertices[3].y =_position.y + _size.y ;vertices[3].z =_position.z;

RenderManager::Instance()->bindTexture(_back);
RenderManager::Instance()->DrawVertexObject(vertices,4,true,Textured,TriangleStrip);
}

//front
{
TexturedVertex* vertices = (TexturedVertex*)RenderManager::Instance()->CreateVertexObject(Textured,4);

vertices[0].u = 1.0f; vertices[0].v = 1.0f;vertices[0].x =_position.x ;vertices[0].y =_position.y ;vertices[0].z =_position.z + _size.z;
vertices[1].u = 1.0f; vertices[1].v = 0.0f;vertices[1].x =_position.x ;vertices[1].y =_position.y + _size.y ;vertices[1].z =_position.z + _size.z;
vertices[2].u = 0.0f; vertices[2].v = 1.0f;vertices[2].x =_position.x + _size.x ;vertices[2].y =_position.y ;vertices[2].z =_position.z + _size.z;
vertices[3].u = 0.0f; vertices[3].v = 0.0f;vertices[3].x =_position.x + _size.x ;vertices[3].y =_position.y + _size.y ;vertices[3].z =_position.z + _size.z;

RenderManager::Instance()->bindTexture(_front);
RenderManager::Instance()->DrawVertexObject(vertices,4,true,Textured,TriangleStrip);
}

//down
{
TexturedVertex* vertices = (TexturedVertex*)RenderManager::Instance()->CreateVertexObject(Textured,4);

vertices[0].u = 1.0f; vertices[0].v = 1.0f;vertices[0].x =_position.x ;vertices[0].y =_position.y ;vertices[0].z =_position.z;
vertices[1].u = 1.0f; vertices[1].v = 0.0f;vertices[1].x =_position.x ;vertices[1].y =_position.y ;vertices[1].z =_position.z + _size.z;
vertices[2].u = 0.0f; vertices[2].v = 1.0f;vertices[2].x =_position.x + _size.x ;vertices[2].y =_position.y ;vertices[2].z =_position.z;
vertices[3].u = 0.0f; vertices[3].v = 0.0f;vertices[3].x =_position.x + _size.x ;vertices[3].y =_position.y ;vertices[3].z =_position.z + _size.z;

RenderManager::Instance()->bindTexture(_down);
RenderManager::Instance()->DrawVertexObject(vertices,4,true,Textured,TriangleStrip);
}

//up
{
TexturedVertex* vertices = (TexturedVertex*)RenderManager::Instance()->CreateVertexObject(Textured,4);

vertices[0].u = 1.0f; vertices[0].v = 0.0f;vertices[0].x =_position.x ;vertices[0].y =_position.y + _size.y ;vertices[0].z =_position.z;
vertices[1].u = 0.0f; vertices[1].v = 0.0f;vertices[1].x =_position.x + _size.x ;vertices[1].y =_position.y + _size.y ;vertices[1].z =_position.z;
vertices[2].u = 1.0f; vertices[2].v = 1.0f;vertices[2].x =_position.x ;vertices[2].y =_position.y + _size.y ;vertices[2].z =_position.z + _size.z;
vertices[3].u = 0.0f; vertices[3].v = 1.0f;vertices[3].x =_position.x + _size.x ;vertices[3].y =_position.y + _size.y ;vertices[3].z =_position.z + _size.z;

RenderManager::Instance()->bindTexture(_up);
RenderManager::Instance()->DrawVertexObject(vertices,4,true,Textured,TriangleStrip);
}

//right
{
TexturedVertex* vertices = (TexturedVertex*)RenderManager::Instance()->CreateVertexObject(Textured,4);

vertices[0].u = 1.0f; vertices[0].v = 1.0f;vertices[0].x =_position.x ;vertices[0].y =_position.y ;vertices[0].z =_position.z;
vertices[1].u = 1.0f; vertices[1].v = 0.0f;vertices[1].x =_position.x ;vertices[1].y =_position.y + _size.y ;vertices[1].z =_position.z;
vertices[2].u = 0.0f; vertices[2].v = 1.0f;vertices[2].x =_position.x ;vertices[2].y =_position.y ;vertices[2].z =_position.z + _size.z;
vertices[3].u = 0.0f; vertices[3].v = 0.0f;vertices[3].x =_position.x ;vertices[3].y =_position.y + _size.y ;vertices[3].z =_position.z + _size.z;

RenderManager::Instance()->bindTexture(_right);
RenderManager::Instance()->DrawVertexObject(vertices,4,true,Textured,TriangleStrip);
}

//left
{
TexturedVertex* vertices = (TexturedVertex*)RenderManager::Instance()->CreateVertexObject(Textured,4);

vertices[0].u = 0.0f; vertices[0].v = 1.0f;vertices[0].x =_position.x + _size.x ;vertices[0].y =_position.y ;vertices[0].z =_position.z;
vertices[1].u = 1.0f; vertices[1].v = 1.0f;vertices[1].x =_position.x + _size.x ;vertices[1].y =_position.y ;vertices[1].z =_position.z + _size.z;
vertices[2].u = 0.0f; vertices[2].v = 0.0f;vertices[2].x =_position.x + _size.x ;vertices[2].y =_position.y + _size.y ;vertices[2].z =_position.z;
vertices[3].u = 1.0f; vertices[3].v = 0.0f;vertices[3].x =_position.x + _size.x ;vertices[3].y =_position.y + _size.y ;vertices[3].z =_position.z + _size.z;

RenderManager::Instance()->bindTexture(_left);
RenderManager::Instance()->DrawVertexObject(vertices,4,true,Textured,TriangleStrip);
}

RenderManager::Instance()->SetDepthTest(true);
RenderManager::Instance()->SetDepthMask(true);
}
}
}
@@ -0,0 +1,50 @@
#ifndef SKYBOX_H
#define SKYBOX_H

#include <Aurora/Graphics/Image.h>
#include <Aurora/Math/Vector3.h>

using namespace Aurora::Math;

namespace Aurora
{
namespace Graphics
{
enum SkyFace
{
Front,
Back,
Left,
Right,
Up,
Down
};

class SkyBox
{
private:

Image* _front;
Image* _back;
Image* _left;
Image* _right;
Image* _up;
Image* _down;

Vector3 _position;
Vector3 _size;

public:

SkyBox();
~SkyBox();

void LoadImage(const char* fileName,SkyFace skyFace);
void SetPositionSize(Vector3 position,Vector3 size);

void Draw();
};
}
}

#endif
@@ -72,7 +72,7 @@ namespace Aurora
sceGuEnable(GU_DEPTH_TEST);

sceGuDisable(GU_TEXTURE_2D);
sceGuDisable(GU_CLIP_PLANES);
sceGuEnable(GU_CLIP_PLANES);

sceGuEnable(GU_CULL_FACE);
SetFrontFace(CCW);
@@ -471,6 +471,28 @@ namespace Aurora
sceGuDisable(GU_BLEND);
}
}

void GuRenderManager::SetDepthTest(bool state)
{
if(state)
{
sceGuEnable(GU_DEPTH_TEST);
}else
{
sceGuDisable(GU_DEPTH_TEST);
}
}

void GuRenderManager::SetDepthMask(bool state)
{
if(state)
{
sceGuDepthMask(GU_FALSE);
}else
{
sceGuDepthMask(GU_TRUE);
}
}

void* GuRenderManager::CreateVertexObject(VertexType vertexType,int size)
{
@@ -507,14 +529,38 @@ namespace Aurora
case Simple :
{
SimpleVertex* vertices = (SimpleVertex*)vertexObject;
sceGumDrawArray(GU_TRIANGLES, GU_VERTEX_32BITF|GU_TRANSFORM_3D, vertexCound, 0, vertices);

switch(vertecPrimitive)
{
case Triangle:
sceGumDrawArray(GU_TRIANGLES, GU_VERTEX_32BITF|GU_TRANSFORM_3D, vertexCound, 0, vertices);
break;
case TriangleFan:
sceGumDrawArray(GU_TRIANGLE_FAN, GU_VERTEX_32BITF|GU_TRANSFORM_3D, vertexCound, 0, vertices);
break;
case TriangleStrip:
sceGumDrawArray(GU_TRIANGLE_STRIP, GU_VERTEX_32BITF|GU_TRANSFORM_3D, vertexCound, 0, vertices);
break;
}
}
break;

case Textured :
{
TexturedVertex* vertices = (TexturedVertex*)vertexObject;
sceGumDrawArray(GU_TRIANGLES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D, vertexCound, 0, vertices);

switch(vertecPrimitive)
{
case Triangle:
sceGumDrawArray(GU_TRIANGLES, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D, vertexCound, 0, vertices);
break;
case TriangleFan:
sceGumDrawArray(GU_TRIANGLE_FAN, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D, vertexCound, 0, vertices);
break;
case TriangleStrip:
sceGumDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D, vertexCound, 0, vertices);
break;
}
}
break;

@@ -88,6 +88,8 @@ namespace Aurora
void SetColor(unsigned int col);
void SetBlending(bool state);
void SetFrontFace(FrontFace face);
void SetDepthTest(bool state);
void SetDepthMask(bool state);

void* CreateVertexObject(VertexType vertexType,int size);
void DrawVertexObject(void* vertexObject,int vertexCound,bool textured,VertexType vertexType,VertexPrimitive vertecPrimitive);
Oops, something went wrong.

0 comments on commit 18ce0fb

Please sign in to comment.
You can’t perform that action at this time.