void Demo::buildScene() { // scene.insertStatic(new CapsuleObject(Capsule(Vector3(-9, 1, 4), Vector3(-9, 4, 4), 1), (Color3::red() + Color3::white()) / 2)); scene.insertStatic(new BoxObject(Box(Vector3(6, 0, 0), Vector3(7, 1, 8)), (Color3::green() + Color3::white()) / 2)); scene.insertStatic(new GeneralObject(Model::getModel("cow.ifs"), CoordinateFrame(Vector3(-7,1.7f,4)), Color3::yellow())); scene.insertStatic(new GeneralObject(Model::getModel("p51-mustang.ifs"), CoordinateFrame(Vector3(10,1,2)), Color3::orange())); scene.insertStatic(new GeneralObject(Model::getModel("knot.ifs"), CoordinateFrame(Vector3(7,2.2f,-4)), (Color3::blue() + Color3::white()) / 2)); insertTray(); insertRamps(); insertSpiralSlide(); //insertRollingContactSpheres(); //insertRestingContactSpheres(); // Spheres int i; scene.insertDynamic(new SimSphere(Sphere(Vector3(0, 7, 0), .5f), Vector3::random() * 10, Color3::wheelRandom())); for (i = 0; i < 5; ++i) { scene.insertDynamic(new SimSphere(Sphere(Vector3(0, 7, 0), .25f), Vector3::random() * 10, Color3::wheelRandom())); } /* { CoordinateFrame c; c.lookAt(Vector3(0,-1,0), Vector3::UNIT_X); c.translation = Vector3(5.25,4,0); scene.insertStatic(new GeneralObject(Model::getModel("triangle.ifs"), c, (Color3::blue() + Color3::white()) / 2)); }*/ }
CoordinateFrame CoordinateFrame::fromXYZYPRRadians(float x, float y, float z, float yaw, float pitch, float roll) { const Matrix3& rotation = Matrix3::fromEulerAnglesYXZ(yaw, pitch, roll); const Vector3 translation(x, y, z); return CoordinateFrame(rotation, translation); }
void Demo::onGraphics(RenderDevice* rd) { LightingParameters lighting(G3D::toSeconds(11, 00, 00, AM)); rd->setProjectionAndCameraMatrix(app->debugCamera); // Cyan background rd->setColorClearValue(Color3(0.1f, 0.5f, 1.0f)); rd->clear(app->sky.isNull(), true, true); if (app->sky.notNull()) { app->sky->render(rd, lighting); } // Setup lighting rd->enableLighting(); rd->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); rd->setAmbientLightColor(lighting.ambient); Draw::axes(CoordinateFrame(Vector3(0, 4, 0)), rd); rd->disableLighting(); if (app->sky.notNull()) { app->sky->renderLensFlare(rd, lighting); } }
PhysicsFrame::PhysicsFrame(const Any& a) { const std::string& n = toLower(a.name()); *this = PhysicsFrame(); if (beginsWith(n, "vector3")) { *this = PhysicsFrame(Vector3(a)); } else if (beginsWith(n, "matrix3")) { *this = PhysicsFrame(Matrix3(a)); } else if (beginsWith(n, "cframe") || beginsWith(n, "coordinateframe")) { *this = PhysicsFrame(CoordinateFrame(a)); } else if (beginsWith(n, "pframe") || beginsWith(n, "physicsframe")) { if (a.type() == Any::ARRAY) { a.verifySize(2); rotation = a[0]; translation = a[1]; } else { for (Any::AnyTable::Iterator it = a.table().begin(); it.hasMore(); ++it) { const std::string& n = toLower(it->key); if (n == "translation") { translation = it->value; } else if (n == "rotation") { rotation = it->value; } else { a.verify(false, "Illegal table key: " + it->key); } } } } }
void BoxObject::render() const { // TODO: switch to using VAR to radically improve performance. // Draw the six faces Vector3 v0, v1, v2, v3; glDiffuse(); app->renderDevice->setColor(color); app->renderDevice->setObjectToWorldMatrix(CoordinateFrame()); app->renderDevice->beginPrimitive(RenderDevice::QUADS); for (int f = 0; f < 6; ++f) { box.getFaceCorners(f, v0, v1, v2, v3); app->renderDevice->setNormal((v1 - v0).cross(v3 - v0).direction()); app->renderDevice->sendVertex(v0); app->renderDevice->sendVertex(v1); app->renderDevice->sendVertex(v2); app->renderDevice->sendVertex(v3); } app->renderDevice->endPrimitive(); /* Messes up the shadow map for some reason. app->renderDevice->pushState(); Draw::box(box, app->renderDevice, color, Color4::clear()); app->renderDevice->popState(); */ }
void Viewer::onInit() { app->debugCamera.setPosition(Vector3(0, 0, 4)); app->debugCamera.lookAt(Vector3(0, 0, 0)); entityArray.append(Entity::create(Mesh::quad(), CoordinateFrame())); bumpScale = 0.04f; app->debugLog->println("Done Viewer::init"); }
void ToneMap::applyPS20(RenderDevice* rd) { // TODO: obey viewport resizeImages(rd); TextureRef bloomMap = getBloomMap(rd); rd->push2D(); rd->setAlphaTest(RenderDevice::ALPHA_ALWAYS_PASS, 0); rd->setColor(Color3::white()); // Undo renderdevice's 0.35 translation rd->setCameraToWorldMatrix(CoordinateFrame()); rd->setObjectToWorldMatrix(CoordinateFrame()); // Grab the image of the screen that was just rendered Rect2D rect = Rect2D::xywh(0, 0, rd->width(), rd->height()); screenImage->copyFromScreen(rect); // Threshold, gaussian blur horizontally, and subsample so that we have an image 1/4 as wide. bloomShader[0]->args.set("screenImage", screenImage); rd->setShader(bloomShader[0]); Draw::fastRect2D(bloomMapIntermediate->rect2DBounds(), rd); bloomMapIntermediate->copyFromScreen(bloomMapIntermediate->rect2DBounds()); // Gaussian filter vertically and subsample so that we have an image 1/4 as high and // blend this result in with the previous frame's bloom map to produce motion blur in // bright areas. bloomShader[1]->args.set("bloomImage", bloomMapIntermediate); bloomShader[1]->args.set("oldBloom", bloomMap); rd->setShader(bloomShader[1]); Draw::fastRect2D(bloomMap->rect2DBounds(), rd); bloomMap->copyFromScreen(bloomMap->rect2DBounds()); bool showBloomMap = false; // Set to true for debugging if (! showBloomMap) { // Now combine bloomShader[2]->args.set("screenImage", screenImage); bloomShader[2]->args.set("bloomImage", bloomMap); bloomShader[2]->args.set("gamma", RG); rd->setShader(bloomShader[2]); Draw::fastRect2D(rect, rd); } rd->pop2D(); }
CoordinateFrame CoordinateFrame::fromXYZYPRRadians(float x, float y, float z, float yaw, float pitch, float roll) { Matrix3 rotation = Matrix3::fromAxisAngle(Vector3::unitY(), yaw); rotation = Matrix3::fromAxisAngle(rotation.column(0), pitch) * rotation; rotation = Matrix3::fromAxisAngle(rotation.column(2), roll) * rotation; const Vector3 translation(x, y, z); return CoordinateFrame(rotation, translation); }
void Demo::onInit() { md2Model = MD2Model::fromFile("d:/games/data/quake2/players/pknight/tris.md2"); GMaterial material; material.texture.append(MD2Model::textureFromFile("d:/games/data/quake2/players/pknight/ctf_b.pcx")); CoordinateFrame obj = CoordinateFrame(Matrix3::fromAxisAngle(Vector3::unitY(), toRadians(30)), Vector3(2, 0, 0)); app->debugCamera.setPosition(Vector3(5,5,5)); app->debugCamera.lookAt(Vector3::zero()); // World control // manipulator->setFrame(obj); // manipulator->setControlFrame(CoordinateFrame()); models.append(md2Model->pose(CoordinateFrame(), MD2Model::Pose(), material)); // Local control manipulator->setFrame(obj); manipulator->setControlFrame(obj); }
void Demo::doGraphics() { LightingParameters lighting(G3D::toSeconds(11, 00, 00, AM)); app->renderDevice->setProjectionAndCameraMatrix(app->debugCamera); // Cyan background app->renderDevice->setColorClearValue(Color3(.1f, .5f, 1)); app->renderDevice->clear(app->sky.isNull(), true, true); if (app->sky.notNull()) { app->sky->render(lighting); } // Setup lighting app->renderDevice->enableLighting(); app->renderDevice->setLight(0, GLight::directional(lighting.lightDirection, lighting.lightColor)); app->renderDevice->setAmbientLightColor(lighting.ambient); Draw::axes(CoordinateFrame(Vector3(0, 4, 0)), app->renderDevice); app->renderDevice->disableLighting(); app->renderDevice->setTexture(0, video); double u = video->texelWidth(); double v = video->texelHeight(); double w = 1; double h = (w * v) / u; app->renderDevice->beginPrimitive(RenderDevice::QUADS); app->renderDevice->setTexCoord(0, Vector2(0, v)); app->renderDevice->sendVertex(Vector2(0, 0)); app->renderDevice->setTexCoord(0, Vector2(u, v)); app->renderDevice->sendVertex(Vector2(w, 0)); app->renderDevice->setTexCoord(0, Vector2(u, 0)); app->renderDevice->sendVertex(Vector2(w, h)); app->renderDevice->setTexCoord(0, Vector2(0, 0)); app->renderDevice->sendVertex(Vector2(0, h)); app->renderDevice->endPrimitive(); /*Draw::rect2D(Rect2D::xywh(-1, 1, 2, -2), app->renderDevice, Color3::white(), Rect2D::xywh(0, 0, video->texelWidth(), video->texelHeight())); app->renderDevice->setTexture(0, NULL);*/ if (app->sky.notNull()) { app->sky->renderLensFlare(lighting); } }
CoordinateFrame CoordinateFrame::lerp( const CoordinateFrame& other, float alpha) const { if(alpha == 1.0f) { return other; } else if(alpha == 0.0f) { return *this; } else { const Quat q1(this->rotation); const Quat q2(other.rotation); return CoordinateFrame( q1.slerp(q2, alpha).toRotationMatrix(), translation * (1 - alpha) + other.translation * alpha); } }
void App::onGraphics3D (RenderDevice* rd, Array<Surface::Ref>& surface3D) { if (_scene.isNull()) { return; } Draw::skyBox(rd, _scene->skyBoxTexture(), _scene->skyBoxConstant()); Surface::sortAndRender(rd, defaultCamera, surface3D, _scene->lighting()); if (_wireframe) { rd->pushState(); { rd->setRenderMode(RenderDevice::RENDER_WIREFRAME); rd->setLineWidth(2); rd->setColor(Color3::black()); Surface::sendGeometry(rd, surface3D); } rd->popState(); } Draw::axes(CoordinateFrame(Vector3(0, 0, 0)), rd); Draw::lighting(_scene->lighting(), rd); if (_renderSettings._usePhotonMap && _raytracer._photonMap) { rd->setPointSize(5); rd->beginPrimitive(PrimitiveType::POINTS); for (PhotonGrid::Iterator it = _raytracer._photonMap->begin(); it.hasMore(); ++it) { rd->setColor(it->power / it->power.max()); rd->sendVertex(it->position); } rd->endPrimitive(); } // Call to make the GApp show the output of debugDraw drawDebugShapes(); }
CoordinateFrame CoordinateFrame::lerp( const CoordinateFrame& other, float alpha) const { if (alpha == 1.0) { return other; } else if (alpha == 0.0) { return *this; } else { Quaternion q1 = Quaternion(this->rotation); Quaternion q2 = Quaternion(other.rotation); Matrix3 kRot; Quaternion q = Quaternion::Slerp(alpha,q1,q2); q.ToRotationMatrix(kRot); return CoordinateFrame(kRot, this->translation * (1 - alpha) + other.translation * alpha); } }
void ArticulatedModel::initOBJ(const std::string& filename, const Preprocess& preprocess) { Stopwatch loadTimer; TextInput::Settings set; set.cppBlockComments = false; set.cppLineComments = false; set.otherCommentCharacter = '#'; set.generateNewlineTokens = true; // Notes on OBJ file format. See also: // // - http://www.martinreddy.net/gfx/3d/OBJ.spec // - http://en.wikipedia.org/wiki/Obj // - http://www.royriggs.com/obj.html // // OBJ indexing is 1-based. // Line breaks are significant. // The first token on a line indicates the contents of the line. // // Faces contain separate indices for normals and texcoords. // We load the raw vertices and then form our own optimized // gl indices from them. // // Negative indices are relative to the last coordinate seen. // Raw arrays with independent indexing, as imported from the file Array<Vector3> rawVertex; Array<Vector3> rawNormal; Array<Vector2> rawTexCoord; // part.geometry.vertexArray[i] = rawVertex[cookVertex[i]]; Array<int> cookVertex; Array<int> cookNormal; Array<int> cookTexCoord; // Put everything into a single part // Convert to a Part Part& part = partArray.next(); part.cframe = CoordinateFrame(); part.name = "root"; part.parent = -1; // v,t,n repeated for each vertex Array<int> faceTempIndex; // Count of errors from mismatched texcoord and vertex int texCoordChanged = 0; int normalChanged = 0; Table<std::string, Material::Ref> materialLibrary; Table<std::string, TriListSpec*> groupTable; TriListSpec* currentTriList = NULL; int numTris = 0; const Matrix3 normalXform = preprocess.xform.upper3x3().transpose().inverse(); const std::string& basePath = FilePath::parent(FileSystem::resolve(filename)); { TextInput ti(filename, set); while (ti.hasMore()) { // Consume comments/newlines while (ti.hasMore() && (ti.peek().type() == Token::NEWLINE)) { // Consume the newline ti.read(); } if (! ti.hasMore()) { break; } // Process one line const std::string& cmd = ti.readSymbol(); if (cmd == "mtllib") { // Specify material library const std::string& mtlFilename = ti.readUntilNewlineAsString(); loadMTL(FilePath::concat(basePath, mtlFilename), materialLibrary, preprocess); } else if (cmd == "g") { // New trilist const std::string& name = ti.readUntilNewlineAsString(); if (! groupTable.containsKey(name)) { currentTriList = new TriListSpec(); currentTriList->name = name; groupTable.set(name, currentTriList); } else { currentTriList = groupTable[name]; } } else if (cmd == "usemtl") { if (currentTriList) { currentTriList->materialName = ti.readUntilNewlineAsString(); } } else if (cmd == "v") { rawVertex.append(readVertex(ti, preprocess.xform)); } else if (cmd == "vt") { // Texcoord Vector2& t = rawTexCoord.next(); t.x = ti.readNumber(); t.y = 1.0f - ti.readNumber(); } else if (cmd == "vn") { // Normal rawNormal.append(readNormal(ti, normalXform)); } else if ((cmd == "f") && currentTriList) { // Face // Read each vertex while (ti.hasMore() && (ti.peek().type() != Token::NEWLINE)) { // Read one 3-part index int v = ti.readNumber(); if (v < 0) { v = rawVertex.size() + 1 + v; } int n = 0; int t = 0; if (ti.peek().type() == Token::SYMBOL) { ti.readSymbol("/"); if (ti.peek().type() == Token::NUMBER) { t = ti.readNumber(); if (t < 0) { t = rawTexCoord.size() + 1 + t; } } if (ti.peek().type() == Token::SYMBOL) { ti.readSymbol("/"); if (ti.peek().type() == Token::NUMBER) { n = ti.readNumber(); if (n < 0) { n = rawNormal.size() + 1 + n; } } } } // Switch to zero-based indexing --v; --n; --t; faceTempIndex.append(v, t, n); } alwaysAssertM(faceTempIndex.size() >= 3*3, "Face with fewer than three vertices in model."); numTris += (faceTempIndex.size()/3) - 2; // The faceTempIndex is now a triangle fan. Convert it to a triangle list and use unique vertices for (int i = 2; i < faceTempIndex.size()/3; ++i) { // Always start with vertex 0 cookVertex.append(faceTempIndex[0]); cookTexCoord.append(faceTempIndex[1]); cookNormal.append(faceTempIndex[2]); // The vertex just before the one we're adding int j = (i - 1) * 3; cookVertex.append(faceTempIndex[j]); cookTexCoord.append(faceTempIndex[j+1]); cookNormal.append(faceTempIndex[j+2]); // The vertex we're adding j = i * 3; cookVertex.append(faceTempIndex[j]); cookTexCoord.append(faceTempIndex[j+1]); cookNormal.append(faceTempIndex[j+2]); // Update the index array to contain the three vertices we just added currentTriList->cpuIndex.append(cookVertex.size() - 3, cookVertex.size() - 2, cookVertex.size() - 1); } faceTempIndex.fastClear(); } // Read until the end of the line while (ti.hasMore() && (ti.read().type() != Token::NEWLINE)); } } debugPrintf("Creating TriLists\n"); // Copy geometry const int N = cookVertex.size(); part.geometry.vertexArray.resize(N); for (int i = 0; i < N; ++i) { part.geometry.vertexArray[i] = rawVertex[cookVertex[i]]; } // Optional normals if (rawNormal.size() > 0) { part.geometry.normalArray.resize(N); for (int i = 0; i < N; ++i) { part.geometry.normalArray[i] = rawNormal[cookNormal[i]]; } } // Optional texcoords if (rawTexCoord.size() > 0) { part.texCoordArray.resize(N); for (int i = 0; i < N; ++i) { part.texCoordArray[i] = rawTexCoord[cookTexCoord[i]]; } } // Create trilists for (Table<std::string, TriListSpec*>::Iterator it = groupTable.begin(); it.hasMore(); ++it) { TriListSpec* s = it->value; Material::Ref material; if (materialLibrary.containsKey(s->materialName)) { material = materialLibrary[s->materialName]; } else { material = Material::createDiffuse(Color3::white() * 0.8f); debugPrintf("Warning: unrecognized material: %s\n", s->materialName.c_str()); } Part::TriList::Ref triList = part.newTriList(material); triList->twoSided = false; triList->indexArray = s->cpuIndex; } groupTable.deleteValues(); groupTable.clear(); debugPrintf("Done loading. %d vertices, %d faces, %d frames\n\n", cookVertex.size(), numTris, N); loadTimer.after("Loading"); }
void TrackDClient::pollForInput(Array<EventRef> &events) { // Update trackers for (int i=0;i<iMin(_numSensors, _tEventNames.size());i++) { float tracker[6]; trackdGetPosition(_trackerMemory, i, &(tracker[0])); trackdGetEulerAngles(_trackerMemory, i, &(tracker[3])); Vector3 trans(tracker[0], tracker[1], tracker[2]); Matrix3 rotY = Matrix3::fromAxisAngle(Vector3(0,1,0), toRadians(tracker[4])); Matrix3 rotX = Matrix3::fromAxisAngle(Vector3(1,0,0), toRadians(tracker[3])); Matrix3 rotZ = Matrix3::fromAxisAngle(Vector3(0,0,1), toRadians(tracker[5])); CoordinateFrame trackerToDevice = CoordinateFrame(trans) * CoordinateFrame(rotY) * CoordinateFrame(rotX) * CoordinateFrame(rotZ); trackerToDevice.translation *= _trackerUnitsToRoomUnitsScale; /** This is probably more direct, but can't test it right now.. float mat[4][4]; trackdGetMatrix(_trackerMemory, i, mat); CoordinateFrame trackerToDevice = CoordinateFrame(Matrix3(mat[0][0], mat[1][1], mat[2][2], mat[0][1], mat[1][1], mat[2][1], mat[0][2], mat[1][2], mat[2][2]), Vector3(mat[0][3], mat[1][3], mat[2][3])); **/ CoordinateFrame eventRoom = _finalOffset[i] * _deviceToRoom * trackerToDevice * _propToTracker[i]; events.append(new Event(getTrackerName(i), eventRoom)); } // Update buttons for (int i=0;i<iMin(_numButtons, _bEventNames.size());i++) { int b = trackdGetButton(_wandMemory, i); if (b != _buttonStates[i]) { _buttonStates[i] = b; std::string name = getButtonName(i); if (b) { name = name + "_down"; } else { name = name + "_up"; } events.append(new Event(name)); } } /** // Update valuators for (int i=0;i<_numValuators;i++) { float v = trackdGetValuator(_wandMemory, i); if (v != _valuatorStates[i]) { _valuatorStates[i] = v; events.append(new Event(getValuatorName(i), v)); } } **/ }
void doGraphics() { bool screenshot = singleScreen || batchScreen; LightingParameters lighting(G3D::toSeconds(10, 00, 00, AM)); // Some models have part of their geometry stored in the "weapon" file. // Darth Maul, for example, has his lower half in the weapon. const double footy = 0.98 * min(model.boundingBox(MD2Model::STAND).getCorner(0).y, weapon.boundingBox(MD2Model::STAND).getCorner(0).y); renderDevice->beginFrame(); renderDevice->clear(true, true, true); renderDevice->pushState(); camera->setProjectionAndCameraMatrix(); beginLighting(lighting); int n = 1; if (!screenshot) { // Draw a bunch of characters for (int z = 0; z < 6; ++z) { for (int x = -2; x <= 2; ++x) { drawCharByParams(x, z, footy, n); ++n; } } } // Draw the main character { CoordinateFrame cframe(Vector3(0, -footy, -8)); if (modelTexture.size() > 0) { renderDevice->setTexture(0, modelTexture.last()); } // use global pose variable drawCharWithShadow(cframe, pose); } endLighting(); renderDevice->setObjectToWorldMatrix(CoordinateFrame()); // Ground plane (to hide parts of characters that stick through ground) renderDevice->setColor(Color3::WHITE); renderDevice->beginPrimitive(RenderDevice::QUADS); renderDevice->sendVertex(Vector3(-50, -.01, 50)); renderDevice->sendVertex(Vector3(50, -.01, 50)); renderDevice->sendVertex(Vector3(50, -.01, -50)); renderDevice->sendVertex(Vector3(-50, -.01, -50)); renderDevice->endPrimitive(); renderDevice->popState(); renderDevice->push2D(); double x = 10; double y = 10; double f = 16; int fontSize = (batchScreen) ? (22) : (30); font->draw2DString(model.name, renderDevice->getWidth()/2, renderDevice->getHeight() - 45, fontSize, Color3::BLACK, Color3::WHITE, GFont::XALIGN_CENTER); if (!screenshot) { font->draw2DString(format("%d fps", iRound(renderDevice->getFrameRate())), x, y, 20, Color3::YELLOW, Color3::BLACK); y += 30; font->draw2DString(format("%d characters", n), x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString(format("%1.1f MB", model.mainMemorySize() / 1e6), x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString(format("%1.0f Mtris/sec", renderDevice->getTriangleRate() / 1e6), x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; x = renderDevice->getWidth() - 130; y = 10; f = 12; font->draw2DString("CLICK attack", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("SPACE jump", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("CTRL crouch", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("1 . . 5 taunt", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("6 . . 8 die", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("9 . . - pain", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("R/T run/back", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("E new character", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; font->draw2DString("Z single screen", x, y, f, Color3::CYAN, Color3::BLACK); y += f * 1.5; } renderDevice->pop2D(); renderDevice->endFrame(); }
void ISenseDirect::pollForInput(Array<EventRef> &events) { ISD_TRACKER_DATA_TYPE trackerData; ISD_GetData( _handle, &trackerData ); for (int s=0;s<_maxStations;s++) { ISD_STATION_STATE_TYPE *data = &trackerData.Station[s]; Vector3 trans = Vector3(data->Position[0], data->Position[1], data->Position[2]); //printf("%6.2f %6.2f %6.2f ", // data->Position[0], data->Position[1], data->Position[2]); CoordinateFrame trackerToDevice; if ( _stationInfo[s].AngleFormat == ISD_QUATERNION ) { //printf("%5.2f %5.2f %5.2f %5.2f ", data->Orientation[0], // data->Orientation[1], data->Orientation[2], data->Orientation[3]); Matrix3 rot = Matrix3(Quat(data->Orientation[0], data->Orientation[1], data->Orientation[2], data->Orientation[3])); trackerToDevice = CoordinateFrame(rot, trans); } else { // Euler angles //printf("%7.2f %7.2f %7.2f ", // data->Orientation[0], data->Orientation[1], data->Orientation[2]); Matrix3 rotY = Matrix3::fromAxisAngle(Vector3(0,1,0), toRadians(data->Orientation[1])); Matrix3 rotX = Matrix3::fromAxisAngle(Vector3(1,0,0), toRadians(data->Orientation[0])); Matrix3 rotZ = Matrix3::fromAxisAngle(Vector3(0,0,1), toRadians(data->Orientation[2])); trackerToDevice = trans * rotY * rotX * rotZ; } trackerToDevice.translation *= _trackerUnitsToRoomUnitsScale; CoordinateFrame eventRoom = _finalOffset[s] * _deviceToRoom * trackerToDevice * _propToTracker[s]; events.append(new Event(getTrackerName(s), eventRoom)); /*printf("%d%d%d%d%d ", (int) data->ButtonState[0], (int) data->ButtonState[1], (int) data->ButtonState[2], (int) data->ButtonState[3], (int) data->ButtonState[4]); */ for (int i=0;i<ISD_MAX_BUTTONS;i++) { if (data->ButtonState[i] != _btnStatus[s][i]) { _btnStatus[s][i] = !_btnStatus[s][i]; if (_btnStatus[s][i]) { events.append(new Event(getButtonName(s, i) + "_down")); } else { events.append(new Event(getButtonName(s, i) + "_up")); } } } // TODO: deal with analogs.. //printf("%d %d ", data->AnalogData[0], data->AnalogData[1]); } }
void App::setViewer(const std::string& newFilename) { filename = newFilename; defaultCamera.setCoordinateFrame(CoordinateFrame(Vector3(0,0,5))); defaultController->setFrame(CoordinateFrame(Vector3(0,0,5))); //modelController->setFrame(CoordinateFrame(Matrix3::fromAxisAngle(Vector3(0,1,0), toRadians(180)))); delete viewer; viewer = NULL; shadowMap->setSize(0); std::string ext = toLower(filenameExt(filename)); std::string base = toLower(filenameBase(filename)); if ((ext == "3ds") || (ext == "ifs") || (ext == "obj") || (ext == "ply2") || (ext == "off") || (ext == "ply") || (ext == "any" && endsWith(base, ".am"))) { shadowMap->setSize(2048); viewer = new ArticulatedViewer(); } else if (Texture::isSupportedImage(filename)) { // Images can be either a Texture or a Sky, TextureViewer will figure it out viewer = new TextureViewer(); // Angle the camera slightly so a sky/cube map doesn't see only 1 face defaultController->setFrame(Matrix3::fromAxisAngle(Vector3::unitY(), halfPi() / 2.0) * Matrix3::fromAxisAngle(Vector3::unitX(), halfPi() / 2.0)); } else if (ext == "fnt") { viewer = new FontViewer(debugFont); } else if (ext == "bsp") { viewer = new BSPViewer(); } else if (ext == "md2") { viewer = new MD2Viewer(); } else if (ext == "gtm") { viewer = new GUIViewer(this); } else if (ext == "icn") { viewer = new IconSetViewer(debugFont); } else if (ext == "pk3") { // Something in Quake format - figure out what we should load Array <std::string> files; bool set = false; // First, try for a .bsp map std::string search = filename + "/maps/*"; FileSystem::getFiles(search, files, true); for (int t = 0; t < files.length(); ++t) { if (filenameExt(files[t]) == "bsp") { filename = files[t]; viewer = new BSPViewer(); set = true; } } if (!set) { viewer = new EmptyViewer(); } } else if (ext == "avi" || ext == "wmv" || ext == "mp4" || ext == "asf" || (ext == "mov") || (ext == "dv") || (ext == "qt") || (ext == "asf") || (ext == "mpg")) { viewer = new VideoViewer(); } else { viewer = new EmptyViewer(); } if (viewer != NULL) { viewer->onInit(filename); } window()->setCaption(filenameBaseExt(filename) + " - G3D Viewer"); }