void GameObjectView::loadView( const Resource &r, Physics & p, bool env ) { m.initalModelHeight = 0; physic = &p; view.clear(); m.radius = 0; float ksize = rand()/float(RAND_MAX);//getClass().sizeBounds; double *sz = m.rndSize; for( int i=0; i<3; ++i ){ double diff = getClass().sizeBounds.max[i]-getClass().sizeBounds.min[i]; sz[i] = getClass().sizeBounds.min[i]+diff*ksize; } for( size_t i=0; i<getClass().view.size(); ++i ){ const ProtoObject::View &v = getClass().view[i]; size_t envC = this->env.size(); loadView( r, v, env ); for( size_t r=envC; r<this->env.size(); ++r ) this->env[r].viewID = i; } bool res = false; for( size_t i=0; i<getClass().behaviors.size(); ++i ) if( getClass().behaviors[i]=="resource" ) res = true; if( !getClass().data.isBackground || res ){ { const ProtoObject::View & v = prototypes.get("selection.green").view[0]; setupMaterials( *selection[0], v ); } { const ProtoObject::View & v = prototypes.get("selection.over").view[0]; setupMaterials( *selection[1], v ); } { const ProtoObject::View & v = prototypes.get("selection.moveTo").view[0]; setupMaterials( *selection[2], v ); } { const ProtoObject::View & v = prototypes.get("selection.moveTo").view[0]; setupMaterials( *selection[3], v ); } { const ProtoObject::View & v = prototypes.get("selection.atkTo").view[0]; setupMaterials( *selection[4], v ); } for( int i=0; i<selectModelsCount; ++i ) r.model("quad/model").setTo( *selection[i] ); } setViewSize(1, 1, 1); //rotate( 180 ); }
void Oblig4App::display() { // Clear buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Set up projection matrix glMatrixMode(GL_PROJECTION); glm::mat4x4 projection_matrix = m_viewer_.getProjectionMatrix(); glLoadMatrixf(glm::value_ptr(projection_matrix)); // Set the matrix mode to Modelview glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Light stationary with regard to camera (because MV matrix is empty) GLfloat light0_position[] = { 2.0f, 2.0f, 2.0f, 1.0f }; glLightfv(GL_LIGHT0, GL_POSITION, light0_position); // Set the MV matrix glm::mat4x4 model_view_matrix = m_viewer_.getModelViewMatrix(); model_view_matrix = glm::translate(model_view_matrix, glm::vec3(0.0, 0.0, -1.0)); model_view_matrix = glm::scale(model_view_matrix, glm::vec3(0.5, 0.5, 0.5)); glLoadMatrixf(glm::value_ptr(model_view_matrix)); // Position the directional light (stationary to the object) GLfloat light1_position[] = { 0.0f, -1.0f, 0.0f, 0.0f }; glLightfv(GL_LIGHT1, GL_POSITION, light1_position); // Render the mesh setupMaterials(); m_meshes_[m_current_level_]->render(); glutSwapBuffers(); CHECK_OPENGL; }
void SceneObject::draw() { setupMaterials(); glPushMatrix(); glTranslated( pos[0], pos[1], pos[2] ); drawGeom(); glPopMatrix(); }
void GameObjectView::loadView( const Model &model, const ProtoObject::View & pview ){ view.clear(); for( int i=0; i<3; ++i ) m.modelSize[i] = model.bounds().max[i]-model.bounds().min[i]; GraphicObject object( scene ); //object.setModel( model ); model.setTo(object); m.radius = model.bounds().radius(); setupMaterials( object, pview ); view.push_back( object ); }
bool Physics::initialize() { // init physics engine _p_world = NewtonCreate( physicsAlloc, physicsFree ); assert( _p_world ); // set minimum frame rate NewtonSetMinimumFrameRate( _p_world, 1.0f / FIX_PHYSICS_UPDATE_PERIOD ); NewtonSetSolverModel( _p_world, 0 ); // 0: exact, 1 adaptive, n linear. for games linear is ok NewtonSetFrictionModel( _p_world, 0 ); // 0: exact, 1 adaptive // setup all predefined materials setupMaterials(); return true; }
Exercise20::Exercise20(QWidget * parent) : AbstractGLExercise(parent) , m_drawable(NULL) , m_he(NULL) , m_shadingMode(Phong_Shading) , m_materialMode(Gold) { m_view = QMatrix4x4(); m_view.lookAt( QVector3D( 0.f, 1.f, 4.f) , QVector3D( 0.f, 0.f, 0.f) , QVector3D( 0.f, 1.f, 0.f)); m_prog_toon = new QGLShaderProgram; m_prog_phong = new QGLShaderProgram; setupLight(); setupMaterials(); }
void GameObjectView::loadView( const Resource & r, const ProtoObject::View &src, bool isEnv ) { const Model & model = r.model( src.name+"/model" ); m.initalModelHeight = std::max<double>(m.initalModelHeight, model.bounds().max[2]); if( view.size()==0 ){ for( int i=0; i<3; ++i ) m.modelSize[i] = model.bounds().max[i]-model.bounds().min[i]; } AbstractGraphicObject * obj = 0; Physics& p = *physic; float szMid = 0; for( int i=0; i<3; ++i ) szMid += src.size[i]; szMid /= 3; if( isEnv ){ if( src.isParticle.size()==0 ){ if( model.groupsCount() ){ for( size_t i=0; i<model.groupsCount(); ++i ){ EnvObject object( scene ); object.setModel( model.group(i) ); env.push_back( object ); Model m = model.group(i); if( m.physicType()==ModelPhysic::Sphere ){ setForm( this->env.back(), p.createSphere( x(), y(), 0, object.model().radius()*szMid ) ); } if( m.physicType()==ModelPhysic::Box ){ const double bs[] = { m.boxSzX()*src.size[0], m.boxSzY()*src.size[1], m.boxSzZ()*src.size[2], }; setForm( this->env.back(), p.createBox( x(), y(), 0, bs[0], bs[1], bs[2] )); } setupMaterials( env.back(), src ); } } else { EnvObject object( scene ); object.setModel( model ); env.push_back( object ); if( src.physModel==ProtoObject::View::Sphere ){ setForm( this->env.back(), p.createSphere( x(), y(), 0, src.sphereDiameter ) ); } if( src.physModel==ProtoObject::View::Box ){ const double *bs = src.boxSize; setForm( this->env.back(), p.createBox( x(), y(), 0, bs[0], bs[1], bs[2] )); } obj = &env.back(); } }else { ParticleSystem sys( psysEngine, src, prototypes.particle(src.isParticle) ); particles.push_back( sys ); } } else { if( src.isParticle.size()==0 ){ if( (int(model.size()) > GraphicsSystem::dipOptimizeRef() || !getClass().data.isBackground || getClass().data.isDynamic) && !src.hasOverDecal && !src.isLandDecal){ GraphicObject object( scene ); //object.setModel( model ); model.setTo(object); object.setRotation( 0, -90 ); view.push_back( object ); if( src.randRotate ){ view.back().setRotation(0, rand()%360 ); } obj = &view.back(); } else { int rot = rand()%360; addPacketObject<SmallGraphicsObject>(model, src, rot); if( src.hasOverDecal ){ const ProtoObject::View &v = wrld.game.prototype("land.snow").view[0]; addPacketObject<DecalObject>(model, src, rot, &v); } } //view.back().setSize( sz[0], sz[1], sz[2] ); } else { particles.emplace_back( psysEngine, src, prototypes.particle(src.isParticle) ); } } if( obj ){ setupMaterials(*obj, src ); } bool pCrt = true; //#ifdef __ANDROID__ if( physic->detail()<2 ) pCrt = this->getClass().data.isBackground; //#endif m.radius = std::max(m.radius, model.bounds().diameter()/2.0 ); if( pCrt ){ if( src.physModel==ProtoObject::View::Sphere ){ if( !isEnv ){ setForm( p.createAnimatedSphere ( x(), y(), 0, src.sphereDiameter )); } } if( src.physModel==ProtoObject::View::Box ){ if( !isEnv ){ const double *bs = src.boxSize; setForm( p.createAnimatedBox( x(), y(), 0, bs[0], bs[1], bs[2] )); } } } }