Esempio n. 1
0
    virtual void calc()
    {
        if( fn_bind() )          // avoid GPF!
        {
            if( fn_calc() )      // check or recalc input
            {

                glm::mat4 camera_world_position(1.f);                 // camera world position
                glm::mat4 camera_view(1.f);                           // camera view transformation

                // load camera world position from gdom "wpos"
                set_glm_mat4_from_m4(camera_world_position, mp_wpos); // init glm-variable from gx-gdom-field

                // GetViewMatrix() const
                float* cwp = glm::value_ptr(camera_world_position);   // used as float[16]
                glm::vec3 camera_position(cwp[12], cwp[13], cwp[14]); // cwp translation;
                glm::vec3 z(cwp[ 2], cwp[ 6], cwp[10]);               // cwp z-vector;
                glm::vec3 look_at_point = camera_position + z;
                glm::vec3 up_vector      (cwp[ 1], cwp[ 5], cwp[ 9]); // cwp y-vector;

                camera_view = glm::lookAt(camera_position, look_at_point, up_vector);

                // save camera_view to gdom "view"
                set_m4_from_glm_mat4(mp_view, camera_view);

                // reset state to GOOD
                return gx::fn::calc_success();
            }
            else
            {
                return gx::fn::fn_calc_failed();
            }
        }
        else
        {
            return gx::fn::fn_bind_failed();
        }
    }
Esempio n. 2
0
gint facet_visible(struct model_pak *data, struct plane_pak *plane)
{
gdouble a, norm[3], vec[3];

/* NEW - an edge (2 vertices) is not to be treated as visible */
if (g_slist_length(plane->vertices) < 3)
  return(FALSE);

/* get plane  normal */
ARR3SET(norm, plane->norm);

VEC3MUL(norm, -1.0);

#if DEBUG_FACET
printf("facet (%2d%2d%2d), norm: %5.2f,%5.2f,%5.2f    " 
,plane->index[0] ,plane->index[1] ,plane->index[2]
,norm[0],norm[1],norm[2]);
#endif

/* absolute viewing vector, determining if visible or not */
camera_view(vec, data->camera);

/* got correct facet normal - is it visible? */
a = via(norm,vec,3);
if (a < 0.5*G_PI)
  {
#if DEBUG_FACET
printf("view: %5.2f,%5.2f,%5.2f (%5.1f) YES\n",vec[0],vec[1],vec[2],180.0*a/PI);
#endif
  return(TRUE);
  }
/* else... */
#if DEBUG_FACET
printf("view: %5.2f,%5.2f,%5.2f (%5.1f) NO\n",vec[0],vec[1],vec[2],180.0*a/PI);
#endif
return(FALSE);
}
Esempio n. 3
0
void scene_render(scene_t *scene,float ifps) {
    int i,j,light;
    static int frame;
    glDisable(GL_FOG);
    glDisable(GL_LIGHTING);
    glDisable(GL_TEXTURE_2D);
    scene_update(scene,ifps);   // update scene
    scene_animation(scene); // create mesh and check view animated object
    scene_particle(scene);  // check view and move particle system
    scene_dynamiclight(scene);  // check view and move dynamiclight
    if(frame == FRAME_PER_SHADOW) {
        shadow_enable_shadowmap();  // create shadow maps
        for(i = 0; i < scene->num_animation; i++)
            if(scene->animation[i]->view && scene->animation[i]->shadow > 0)
                shadow_shadowmap(scene->sun->pos,scene->animation[i]->thing,scene->animation[i]->shadow);
        shadow_disable_shadowmap(sys_width(),sys_height());
        frame = 0;
    }
    frame++;
    glColor4f(1.0,1.0,1.0,1.0);
    glEnable(GL_TEXTURE_2D);
    camera_view(scene->camera); // set camera
    sky_render(scene->sky,scene->camera,ifps);  // render sky
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);        // sun light
    glLightfv(GL_LIGHT0,GL_POSITION,scene->sun->pos);
    glLightfv(GL_LIGHT0,GL_DIFFUSE,scene->sun->color);
    glEnable(GL_FOG);
    for(i = 0, j = 1, light = 0; i < scene->num_dynamiclight; i++)
        if(scene->dynamiclight[i]->opengl) {    // add dynamic lights
            switch(j) {
                case 1: light = GL_LIGHT1; break;
                case 2: light = GL_LIGHT2; break;
                case 3: light = GL_LIGHT3; break;
                case 4: light = GL_LIGHT4; break;
                case 5: light = GL_LIGHT5; break;
                case 6: light = GL_LIGHT6; break;
                case 7: light = GL_LIGHT7; break;
            }
            glEnable(light);
            glLightfv(light,GL_POSITION,scene->dynamiclight[i]->light->center);
            glLightfv(light,GL_DIFFUSE,scene->dynamiclight[i]->light->color);
            j++;
            if(j == 8) break;
        }
    glFogfv(GL_FOG_COLOR,scene->camera->fogcolor);
    glFogf(GL_FOG_START,scene->camera->fogstart);
    glFogf(GL_FOG_END,scene->camera->fogend);
    land_render(scene->land,scene->camera); // render landscape
    for(i = 0; i < scene->num_thing; i++)   // render thing
        if(camera_check_sphere(scene->camera,scene->thing[i]->center,scene->thing[i]->radius) &&
           camera_check_box(scene->camera,scene->thing[i]->min,scene->thing[i]->max))
            thing_render(scene->thing[i]);
    for(i = 0; i < scene->num_animation; i++)   // render animated object
        if(scene->animation[i]->view)
            thing_render(scene->animation[i]->thing);
    glDisable(GL_LIGHTING);
    shadow_enable_project();
    for(i = 0; i < scene->num_animation; i++)   // dynamic shadow on land
        if(scene->animation[i]->view && scene->animation[i]->shadow > 0) {
            shadow_project(scene->sun->pos,scene->animation[i]->thing);
            land_dynamicshadow(scene->land,scene->sun->pos,scene->animation[i]->thing);
        }
    shadow_disable_project();
    for(i = 0; i < scene->num_particle; i++)    // particle
        if(scene->particle[i]->view)
            particle_render(scene->particle[i]->particle,scene->camera,ifps);
    for(i = 0; i < scene->num_dynamiclight; i++)// dynamiclight
        if(scene->dynamiclight[i]->view)
            dynamiclight_render(scene->dynamiclight[i]->light,scene->camera,scene->land);
    glDisable(GL_FOG);
    sky_sun_render(scene->sun,scene->camera);   // render sun and flare
    glDisable(GL_TEXTURE_2D);
}