mirror of
https://github.com/ApfelTeeSaft/vb01.git
synced 2026-08-26 19:33:45 +00:00
shadow sample improvement
This commit is contained in:
+28
-6
@@ -7,15 +7,16 @@
|
|||||||
#include "animation.h"
|
#include "animation.h"
|
||||||
#include "animationController.h"
|
#include "animationController.h"
|
||||||
#include "animationChannel.h"
|
#include "animationChannel.h"
|
||||||
#include <ft2build.h>
|
#include "assetManager.h"
|
||||||
#include FT_FREETYPE_H
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace vb01;
|
using namespace vb01;
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
const string PATH = "../", TEX_PATH = PATH + "samples/textures/", MODEL_PATH = PATH + "samples/models/";
|
const string PATH = "../", TEX_PATH = PATH + "samples/textures/", MODEL_PATH = PATH + "samples/models/";
|
||||||
string skyboxTextures[] = {
|
|
||||||
|
const int numTextures = 6;
|
||||||
|
string skyboxTextures[numTextures] = {
|
||||||
TEX_PATH + "top.jpg",
|
TEX_PATH + "top.jpg",
|
||||||
TEX_PATH + "bottom.jpg",
|
TEX_PATH + "bottom.jpg",
|
||||||
TEX_PATH + "left.jpg",
|
TEX_PATH + "left.jpg",
|
||||||
@@ -24,6 +25,10 @@ int main(){
|
|||||||
TEX_PATH + "back.jpg"
|
TEX_PATH + "back.jpg"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Loads the assets to be stored and retrievable at a later time
|
||||||
|
for(int i = 0; i < numTextures; i++)
|
||||||
|
AssetManager::getSingleton()->load(skyboxTextures[i]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gets Root object to start the sample,
|
* Gets Root object to start the sample,
|
||||||
* also passes the base path for asset retrieval.
|
* also passes the base path for asset retrieval.
|
||||||
@@ -40,23 +45,33 @@ int main(){
|
|||||||
cam->setPosition(Vector3(0, 1, 1) * 20);
|
cam->setPosition(Vector3(0, 1, 1) * 20);
|
||||||
cam->lookAt(Vector3(0, -1, -1).norm(), Vector3(0, 1, -1).norm());
|
cam->lookAt(Vector3(0, -1, -1).norm(), Vector3(0, 1, -1).norm());
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Creates a plaform for the shadow to be cast upon
|
||||||
|
*/
|
||||||
Box *box = new Box(Vector3(40, .2, 40));
|
Box *box = new Box(Vector3(40, .2, 40));
|
||||||
Node *boxNode = new Node();
|
Node *boxNode = new Node();
|
||||||
Material *boxMat = new Material(PATH + "texture");
|
Material *boxMat = new Material(PATH + "texture");
|
||||||
boxMat->addBoolUniform("texturingEnabled", true);
|
boxMat->addBoolUniform("texturingEnabled", true);
|
||||||
boxMat->addBoolUniform("lightingEnabled", true);
|
boxMat->addBoolUniform("lightingEnabled", true);
|
||||||
string im0[] = {TEX_PATH + "bricks.jpg"};
|
string im0[] = {TEX_PATH + "bricks.jpg"};
|
||||||
|
AssetManager::getSingleton()->load(im0[0]);
|
||||||
Texture *boxTex = new Texture(im0, 1, false);
|
Texture *boxTex = new Texture(im0, 1, false);
|
||||||
boxMat->addTexUniform("textures[0]", boxTex, true);
|
boxMat->addTexUniform("textures[0]", boxTex, true);
|
||||||
box->setMaterial(boxMat);
|
box->setMaterial(boxMat);
|
||||||
boxNode->attachMesh(box);
|
boxNode->attachMesh(box);
|
||||||
rootNode->attachChild(boxNode);
|
rootNode->attachChild(boxNode);
|
||||||
|
|
||||||
Model *jet = new Model(MODEL_PATH + "jet00.obj");
|
/*
|
||||||
|
* Creates a model that casts a shadow
|
||||||
|
*/
|
||||||
|
string modelPath = MODEL_PATH + "jet00.xml";
|
||||||
|
AssetManager::getSingleton()->load(modelPath);
|
||||||
|
Model *jet = new Model(modelPath);
|
||||||
Material *jetMat = new Material(PATH + "texture");
|
Material *jetMat = new Material(PATH + "texture");
|
||||||
jetMat->addBoolUniform("texturingEnabled", true);
|
jetMat->addBoolUniform("texturingEnabled", true);
|
||||||
jetMat->addBoolUniform("lightingEnabled", true);
|
jetMat->addBoolUniform("lightingEnabled", true);
|
||||||
string im1[] = {TEX_PATH + "defaultTexture.jpg"};
|
string im1[] = {TEX_PATH + "defaultTexture.jpg"};
|
||||||
|
AssetManager::getSingleton()->load(im1[0]);
|
||||||
Texture *jetTex = new Texture(im1, 1, false);
|
Texture *jetTex = new Texture(im1, 1, false);
|
||||||
jetMat->addTexUniform("textures[0]", jetTex, true);
|
jetMat->addTexUniform("textures[0]", jetTex, true);
|
||||||
jet->setMaterial(jetMat);
|
jet->setMaterial(jetMat);
|
||||||
@@ -64,20 +79,27 @@ int main(){
|
|||||||
jet->setCastShadow(true);
|
jet->setCastShadow(true);
|
||||||
jet->setPosition(Vector3(0, 2, 0));
|
jet->setPosition(Vector3(0, 2, 0));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Creates a light according to which the shadow will be cast
|
||||||
|
* Lights are transformed by their node:
|
||||||
|
* light position = node position, light orientation = node orientation
|
||||||
|
*/
|
||||||
Light *light = new Light(Light::POINT);
|
Light *light = new Light(Light::POINT);
|
||||||
light->setColor(Vector3(1, 1, 1));
|
light->setColor(Vector3(1, 1, 1));
|
||||||
light->setAttenuationValues(.001, .001, 1);
|
light->setAttenuationValues(.001, .001, 1);
|
||||||
|
|
||||||
Node *lightNode = new Node();
|
Node *lightNode = new Node();
|
||||||
lightNode->addLight(light);
|
lightNode->addLight(light);
|
||||||
rootNode->attachChild(lightNode);
|
rootNode->attachChild(lightNode);
|
||||||
lightNode->setPosition(Vector3(0, 5, 0));
|
lightNode->setPosition(Vector3(0, 5, 0));
|
||||||
|
|
||||||
float angle = 0;
|
float angle = 0;
|
||||||
while(true){
|
|
||||||
root->update();
|
|
||||||
|
|
||||||
|
while(true){
|
||||||
jet->setOrientation(Quaternion(angle, Vector3(1, 1, 1).norm()));
|
jet->setOrientation(Quaternion(angle, Vector3(1, 1, 1).norm()));
|
||||||
angle += .1;
|
angle += .1;
|
||||||
|
|
||||||
|
root->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user