Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <iostream>
00012
00013 #include "common/wave_ex.h"
00014 #include "bvh/bvh.h"
00015 #include "perf/perf.h"
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 static void
00026 dumpPositions
00027 (
00028 IN bvh::Skeleton * skeleton,
00029 IN float time
00030 )
00031 {
00032 ASSERT(skeleton, "null");
00033
00034 int nObjects = skeleton->getObjectCount();
00035 ASSERT_THROW(nObjects > 0, "no objects? count=" << nObjects);
00036
00037 int nNodes = skeleton->getNodeCount(0);
00038 ASSERT_THROW(nNodes > 0, "no nodes? count=" << nNodes);
00039
00040 static const int maxNodes = 256;
00041 bvh::node_position_t nodes[maxNodes];
00042 ASSERT_THROW(nNodes <= maxNodes,
00043 "skeleton has too many nodes: " << nNodes);
00044
00045 skeleton->getNodePositions(0, time, nodes);
00046 DPRINTF("At time t=%f", time);
00047 for (int i = 0; i < nNodes; ++i) {
00048 const bvh::node_position_t& n = nodes[i];
00049 n.pos.dump(n.name);
00050 }
00051 }
00052
00053
00054
00055 static void
00056 doTest
00057 (
00058 IN const char * bvhFile
00059 )
00060 {
00061 ASSERT(bvhFile, "null");
00062
00063 smart_ptr<bvh::Skeleton> skeleton = bvh::Skeleton::load(bvhFile);
00064 ASSERT(skeleton, "null");
00065
00066 skeleton->dump("Just loaded");
00067
00068 dumpPositions(skeleton, 0.0);
00069 dumpPositions(skeleton, 2.0);
00070 dumpPositions(skeleton, -0.4);
00071
00072
00073 int nNodes = skeleton->getNodeCount(0);
00074 ASSERT_THROW(nNodes > 0, "no nodes? count=" << nNodes);
00075
00076 static const int maxNodes = 256;
00077 bvh::node_position_t nodes[maxNodes];
00078 ASSERT_THROW(nNodes <= maxNodes,
00079 "skeleton has too many nodes: " << nNodes);
00080
00081 int idx = nNodes / 3;
00082 const float dt = 0.05;
00083 for (int i = 0; i < 300; ++i) {
00084 float t = i * dt;
00085 skeleton->getNodePositions(0, t, nodes);
00086 const bvh::node_position_t& n = nodes[idx];
00087 DPRINTF("t=%fs '%s' (child of '%s') at (%f, %f, %f)",
00088 t, n.name, (n.parent ? n.parent->name : "none"),
00089 n.pos.x, n.pos.y, n.pos.z);
00090 }
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 int
00102 main
00103 (
00104 IN int argc,
00105 IN const char * argv[]
00106 )
00107 {
00108 ASSERT(2 == argc, "Usage: bvh-test <bvh-filename>");
00109 const char * bvhFile = argv[1];
00110
00111 try {
00112 perf::Timer timer("overall timer");
00113 doTest(bvhFile);
00114 } catch (std::exception& e) {
00115 DPRINTF("Exception: %s", e.what());
00116 }
00117
00118 perf::dumpTimingSummary(std::cerr);
00119
00120
00121 return 1;
00122 }
00123