diff --git a/lightSample.cpp b/lightSample.cpp index dd6f7ab..cc50ac2 100644 --- a/lightSample.cpp +++ b/lightSample.cpp @@ -22,17 +22,27 @@ int main(){ TEX_PATH + "back.jpg" }; + /* + * Gets Root object to start the sample, + * also passes the base path for asset retrieval. + */ Root *root = Root::getSingleton(); root->start(800, 600, PATH, "Light sample"); root->createSkybox(skyboxTextures); Node *rootNode = root->getRootNode(); + /* + * Places the camera above the platform at an angle. + */ Camera *cam = root->getCamera(); cam->setPosition(Vector3(0, 1, 1) * 20); cam->lookAt(Vector3(0, -1, -1).norm(), Vector3(0, 1, -1).norm()); Model *box = new Model(MODEL_PATH + "platform.vb"); + /* + * Creates a material with diffuse, normal, and specular maps attached. + */ Material *mat = new Material(); mat->setTexturingEnabled(true); mat->setLightingEnabled(true); @@ -51,20 +61,31 @@ int main(){ Texture *specularTex = new Texture(im2, 1, Texture::SPECULAR); mat->addSpecularMap(specularTex); + //Setting specular parameteres mat->setSpecularStrength(1); - mat->setShinyness(2); + mat->setShinyness(32); box->setMaterial(mat); rootNode->attachChild(box); + /* + * Creates a spotlight placed at an angle agaist the platform. + */ Light *light = new Light(Light::SPOT); light->setColor(Vector3(1, 1, 1)); + Node *lightNode = new Node(Vector3::VEC_ZERO, Quaternion::QUAT_W, Vector3::VEC_IJK, "", new AnimationController()); lightNode->addLight(light); rootNode->attachChild(lightNode); lightNode->setOrientation(Quaternion(.7, Vector3(1, 0, 0))); lightNode->setPosition(Vector3(0, 5, -5)); + /* + * KeyframeChannel structs determine what object and how it will be animated. + * They also use keyframes which in turn are determined by their interpolation types, + * values that are returned for animatable parameters, e.g. x coordinate for position + * and frame number. + */ KeyframeChannel kcA; kcA.animatable = light; kcA.type = KeyframeChannel::SPOTLIGHT_OUTER_ANGLE; @@ -86,6 +107,10 @@ int main(){ animation->addKeyframeChannel(kcA); animation->addKeyframeChannel(kcB); + /* + * The AnimationController plays the animations set in the AnimationChannel objects. + * AnimationChannel objects require an animation and animatable objects, e.g. textures to work. + */ AnimationController *controller = lightNode->getAnimationController(); controller->addAnimation(animation); AnimationChannel *channel = new AnimationChannel(); diff --git a/morphAnimationSample.cpp b/morphAnimationSample.cpp index 0180b00..dc2cc69 100644 --- a/morphAnimationSample.cpp +++ b/morphAnimationSample.cpp @@ -21,11 +21,18 @@ int main(){ TEX_PATH + "back.jpg" }; + /* + * Gets Root object to start the sample, + * also passes the base path for asset retrieval. + */ Root *root = Root::getSingleton(); root->start(800, 600, PATH, "Morph animation sample"); root->createSkybox(skyboxTextures); Node *rootNode = root->getRootNode(); + /* + * Places the camera to the side of the model. + */ Camera *cam = root->getCamera(); cam->setPosition(Vector3(-1, 0.25, .2) * 20); cam->lookAt(Vector3(1, 0, 0).norm(), Vector3(0, 1, 0).norm()); @@ -45,6 +52,10 @@ int main(){ Mesh *mesh = node->getMesh(0); Skeleton *skeleton = mesh->getSkeleton(); + /* + * The AnimationController plays the animations set in the AnimationChannel objects. + * AnimationChannel objects require an animation and animatable objects, e.g. textures to work. + */ AnimationController *controller = skeleton->getAnimationController(); AnimationChannel *channel = new AnimationChannel(); controller->addAnimationChannel(channel); @@ -52,6 +63,9 @@ int main(){ channel->setAnimationName("morph"); channel->setLoop(true); + /* + * Creates a box attached to the bone controlling the shape keys. + */ Box *box = new Box(Vector3(1, 1, 1) * .25); Material *boxMat = new Material(); boxMat->setTexturingEnabled(false); diff --git a/shadowSample.cpp b/shadowSample.cpp index 0a29d46..e72d8d0 100644 --- a/shadowSample.cpp +++ b/shadowSample.cpp @@ -22,70 +22,61 @@ int main(){ TEX_PATH + "back.jpg" }; + /* + * Gets Root object to start the sample, + * also passes the base path for asset retrieval. + */ Root *root = Root::getSingleton(); root->start(800, 600, PATH, "Shadow sample"); root->createSkybox(skyboxTextures); Node *rootNode = root->getRootNode(); + /* + * Places the camera above the platform at an angle. + */ Camera *cam = root->getCamera(); cam->setPosition(Vector3(0, 1, 1) * 20); cam->lookAt(Vector3(0, -1, -1).norm(), Vector3(0, 1, -1).norm()); Box *box = new Box(Vector3(40, .2, 40)); Node *boxNode = new Node(); - Material *mat = new Material(); - mat->setTexturingEnabled(true); - mat->setLightingEnabled(true); + Material *boxMat = new Material(); + boxMat->setTexturingEnabled(true); + boxMat->setLightingEnabled(true); string im0[] = {TEX_PATH + "bricks.jpg"}; - Texture *diffuseTex = new Texture(im0, 1); - mat->addDiffuseMap(diffuseTex); - box->setMaterial(mat); + Texture *boxTex = new Texture(im0, 1); + boxMat->addDiffuseMap(boxTex); + box->setMaterial(boxMat); boxNode->attachMesh(box); rootNode->attachChild(boxNode); - { - Box *box = new Box(Vector3(4, .2, 4)); - Node *boxNode = new Node(); - Material *mat = new Material(); - mat->setTexturingEnabled(true); - mat->setLightingEnabled(true); - string im0[] = {TEX_PATH + "defaultTexture.jpg"}; - Texture *diffuseTex = new Texture(im0, 1); - mat->addDiffuseMap(diffuseTex); - box->setMaterial(mat); - boxNode->attachMesh(box); - rootNode->attachChild(boxNode); - box->setCastShadow(true); - boxNode->setPosition(Vector3(0, 2, 0)); - } - /* - { - Model *box = new Model(MODEL_PATH + "jet00.obj"); - Material *mat = new Material(); - mat->setTexturingEnabled(true); - mat->setLightingEnabled(true); - mat->setNormalMapEnabled(false); - mat->setSpecularMapEnabled(false); - string im0[] = {TEX_PATH + "defaultTexture.jpg"}; - Texture *diffuseTex = new Texture(im0, 1); - mat->addDiffuseMap(diffuseTex); - box->setMaterial(mat); - rootNode->attachChild(box); - box->setCastShadow(true); - box->setPosition(Vector3(0, 3, 0)); - } - */ + Model *jet = new Model(MODEL_PATH + "jet00.obj"); + Material *jetMat = new Material(); + jetMat->setTexturingEnabled(true); + jetMat->setLightingEnabled(true); + string im1[] = {TEX_PATH + "defaultTexture.jpg"}; + Texture *jetTex = new Texture(im1, 1); + jetMat->addDiffuseMap(jetTex); + jet->setMaterial(jetMat); + rootNode->attachChild(jet); + jet->setCastShadow(true); + jet->setPosition(Vector3(0, 2, 0)); - Light *light = new Light(Light::DIRECTIONAL); + Light *light = new Light(Light::POINT); light->setColor(Vector3(1, 1, 1)); - Node *lightNode = new Node(Vector3::VEC_ZERO, Quaternion::QUAT_W, Vector3::VEC_IJK, "", new AnimationController()); + light->setAttenuationValues(.001, .001, 1); + Node *lightNode = new Node(); lightNode->addLight(light); rootNode->attachChild(lightNode); - lightNode->setOrientation(Quaternion(1.57, Vector3(1, 0, 0))); lightNode->setPosition(Vector3(0, 5, 0)); - while(true) + float angle = 0; + while(true){ root->update(); + jet->setOrientation(Quaternion(angle, Vector3(1, 1, 1).norm())); + angle += .1; + } + return 0; } diff --git a/skeletalAnimationSample.cpp b/skeletalAnimationSample.cpp index 7213e4c..a6522da 100644 --- a/skeletalAnimationSample.cpp +++ b/skeletalAnimationSample.cpp @@ -11,6 +11,7 @@ using namespace vb01; int main(){ const string PATH = "../", TEX_PATH = PATH + "samples/textures/", MODEL_PATH = PATH + "samples/models/"; + string skyboxTextures[] = { TEX_PATH + "top.jpg", TEX_PATH + "bottom.jpg", @@ -20,11 +21,18 @@ int main(){ TEX_PATH + "back.jpg" }; + /* + * Gets Root object to start the sample, + * also passes the base path for asset retrieval. + */ Root *root = Root::getSingleton(); root->start(800, 600, PATH, "Skeletal animation sample"); root->createSkybox(skyboxTextures); Node *rootNode = root->getRootNode(); + /* + * Places the camera in front of the model. + */ Camera *cam = root->getCamera(); cam->setPosition(Vector3(0, 0, 1) * 20); cam->lookAt(Vector3(0, 0, -1).norm(), Vector3(0, 1, 0).norm()); @@ -44,6 +52,10 @@ int main(){ Mesh *mesh = node->getMesh(0); Skeleton *skeleton = mesh->getSkeleton(); + /* + * The AnimationController plays the animations set in the AnimationChannel objects. + * AnimationChannel objects require an animation and animatable objects, e.g. textures to work. + */ AnimationController *controller = skeleton->getAnimationController(); AnimationChannel *channel = new AnimationChannel(); controller->addAnimationChannel(channel); diff --git a/textSample.cpp b/textSample.cpp index aad5041..e218b35 100644 --- a/textSample.cpp +++ b/textSample.cpp @@ -11,10 +11,15 @@ using namespace std; using namespace vb01; int main(){ - Root *root = Root::getSingleton(); - Node *guiNode = root->getGuiNode(); const string PATH = "../", FONT_PATH = PATH + "samples/textSample/fonts/", TEX_PATH = PATH + "samples/textures/"; + + /* + * Gets Root object to start the sample, + * also passes the base path for asset retrieval. + */ + Root *root = Root::getSingleton(); root->start(800, 600, PATH, "Text sample"); + Node *guiNode = root->getGuiNode(); int numTexts = 4; wstring texts[] = { @@ -42,8 +47,13 @@ int main(){ false }; + /* + * Creates a material for text objects and + * attaches a diffuse texture with 2 images + */ Material *textMat = new Material(Material::MATERIAL_TEXT); textMat->setTexturingEnabled(true); + string frames[]{TEX_PATH + "bricks.jpg", TEX_PATH + "defaultTexture.jpg"}; Texture *texture = new Texture(frames, 2); textMat->addDiffuseMap(texture); @@ -54,10 +64,17 @@ int main(){ text->setScale(.5); text->setHorizontal(horizontal[i]); text->setMaterial(textMat); + Node *textNode = new Node(Vector3(0, 50 * (i + 1), 0), Quaternion::QUAT_W, Vector3::VEC_IJK, "", new AnimationController()); textNode->addText(text); guiNode->attachChild(textNode); + /* + * KeyframeChannel structs determine what object and how it will be animated. + * They also use keyframes which in turn are determined by their interpolation types, + * values that are returned for animatable parameters, e.g. x coordinate for position + * and frame number. + */ KeyframeChannel kcA; kcA.animatable = texture; kcA.type = KeyframeChannel::TEXTURE_FRAME_A; @@ -66,33 +83,26 @@ int main(){ KeyframeChannel kcB; kcB.animatable = texture; kcB.type = KeyframeChannel::TEXTURE_FRAME_B; - Keyframe k1; - k1.interpolation = Keyframe::CONSTANT; - k1.value = 1; - k1.frame = 1; - kcB.keyframes = vector({k1}); + kcB.keyframes = vector({KeyframeChannel::createKeyframe(Keyframe::CONSTANT, 1, 1)}); KeyframeChannel kcC; kcC.animatable = texture; kcC.type = KeyframeChannel::TEXTURE_MIX_RATIO; - Keyframe k; - k.interpolation = Keyframe::LINEAR; - k.value = 0; - k.frame = 1; - Keyframe kk; - kk.interpolation = Keyframe::LINEAR; - kk.value = 1; - kk.frame = 15; - Keyframe kkk; - kkk.interpolation = Keyframe::LINEAR; - kkk.value = 0; - kkk.frame = 29; - kcC.keyframes = vector({k, kk, kkk}); + kcC.keyframes = vector({ + KeyframeChannel::createKeyframe(Keyframe::LINEAR, 0, 1), + KeyframeChannel::createKeyframe(Keyframe::LINEAR, 1, 15), + KeyframeChannel::createKeyframe(Keyframe::LINEAR, 0, 29) + }); + Animation *anim = new Animation("tex"); anim->addKeyframeChannel(kcA); anim->addKeyframeChannel(kcB); anim->addKeyframeChannel(kcC); + /* + * The AnimationController plays the animations set in the AnimationChannel objects. + * AnimationChannel objects require an animation and animatable objects, e.g. textures to work. + */ AnimationController *controller = textNode->getAnimationController(); controller->addAnimation(anim); AnimationChannel *channel = new AnimationChannel();