📄 uproc.c
字号:
/****************************************************************************** ** uproc.c --** OpenGVS run-time code for the Train demo********************************************************************************/#include <g_sys.h>#include <stdio.h>#include <stdlib.h>#include <g_timer.h>#include <g_consts.h>#include <g_timer.h>#include <gv_cam.h>#include <gv_chn.h>#include <gv_fbf.h>#include <gv_user.h>#include <gvu_path.h>#include <tgifts.h>#include "train.h"#include "hostdata.h"/* Global throughout this module only */static G_Boolean debug = G_FALSE;static TParse_data * tdata = NULL;static GV_Obi owntrain = NULL;/*************************************************************************** ** path_proc--** Update the specified object every frame based upon the path*****************************************************************************/static void path_proc( GVU_Path path, GV_Obi object ){ G_Position position; G_Rotation rotation; GVU_path_inq_position_current( path, &position ); GVU_path_inq_rotation_current( path, &rotation ); GV_obi_set_position( object, &position ); GV_obi_set_rotation( object, &rotation );}/*************************************************************************** ** GV_user_proc --** OpenGVS callback function;* called every frame to handle graphics updates*****************************************************************************/int GV_user_proc( void ){ static G_Boolean first_time = G_TRUE; static GV_Obi train_town = NULL; static GV_Obi skydome = NULL; GV_Channel chnhdl; GV_Camera camera; G_State state; GV_chn_inq_input_focus( &chnhdl ); GV_chn_inq_camera( chnhdl, &camera ); if( pcf_timing ) ttiming_uproc_pre() ; if( first_time ) { /* Save pointer to command line data */ tparse_inq_data( &tdata ); GV_obi_inq_by_name( "SKYDOME", &skydome ); GV_obi_inq_by_name( "TRAIN_TOWN", &train_town ); GV_obi_inq_by_name( "OWNTRAIN", &owntrain ); if( debug ) { GV_Scene scene; GV_Fog fogmodel; float clipnear, clipfar, visibility; GV_chn_inq_clip_far( chnhdl, &clipfar ); GV_chn_inq_clip_near( chnhdl, &clipnear ); GV_chn_inq_scene( chnhdl, &scene ); GV_scn_inq_fog( scene, &fogmodel ); GV_fog_inq_opaque_distance( fogmodel, &visibility ); fprintf( stdout, "GV_user_proc: channel near=%.2f, far=%.2f, " "fog range=%.2f\n", clipnear, clipfar, visibility ); } first_time = G_FALSE; } if( tdata && tdata->network_duties != NETWORK_DUTIES_SLAVE ) { static G_Boolean last_pause = G_FALSE; static G_Boolean sleep_while_paused = G_FALSE; static float elapsed_time = 0.0; int inx; if( !path_owntrain ) GVU_path_inq_by_name( "OWNTRAIN", &path_owntrain ); if( pcf_pause ) { /* We are paused... skipping equations of motion and path updates*/ if( last_pause == G_FALSE ) { /* Transition from unpaused to paused */ if( path_owntrain ) GVU_path_inq_time( path_owntrain, &elapsed_time ); } last_pause = G_TRUE; if( sleep_while_paused ) G_sleep( 100 ); /* Milliseconds */ return G_SUCCESS; } else if( (pcf_pause == G_FALSE) && (last_pause == G_TRUE) ) { /* Transition from paused to unpaused; restart all active path logic if any @ the time when we initially paused */ GVU_Path path; GVU_path_inq_first( &path ); while( path ) { GVU_path_reset( path ); GVU_path_set_time( path, elapsed_time ); GVU_path_inq_next( path, &path ); } } last_pause = pcf_pause; /* We are not paused... do normal processing */ if( path_owntrain && owntrain ) path_proc( path_owntrain, owntrain ); for( inx=0; inx<NUM_VEHICLES; inx++ ) path_proc( path_other[inx], vobi[inx] ); if( pcf_record && !pcf_pause ) { static int period = 15; trecord_frame( owntrain, period ); } } GV_obi_inq_state( skydome, &state ); if( state == G_ON ) { /* The skydome will be translated in x and z with the current camera world position to remain fully visible with the eyepoint */ G_Position position; G_Rotation rotation; GV_cam_inq_pos_rot_world( camera, GV_CAM_PLATFORM_LAST, &position, &rotation ); GV_obi_set_position_x( skydome, position.x ); GV_obi_set_position_z( skydome, position.z ); } if( tdata && tdata->network_duties == NETWORK_DUTIES_SLAVE ) { int status; /* Get raw data from master */ status = dnet_slave_get_data( sizeof (host_data), &host_data_length, &host_data ); if( status == G_SUCCESS ) host_slave_get( owntrain, camera ); } /* Perform any spotlight special effects processing as required */ tspotlight_proc( owntrain ); return G_SUCCESS;}/*************************************************************************** ** GV_user_proc_post --** OpenGVS callback function;* called every frame at end of *all* callbacks (cameras, users,* objects, ...) and right before graphics commands from OpenGVS to* the hardware start for this frame*****************************************************************************/int GV_user_proc_post( void ){ GV_Channel chnhdl; GV_chn_inq_input_focus( &chnhdl ); if( chnhdl ) { GV_Camera camera; GV_chn_inq_camera( chnhdl, &camera ); if( tdata && tdata->network_duties == NETWORK_DUTIES_MASTER ) { /* Update "raw" network data */ host_master_put( owntrain, camera ); /* Send raw data to slaves */ dnet_master_send_data( host_data_length, &host_data ); } } if( pcf_timing ) { static int frame = 0 ; ttiming_uproc_post() ; ttiming_frame_count( frame++ ) ; } return G_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -