int PovrayMaker::render() { addCamera(); addLightSource(scale, scale, scale); double axLen=1.5*scale; double axThick=0.005*scale; addCylinder(0, 0,0,axLen, 0,0, axThick,1); addCylinder(0, 0,0,0, axLen,0, axThick,2); addCylinder(0, 0,0,0, 0,axLen, axThick,3); file->close(); QFile iniFile(fileName+QString("%1.ini").arg(dnum)); QString processor("D:\\Program\" \"Files\\POVRAY\\bin\\pvengine /EXIT "); // QString processor("notepad "); if(iniFile.exists()) Povray.start(processor+fileName+QString("%1.ini").arg(dnum)); else Povray.start(processor+fileName+QString("%1.pov").arg(dnum)); if (!Povray.waitForStarted()) return 1; if (!Povray.waitForFinished(-1)) return 2; if(!file->open(QIODevice::Append | QIODevice::Text)) return 3; textOut.setDevice(file); return 0; }
PovrayMaker::~PovrayMaker() { addCamera(); addLightSource(scale, scale, scale); double axLen=1.5*scale; double axThick=0.005*scale; addCylinder(0, 0,0,axLen, 0,0, axThick,1); addCylinder(0, 0,0,0, axLen,0, axThick,2); addCylinder(0, 0,0,0, 0,axLen, axThick,3); }
PhysicsWidget::PhysicsWidget() : QWidget(0) { physicsLbl = new QLabel("Physics:"); physicsLbl->setFixedHeight(28); addBoxBtn = new QPushButton("Add Box"); addSphereBtn = new QPushButton("Add Sphere"); addCylinderBtn = new QPushButton("Add Cylinder"); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(physicsLbl); mainLayout->addWidget(addBoxBtn); mainLayout->addWidget(addSphereBtn); mainLayout->addWidget(addCylinderBtn); setLayout(mainLayout); layout()->setContentsMargins(5,0,0,0); connect(addBoxBtn, SIGNAL(clicked()),this, SLOT(addBox())); connect(addSphereBtn, SIGNAL(clicked()),this, SLOT(addSphere())); connect(addCylinderBtn, SIGNAL(clicked()),this, SLOT(addCylinder())); setFixedHeight(sizeHint().height()); setFixedWidth(150); }
RigidCylinderObject::RigidCylinderObject(float x, float y, float z, float r, float h, float mass){ so = addCylinder(0, 0, 0, r, r, h, 16); btCylinderShape *shape = new btCylinderShapeZ(btVector3(icl2bullet(r * 0.5),icl2bullet(r * 0.5),icl2bullet(h * 0.5))); btTransform T; T.setIdentity(); T.setOrigin(btVector3(icl2bullet(x),icl2bullet(y),icl2bullet(z))); MotionState* motion = new MotionState(T, (RigidObject*)this); btVector3 inertia(0,0,0); shape->calculateLocalInertia(mass, inertia); btRigidBody::btRigidBodyConstructionInfo ci(mass,motion,shape,inertia); ci.m_linearSleepingThreshold *= METER_TO_BULLET_UNIT; ci.m_angularSleepingThreshold *= METER_TO_BULLET_UNIT; setPhysicalObject(new btRigidBody(ci)); }
int PhysicsWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: addBox(); break; case 1: addSphere(); break; case 2: addCylinder(); break; default: ; } _id -= 3; } return _id; }
void NGLScene::keyPressEvent(QKeyEvent *_event) { // this method is called every time the main window recives a key event. // we then switch on the key value and set the camera in the NGLScene switch (_event->key()) { // escape key to quite case Qt::Key_Escape : QGuiApplication::exit(EXIT_SUCCESS); break; // turn on wirframe rendering case Qt::Key_W : glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); break; // turn off wire frame case Qt::Key_S : glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); break; // show full screen case Qt::Key_F : showFullScreen(); break; // show windowed case Qt::Key_N : showNormal(); break; case Qt::Key_Space : m_car->reset(); break; case Qt::Key_X : stepAnimation(); break; case Qt::Key_1 : addCube(); break; case Qt::Key_2 : addSphere(); break; case Qt::Key_3 : addCapsule(); break; case Qt::Key_4 : addCylinder(); break; case Qt::Key_5 : addCone(); break; case Qt::Key_6 : addMesh(TEAPOT); break; case Qt::Key_7 : addMesh(APPLE); break; /* case Qt::Key_Left : m_physics->addImpulse(ngl::Vec3(-5,0.0f,0.0f)); break; case Qt::Key_Right : m_physics->addImpulse(ngl::Vec3(5.0f,0.0f,0.0f)); break; case Qt::Key_Up : m_physics->addImpulse(ngl::Vec3(0.0f,5.0f,0.0f)); break; case Qt::Key_Down : m_physics->addImpulse(ngl::Vec3(0.0f,-5.0f,0.0f)); break; */ case Qt::Key_Left : m_car->left(); break; case Qt::Key_Right : m_car->right(); break; case Qt::Key_Up : m_car->accelerate(); break; case Qt::Key_Down : m_car->stop(); break; case Qt::Key_B : toggleBBox(); break; case Qt::Key_R : toggleRandomPlace(); break; case Qt::Key_0 : resetSim(); break; default : break; } // finally update the GLWindow and re-draw //if (isExposed()) renderNow(); }