예제 #1
0
//------------------------------------------------------------------------------
sf::Vector2f Camera::screenToWorld(const sf::Vector2i & screenPoint) const
{
	sf::Vector2i screenSize = Application::instance()->screenSize();

	sf::Vector2f vpos(
		2.f * (static_cast<f32>(screenPoint.x) / static_cast<f32>(screenSize.x)) - 1.f,
		2.f * (1.f - static_cast<f32>(screenPoint.y) / static_cast<f32>(screenSize.y)) - 1.f
	);

	return m_view.getInverseTransform().transformPoint(vpos);
}
예제 #2
0
std::size_t ConsoleWriteChannel::write(const byte_buffer& buffer)
{
	DWORD result = 0;
	BOOL succeeded = peer_(hCons_,
	                vpos(buffer),
	                buffer.length() / charSize_,
	                &result,
	                NULL);
	validate_io(succeeded,"Write console error.");
	result = result * charSize_;
	return result;
}
float DetourCrowdComponent::getDistanceToGoal() const
{
	if( !m_isInCrowd )
	{
		return -1.0f;
	}

	dtCrowd* crowd = DetourCrowdManager::instance()->getCrowd();
	const dtCrowdAgent* ag = crowd->getAgent(m_crowdId);

	Vec3f tpos(ag->targetPos[0],ag->targetPos[1],ag->targetPos[2]);
	Vec3f vpos(ag->npos[0],ag->npos[1],ag->npos[2]);
	Vec3f curEntityToTargetVec =  tpos - vpos;

	return curEntityToTargetVec.length();
}
예제 #4
0
파일: Game.cpp 프로젝트: xzrunner/t3d
void Game::Init()
{
	Modules::Init();

	Modules::GetLog().Init();

	Modules::GetGraphics().Init(main_window_handle,
		WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP);

	Modules::GetInput().Init(main_instance);
	Modules::GetInput().InitKeyboard(main_window_handle);

	Modules::GetSound().Init(main_window_handle);
//	Modules::GetMusic().Init(main_window_handle);

	// hide the mouse
	if (!WINDOWED_APP)
		ShowCursor(FALSE);

	// seed random number generator
	srand(Modules::GetTimer().Start_Clock());

// 	// initialize math engine
// 	Build_Sin_Cos_Tables();

	// initialize the camera with 90 FOV, normalized coordinates
	_cam = new Camera(CAM_MODEL_EULER,
					  vec4(0,0,0,1),
					  vec4(0,0,0,1),
					  vec4(0,0,0,0),
					  50.0f,
					  500.0f,
					  90.0f,
					  WINDOW_WIDTH,
					  WINDOW_HEIGHT);

	// all your initialization code goes here...
	vec4 vscale(5.0,5.0,5.0,1),  // scale of object
		vpos(0,0,0,1),        // position of object
		vrot(0,0,0,1);        // initial orientation of object

	// load the cube
	_obj.LoadPLG("../../assets/t3d/cube2.plg", &vscale, &vpos, &vrot);

	// set the position of the cube in the world
	_obj.SetWorldPos(0, 0, 100);
}
CVector CStreamSource::getVirtualPos() const
{
	if (getCluster() != 0)
	{
		// need to check the cluster status
		const CClusteredSound::CClusterSoundStatus *css = CAudioMixerUser::instance()->getClusteredSound()->getClusterSoundStatus(getCluster());
		if (css != 0)
		{
			// there is some data here, update the virtual position of the sound.
			float dist = (css->Position - getPos()).norm();
			CVector vpos(CAudioMixerUser::instance()->getListenPosVector() + css->Direction * (css->Dist + dist));
			vpos = _Position * (1-css->PosAlpha) + vpos*(css->PosAlpha);
			return vpos;
		}
	}

	return getPos();
}
예제 #6
0
void column::output()
{
    assert(out != 0);
    vunits vpos(V0);
    output_line *ln = col;
    while (ln) {
        vpos += ln->distance();
        ln->output(out, vpos);
        vpos += ln->height();
        output_line *tem = ln->next;
        delete ln;
        ln = tem;
    }
    tail = &col;
    bottom = V0;
    col = 0;
    the_output = out;
    out = 0;
}
void DetourCrowdComponent::update( dtCrowd* crowd)
{
	if( m_pendingAddToSim )
	{
		addBackToSim();
		return;
	}
	const dtCrowdAgent* ag = crowd->getAgent(m_crowdId);
	if( ag->active && m_isInCrowd )
	{
		const float* pos = ag->npos;
		const float* vel = ag->vel;
		Vec3f velo( vel[0], vel[1], vel[2] );
		Vec3f veloRot = velo.toRotation();
		
		// Scenegraph expects degree, Bullet radians. This should be fixed in those components.
		// Rotate: degree (Scenegraph)
		float yrot = radToDeg(veloRot.y);
		yrot -= 180.f;
		// Rotate: radian (Bullet Physics)
		//float yrot = veloRot.y - Math::Pi;

		//const float* trans = GameEngine::getEntityTransformation(m_owner->worldId());

		// The entity travels on the navigation mesh.
		GameEngine::setEntityTranslation( m_owner->worldId(), pos[0], pos[1] + m_yOffset, pos[2] );
		GameEngine::setEntityRotation( m_owner->worldId(), 0, yrot, 0);

		Vec3f tpos(ag->targetPos[0],ag->targetPos[1],ag->targetPos[2]);
		Vec3f vpos(ag->npos[0],ag->npos[1],ag->npos[2]);
		Vec3f curEntityToTargetVec =  tpos - vpos;

		if( curEntityToTargetVec.length() < m_targetRadius )
		{
			// Target reached. Remove from sim and add obstacle.
			tempRemoveFromSim();
			GameEvent targetReachedEv( GameEvent::E_TARGET_REACHED, 0, 0 );
			GameEngine::sendEvent( m_worldId, &targetReachedEv );
		}
	}
}
예제 #8
0
파일: Game.cpp 프로젝트: xzrunner/t3d
void Game::Init()
{
	Modules::Init();

	Modules::GetLog().Init();

	Modules::GetGraphics().Init(main_window_handle,
		WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP, false);

	Modules::GetInput().Init(main_instance);
	Modules::GetInput().InitKeyboard(main_window_handle);

	Modules::GetSound().Init(main_window_handle);
//	Modules::GetMusic().Init(main_window_handle);

	// hide the mouse
	if (!WINDOWED_APP)
		ShowCursor(FALSE);

	// seed random number generator
	srand(Modules::GetTimer().Start_Clock());

// 	// initialize math engine
// 	Build_Sin_Cos_Tables();

	// initialize the camera with 90 FOV, normalized coordinates
	_cam = new Camera(CAM_MODEL_EULER,		// the euler model
					  vec4(0,0,0,1),	// initial camera position
					  vec4(0,0,0,1),		// initial camera angles
					  vec4(0,0,0,1),		// no target
					  10.0,					// near and far clipping planes
					  12000.0,
					  120.0,					// field of view in degrees
					  WINDOW_WIDTH,			// size of final screen viewport
					  WINDOW_HEIGHT);


	// filenames of objects to load
	char *object_filenames[NUM_OBJECTS] = {
		"../../assets/chap12/fighter_01.cob",
	};

	// load in default object
	vec4 vscale(5.00,5.00,5.00,1),
		 vpos(0,0,150,1), 
		 vrot(0,0,0,1);

	// load all the objects in
	for (int index_obj=0; index_obj < NUM_OBJECTS; index_obj++)
	{
		obj_array[index_obj]->LoadCOB(object_filenames[index_obj],
									  &vscale, &vpos, &vrot, 
									  VERTEX_FLAGS_SWAP_YZ  | 
									  VERTEX_FLAGS_INVERT_WINDING_ORDER |
									  VERTEX_FLAGS_TRANSFORM_LOCAL 
									  /* VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD*/ );

	} // end for index_obj

	// set current object
	curr_object = 0;
	obj_work = obj_array[curr_object];

	vscale.Assign(20.00,20.00,20.00);

	// load in the scenery object that we will place all over the place
	obj_scene->LoadCOB("../../assets/chap12/borg_flat_01.cob",  
					   &vscale, &vpos, &vrot, 
					   VERTEX_FLAGS_SWAP_YZ  |
					   VERTEX_FLAGS_TRANSFORM_LOCAL 
					   /* VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD*/ );

	// position the scenery objects randomly
	for (int index = 0; index < NUM_SCENE_OBJECTS; index++)
	{
		// randomly position object
		scene_objects[index].x = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
		scene_objects[index].y = RAND_RANGE(-(UNIVERSE_RADIUS/2), (UNIVERSE_RADIUS/2));
		scene_objects[index].z = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
	} // end for

	// select random velocities
	for (int index = 0; index < NUM_SCENE_OBJECTS; index++)
	{
		// randomly position object
		scene_objects_vel[index].x = RAND_RANGE(-MAX_VEL, MAX_VEL);
		scene_objects_vel[index].y = RAND_RANGE(-MAX_VEL, MAX_VEL);
		scene_objects_vel[index].z = RAND_RANGE(-MAX_VEL, MAX_VEL);
	} // end for

	// set up lights
	LightsMgr& lights = Modules::GetGraphics().GetLights();
	lights.Reset();

	// create some working colors
	Color white(255,255,255,0),
		  gray(100,100,100,0),
		  black(0,0,0,0),
		  red(255,0,0,0),
		  green(0,255,0,0),
		  blue(0,0,255,0);

	// ambient light
	lights.Init(AMBIENT_LIGHT_INDEX,   
				LIGHT_STATE_ON,      // turn the light on
				LIGHT_ATTR_AMBIENT,  // ambient light type
				gray, black, black,    // color for ambient term only
				NULL, NULL,            // no need for pos or dir
				0,0,0,                 // no need for attenuation
				0,0,0);                // spotlight info NA

	vec4 dlight_dir(-1,0,-1,1);

	// directional light
	lights.Init(INFINITE_LIGHT_INDEX,  
				LIGHT_STATE_ON,      // turn the light on
				LIGHT_ATTR_INFINITE, // infinite light type
				black, gray, black,    // color for diffuse term only
				NULL, &dlight_dir,     // need direction only
				0,0,0,                 // no need for attenuation
				0,0,0);                // spotlight info NA

	vec4 plight_pos(0,200,0,1);

	// point light
	lights.Init(POINT_LIGHT_INDEX,
				LIGHT_STATE_ON,      // turn the light on
				LIGHT_ATTR_POINT,    // pointlight type
				black, green, black,   // color for diffuse term only
				&plight_pos, NULL,     // need pos only
				0,.002,0,              // linear attenuation only
				0,0,1);                // spotlight info NA

	vec4 slight2_pos(0,1000,0,1);
	vec4 slight2_dir(-1,0,-1,1);

	// spot light2
	lights.Init(SPOT_LIGHT2_INDEX,
				LIGHT_STATE_ON,         // turn the light on
				LIGHT_ATTR_SPOTLIGHT2,  // spot light type 2
				black, red, black,      // color for diffuse term only
				&slight2_pos, &slight2_dir, // need pos only
				0,.001,0,                 // linear attenuation only
				0,0,1);    


// 	// create lookup for lighting engine
// 	RGB_16_8_IndexedRGB_Table_Builder(DD_PIXEL_FORMAT565,  // format we want to build table for
// 		palette,             // source palette
// 		rgblookup);          // lookup table

	// create the z buffer
	zbuffer->Create(WINDOW_WIDTH, WINDOW_HEIGHT, ZBUFFER_ATTR_32BIT);

	// load in the background
	background->Create(0,0,800,600,1, BOB_ATTR_VISIBLE | BOB_ATTR_SINGLE_FRAME, DDSCAPS_SYSTEMMEMORY, 0, 32);
	BmpFile* bitmap = new BmpFile("../../assets/chap12/nebred01.bmp");
	background->LoadFrame(bitmap, 0,0,0,BITMAP_EXTRACT_MODE_ABS);
	delete bitmap;
}
예제 #9
0
파일: Game.cpp 프로젝트: xzrunner/t3d
void Game::Init()
{
	Modules::Init();

	Modules::GetLog().Init();

	Modules::GetGraphics().Init(main_window_handle,
		WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BPP, WINDOWED_APP);

	Modules::GetInput().Init(main_instance);
	Modules::GetInput().InitKeyboard(main_window_handle);

	Modules::GetSound().Init(main_window_handle);
//	Modules::GetMusic().Init(main_window_handle);

	// hide the mouse
	if (!WINDOWED_APP)
		ShowCursor(FALSE);

	// seed random number generator
	srand(Modules::GetTimer().Start_Clock());

// 	// initialize math engine
// 	Build_Sin_Cos_Tables();

	// initialize the camera with 90 FOV, normalized coordinates
	_cam = new Camera(CAM_MODEL_EULER,
					  vec4(0,40,0,1),
					  vec4(0,0,0,1),
					  vec4(0,0,0,1),
					  200.0f,
					  12000.0f,
					  120.0f,
					  WINDOW_WIDTH,
					  WINDOW_HEIGHT);

	// all your initialization code goes here...
	vec4 vscale(0.75f,0.75f,0.75f,1),		// scale of object
		vpos(0,0,0,1),        // position of object
		vrot(0,0,0,1);        // initial orientation of object

	// load the master tank object
	vscale.Assign(0.75,0.75,0.75);
	_obj_tank.LoadPLG("../../assets/chap09/tank3.plg",&vscale, &vpos, &vrot);

	// load player object for 3rd person view
	vscale.Assign(15.75,15.75,15.75);
	_obj_player.LoadCOB("../../assets/chap09/tie04.cob",  
		&vscale, &vpos, &vrot, VERTEX_FLAGS_INVERT_TEXTURE_V |
		VERTEX_FLAGS_SWAP_YZ | VERTEX_FLAGS_TRANSFORM_LOCAL_WORLD);

	// load the master tower object
	vscale.Assign(1.0, 2.0, 1.0);
	_obj_tower.LoadPLG("../../assets/chap09/towerg1.plg",&vscale, &vpos, &vrot);

	// load the master ground marker
	vscale.Assign(3.0,3.0,3.0);
	_obj_marker.LoadPLG("../../assets/chap09/marker2.plg",&vscale, &vpos, &vrot);

	// position the tanks
	for (int index = 0; index < NUM_TANKS; index++)
	{
		// randomly position the tanks
		_tanks[index].x = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
		_tanks[index].y = 0; // obj_tank.max_radius;
		_tanks[index].z = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
		_tanks[index].w = RAND_RANGE(0,360);
	}
	// position the towers
	for (int index = 0; index < NUM_TOWERS; index++)
	{
		// randomly position the tower
		_towers[index].x = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
		_towers[index].y = 0; // obj_tower.max_radius;
		_towers[index].z = RAND_RANGE(-UNIVERSE_RADIUS, UNIVERSE_RADIUS);
	}

	// set up lights
	LightsMgr& lights = Modules::GetGraphics().GetLights();
	lights.Reset();

	// create some working colors
	Color white(255,255,255,0),
		  gray(100,100,100,0),
		  black(0,0,0,0),
		  red(255,0,0,0),
		  green(0,255,0,0),
		  blue(0,0,255,0);

	// ambient light
	lights.Init(AMBIENT_LIGHT_INDEX,   
		LIGHT_STATE_ON,      // turn the light on
		LIGHT_ATTR_AMBIENT,  // ambient light type
		gray, black, black,    // color for ambient term only
		NULL, NULL,            // no need for pos or dir
		0,0,0,                 // no need for attenuation
		0,0,0);                // spotlight info NA

	vec4 dlight_dir(-1,0,-1,0);

	// directional light
	lights.Init(INFINITE_LIGHT_INDEX,  
		LIGHT_STATE_ON,      // turn the light on
		LIGHT_ATTR_INFINITE, // infinite light type
		black, gray, black,    // color for diffuse term only
		NULL, &dlight_dir,     // need direction only
		0,0,0,                 // no need for attenuation
		0,0,0);                // spotlight info NA


	vec4 plight_pos(0,200,0,0);

	// point light
	lights.Init(POINT_LIGHT_INDEX,
		LIGHT_STATE_ON,      // turn the light on
		LIGHT_ATTR_POINT,    // pointlight type
		black, green, black,   // color for diffuse term only
		&plight_pos, NULL,     // need pos only
		0,.001,0,              // linear attenuation only
		0,0,1);                // spotlight info NA

	vec4 slight_pos(0,200,0,0);
	vec4 slight_dir(-1,0,-1,0);

	// spot light
	lights.Init(SPOT_LIGHT_INDEX,
		LIGHT_STATE_ON,         // turn the light on
		LIGHT_ATTR_SPOTLIGHT2,  // spot light type 2
		black, red, black,      // color for diffuse term only
		&slight_pos, &slight_dir, // need pos only
		0,.001,0,                 // linear attenuation only
		0,0,1);                   // spotlight powerfactor only


// 	// create lookup for lighting engine
// 	RGB_16_8_IndexedRGB_Table_Builder(DD_PIXEL_FORMAT565,  // format we want to build table for
// 		palette,             // source palette
// 		rgblookup);          // lookup table
}
// return true if current position in record is valid and usable
bool
site_crawler::
process_record_line(char* line)
{
    static const unsigned MAX_WORD(50);

    // do a low-level tab parse:
    {
        char* p(line);
        _word[0]=p;
        _n_word=1;
        while (true) {
            if ((*p == '\n') || (*p == '\0')) break;
            if (*p == sep) {
                *p = '\0';
                _word[_n_word++] = p+1;
                if (_n_word == MAX_WORD) break;
            }
            ++p;
        }
        // allow for optional extra columns in each file format:
        if (_n_word<_opt.sti().col_count()) {
            log_os << "ERROR: Consensus record has " << _n_word << " column(s) but expecting at least " << _opt.sti().col_count() << "\n";
            dump_state(log_os);
            exit(EXIT_FAILURE);
        }
    }

    const vcf_pos last_vpos(vpos());
    _chrom=_opt.sti().chrom(_word);
    _vpos.pos=_opt.sti().pos(_word);

    _is_site_allele_current=false;
    _is_indel_allele_current=false;

    _vpos.is_indel=(_opt.sti().get_is_indel(_word));

    if (pos()<1) {
        log_os << "ERROR: gvcf record position less than 1. position: " << pos() << " ";
        dump_state(log_os);
        exit(EXIT_FAILURE);
    }

    if (_opt.is_region()) {
        // deal with vcf records after the region of interest:
        if (pos()>_opt.region_end) {
            _is_sample_begin_state = false;
            _is_sample_end_state = true;
            return true;
        }
    } else {
        if (pos()>static_cast<pos_t>(_ref_seg.end())) {
            log_os << "ERROR: allele file position exceeds final position in reference sequence segment . position: "
                   << pos() << " ref_contig_end: " << _ref_seg.end() << "\n";
            dump_state(log_os);
            exit(EXIT_FAILURE);
        }
    }

    if (! _opt.sti().get_nonindel_ref_length(pos(),is_indel(),_word,_locus_size)) {
        //log_os << "ERROR: failed to parse locus at pos: "  << pos << "\n";
        log_os << "WARNING: failed to parse locus at: "  << vpos() << "\n";
        dump_state(log_os);
        //exit(EXIT_FAILURE);
        _locus_size=0;
    }

    _locus_offset=0;

    // deal with vcf records which fully proceed the region of interest:
    if (_opt.is_region()) {
        if ((pos()+_locus_size-1)<_opt.region_begin) return false;
    }

    //const bool last_is_call(is_call);
    _is_call = _opt.sti().get_is_call(_word,pos(),_skip_call_begin_pos,_skip_call_end_pos);

    _n_total = _opt.sti().total(_word);

    if (is_indel()) {
        if (! _is_return_indels)
        {
            _vpos.pos=last_vpos.pos;
            _locus_size=0;
            return false;
        }
        else
        {
            _locus_size=0;
        }
    }

    if (is_any_call()) {
        _is_call=update_allele();
    }

    // don't allow failed block read-through, so that we can get through indel-overlap errors
    //if(! is_call) {
    //    if(_locus_size>1) _locus_size=1;
    //}

    if (! _is_sample_begin_state) {
        if (! (last_vpos < vpos()) ) {
            if (_opt.is_murdock_mode) {
                _vpos=last_vpos;
                _locus_size=0;
                return false;
            } else {
                log_os << "ERROR: unexpected position order in variant file. current_pos: "
                       << pos() << " last " << last_vpos << "\n";
                dump_state(log_os);
                exit(EXIT_FAILURE);
            }
        }
    } else {
        _is_sample_begin_state=false;
    }

    // deal with vcf records which partially overlap the region of interest:
    if (_opt.is_region()) {
        if (pos()<_opt.region_begin) return false;
    }

    return true;
}
예제 #11
0
//*************************************************************
void MINDsetup::createGeom(){
//*************************************************************    
    
  _msetup.message("+++ CreatGeom function +++",bhep::VERBOSE);
  
  //----- axes for definition of volumes and surfaces ----//
  
  xaxis=EVector(3,0); xaxis[0] = 1.; 
  yaxis=EVector(3,0); yaxis[1] = 1.; 
  zaxis=EVector(3,0); zaxis[2] = 1.;
  
  //----------- Create a mandatory mother volume ---------//
  
  EVector pos(3,0); pos[2]= VERT_z/2.;
  EVector vpos(3,0); vpos[2] = -MIND_z/2.;
  /*
    Volume* mother = new Box(pos,xaxis,yaxis,
    MOTHER_x/2,MOTHER_y/2,MOTHER_z/2);
  */
  Volume* mother;
  if(OctGeom==1)
    mother = new MINDplate(pos,xaxis,yaxis,
			   MOTHER_x/2,MOTHER_y/2,MOTHER_z/2,
			   MOTHER_earw,MOTHER_earh);
  else if(OctGeom==2)
    mother = new EMINDplate(pos,xaxis,yaxis,
			    MOTHER_x/2,MOTHER_y/2,MOTHER_z/2,
			    MOTHER_earw,MOTHER_earh);

  else if(OctGeom==3)
    mother = new Box(pos, zaxis, xaxis, MOTHER_z/2., MOTHER_x/2, MOTHER_y/2);
 
  else
    mother = new Tube(pos, zaxis,MOTHER_z/2, MOTHER_x/2); 

  _msetup.message("Mother volume generated",bhep::VERBOSE);

  // add mother volume
  
  _gsetup.set_mother(mother);
   
  _msetup.message("Mother added to setup",bhep::VERBOSE);

  // Create detector volume

  const dict::Key vol_name = "Detector";
  const dict::Key vert_name = "VertDetector";
  // Volume* det = new Box(pos,xaxis,yaxis,MIND_x/2,MIND_y/2,MIND_z/2);

  Volume* det;
  Volume* vdet;
  if(OctGeom==1)
    det = new MINDplate(pos,xaxis,yaxis,MIND_x/2,MIND_y/2,MIND_z/2,
				EAR_width, EAR_height);
  else if(OctGeom==2)
    det = new EMINDplate(pos,xaxis,yaxis,
			    MIND_x/2,MIND_y/2,MIND_z/2,
			    EAR_width,EAR_height);
  else if(OctGeom==3)
    det = new Box(pos, zaxis, xaxis, MOTHER_z/2., MOTHER_x/2, MOTHER_y/2);
  else{
    det = new Tube(pos,zaxis,MIND_z/2,MIND_x/2);
    if(VERT_z > 0)
      vdet = new Box(vpos, zaxis, xaxis, VERT_z/2., VERT_x/2., VERT_y/2.);
  }
  _msetup.message("MIND volume generated",bhep::VERBOSE);
 
  // add volume
  
  _gsetup.add_volume("mother",vol_name,det);
  if(VERT_z > 0)
    _gsetup.add_volume("mother",vert_name,vdet);
  // _gsetup.set_volume_property(vol_name,"X0",X0AIR);
  //Introduce IRON scintillator sandwiches.
  // int nplanes = (int)( MIND_z / (IRON_z + nScint * SCINT_z) );
  
  // for (int iplane = 0;iplane < _npieces;iplane++) {
  
  //     add_slab(iplane, vol_name);
  
  //   }
  
  
  
}