Beispiel #1
0
/*
=================
EV_GetGunPosition

Figure out the height of the gun
=================
*/
void EV_GetGunPosition( event_args_t *args, float *pos, float *origin )
{
	int idx;
	Vector view_ofs(0, 0, 0);

	idx = args->entindex;

	view_ofs[2] = DEFAULT_VIEWHEIGHT;

	if ( EV_IsPlayer( idx ) )
	{
		// in spec mode use entity viewheigh, not own
		if ( EV_IsLocal( idx ) && !IS_FIRSTPERSON_SPEC )
		{
			// Grab predicted result for local player
			gEngfuncs.pEventAPI->EV_LocalPlayerViewheight( view_ofs );
		}
		else if ( args->ducking == 1 )
		{
			view_ofs[2] = VEC_DUCK_VIEW;
		}
	}

	VectorAdd( origin, view_ofs, pos );
}
Beispiel #2
0
void CNPC_Turret::Spawn()
{ 
	Precache( );
	SetModel( "models/turret.mdl" );
	m_iHealth 			= sk_turret_health.GetFloat();
	m_HackedGunPos		= Vector( 0, 0, 12.75 );
	m_flMaxSpin =		TURRET_MAXSPIN;

	Vector view_ofs( 0, 0, 12.75 );
	SetViewOffset( view_ofs );

	CNPC_BaseTurret::Spawn( );

	m_iRetractHeight = 16;
	m_iDeployHeight = 32;
	m_iMinPitch	= -90;
	UTIL_SetSize(this, Vector(-32, -32, -m_iRetractHeight), Vector(32, 32, m_iRetractHeight));
	
	SetThink(&CNPC_BaseTurret::Initialize);	

	m_pEyeGlow = CSprite::SpriteCreate( TURRET_GLOW_SPRITE, GetAbsOrigin(), FALSE );
	m_pEyeGlow->SetTransparency( kRenderGlow, 255, 0, 0, 0, kRenderFxNoDissipation );
	m_pEyeGlow->SetAttachment( this, 2 );

	m_eyeBrightness = 0;

	SetNextThink( gpGlobals->curtime + 0.3 ); 
}
Beispiel #3
0
void CNPC_MiniTurret::Spawn()
{ 
	Precache( );

	SetModel( "models/miniturret.mdl" );
	m_iHealth 			= sk_miniturret_health.GetFloat();
	m_HackedGunPos		= Vector( 0, 0, 12.75 );
	m_flMaxSpin = 0;

	Vector view_ofs( 0, 0, 12.75 );
	SetViewOffset( view_ofs );

	CNPC_BaseTurret::Spawn( );
	m_iRetractHeight = 16;
	m_iDeployHeight = 32;
	m_iMinPitch	= -90;
	UTIL_SetSize(this, Vector(-16, -16, -m_iRetractHeight), Vector(16, 16, m_iRetractHeight));

	SetThink(&CNPC_MiniTurret::Initialize);	
	SetNextThink(gpGlobals->curtime + 0.3); 

	if (( m_spawnflags & SF_MONSTER_TURRET_AUTOACTIVATE ) && !( m_spawnflags & SF_MONSTER_TURRET_STARTINACTIVE ))
	{
		m_iAutoStart = true;
	}
}
Beispiel #4
0
/*
=================
EV_GetDefaultShellInfo

Determine where to eject shells from
=================
*/
void EV_GetDefaultShellInfo( event_args_t *args, 
							 const Vector& origin, const Vector& velocity, 
							 Vector& ShellVelocity, Vector& ShellOrigin, 
							 const Vector& forward, const Vector& right, const Vector& up, 
							 float forwardScale, float upScale, float rightScale )
{
	int i;
	Vector view_ofs( 0 );

	float fR, fU;

	int idx;

	idx = args->entindex;

	view_ofs[2] = DEFAULT_VIEWHEIGHT;

	if ( EV_IsPlayer( idx ) )
	{
		if ( EV_IsLocal( idx ) )
		{
			gEngfuncs.pEventAPI->EV_LocalPlayerViewheight( view_ofs );
		}
		else if ( args->ducking == 1 )
		{
			view_ofs = VEC_DUCK_VIEW;
		}
	}

	fR = gEngfuncs.pfnRandomFloat( 50, 70 );
	fU = gEngfuncs.pfnRandomFloat( 100, 150 );

	for ( i = 0; i < 3; i++ )
	{
		ShellVelocity[i] = velocity[i] + right[i] * fR + up[i] * fU + forward[i] * 25;
		ShellOrigin[i]   = origin[i] + view_ofs[i] + up[i] * upScale + forward[i] * forwardScale + right[i] * rightScale;
	}
}
Beispiel #5
0
void Mfg::exportAll(string root_dir)
{
    QString qroot_dir = QString::fromStdString(root_dir);

    //======== 0. make/check directory ========
    if (!QDir(qroot_dir).exists())
        QDir().mkdir(qroot_dir);

    //======== 1. export 3D features ========
    string feat3d_fname = root_dir + "/features3d.txt";
    ofstream feat3d_ofs(feat3d_fname.c_str());

    feat3d_ofs << "keyframe_number: " << views.size() << '\n';
    feat3d_ofs << "intrinsic_camera_param: " << K.at<double>(0, 0) << '\t' << K.at<double>(0, 1) << '\t' << K.at<double>(0, 2) << '\t'
               << K.at<double>(1, 0) << '\t' << K.at<double>(1, 1) << '\t' << K.at<double>(1, 2) << '\t'
               << K.at<double>(2, 0) << '\t' << K.at<double>(2, 1) << '\t' << K.at<double>(2, 2) << '\n';

    // === point ===
    int kpNum = 0;

    for (int i = 0; i < keyPoints.size(); ++i)
    {
        if (!keyPoints[i].is3D || keyPoints[i].gid < 0) continue; // only output 3d pt

        ++kpNum;
    }

    feat3d_ofs << "3D_point_number: " << kpNum << '\t' << keyPoints.size() << '\n';
    feat3d_ofs << "#format: global_id\tx\ty\tz\tplane_id\test_view_id\tviewId_ptLid_number\tviewId_ptLid_pairs\n";

    for (int i = 0; i < keyPoints.size(); ++i)
    {
        if (!keyPoints[i].is3D || keyPoints[i].gid < 0) continue; // only output 3d pt

        feat3d_ofs << keyPoints[i].gid << '\t' << keyPoints[i].x << '\t' << keyPoints[i].y << '\t' << keyPoints[i].z << '\t'
                   << keyPoints[i].pGid << '\t' << keyPoints[i].estViewId << '\t';
        feat3d_ofs << keyPoints[i].viewId_ptLid.size() << '\t';

        for (int j = 0; j < keyPoints[i].viewId_ptLid.size(); ++j)
            feat3d_ofs << keyPoints[i].viewId_ptLid[j][0] << '\t' << keyPoints[i].viewId_ptLid[j][1] << '\t';

        feat3d_ofs << '\n';
    }

    // === lines ===
    int ilNum = 0;

    for (int i = 0; i < idealLines.size(); ++i)
    {
        if (!idealLines[i].is3D || idealLines[i].gid < 0) continue; // only output 3d pt

        ++ilNum;
    }

    feat3d_ofs << "3D_line_number: " << ilNum << '\t' << idealLines.size() << '\n';
    feat3d_ofs << "#format: global_id\tx1\ty1\tz1\tx2\ty2\tz2\tplane_id\tvp_id\test_view_id\tviewId_lnLid_number\tviewId_lnLid_pairs\n";

    for (int i = 0; i < idealLines.size(); ++i)
    {
        if (!idealLines[i].is3D || idealLines[i].gid < 0) continue; // only output 3d pt

        feat3d_ofs << idealLines[i].gid << '\t' << idealLines[i].extremity1().x << '\t' << idealLines[i].extremity1().y << '\t' << idealLines[i].extremity1().z << '\t'
                   << idealLines[i].extremity2().x << '\t' << idealLines[i].extremity2().y << '\t' << idealLines[i].extremity2().z << '\t'
                   << idealLines[i].pGid << '\t' << idealLines[i].vpGid << '\t' << idealLines[i].estViewId << '\t';
        feat3d_ofs << idealLines[i].viewId_lnLid.size() << '\t';

        for (int j = 0; j < idealLines[i].viewId_lnLid.size(); ++j)
            feat3d_ofs << idealLines[i].viewId_lnLid[j][0] << '\t' << idealLines[i].viewId_lnLid[j][1] << '\t';

        feat3d_ofs << '\n';
    }

    // === vanishing points ===
    feat3d_ofs << "3D_vanishing_point_number: " << vanishingPoints.size() << '\n';
    feat3d_ofs << "#format: global_id\tx\ty\tz\tw\test_view_id\tviewId_vpLid_number\tviewId_vpLid_pairs\n";

    for (int i = 0; i < vanishingPoints.size(); ++i)
    {
        feat3d_ofs << vanishingPoints[i].gid << '\t'
                   << vanishingPoints[i].x << '\t' << vanishingPoints[i].y << '\t' << vanishingPoints[i].z << '\t' << vanishingPoints[i].w << '\t'
                   << vanishingPoints[i].estViewId << '\t';
        feat3d_ofs << vanishingPoints[i].viewId_vpLid.size() << '\t';

        for (int j = 0; j < vanishingPoints[i].viewId_vpLid.size(); ++j)
            feat3d_ofs << vanishingPoints[i].viewId_vpLid[j][0] << '\t' << vanishingPoints[i].viewId_vpLid[j][1] << '\t';

        feat3d_ofs << '\n';
    }

    // === planes ===
    feat3d_ofs << "3D_plane_number: " << primaryPlanes.size() << '\n';
    feat3d_ofs << "#format:global_id\tnormal_vec_3d\tdepth\test_view_id\trecent_view_id\tchild_kpt_number\tchild_kpt_gids\tchild_line_number\tchild_line_gids\n";

    for (int i = 0; i < primaryPlanes.size(); ++i)
    {
        feat3d_ofs << primaryPlanes[i].gid << '\t'
                   << primaryPlanes[i].n.at<double>(0) << '\t' << primaryPlanes[i].n.at<double>(1) << '\t' << primaryPlanes[i].n.at<double>(2) << '\t'
                   << primaryPlanes[i].d << '\t' << primaryPlanes[i].estViewId << '\t' << primaryPlanes[i].recentViewId << '\t';
        feat3d_ofs << primaryPlanes[i].kptGids.size() << '\t';

        for (int j = 0; j < primaryPlanes[i].kptGids.size(); ++j) feat3d_ofs << primaryPlanes[i].kptGids[j] << '\t';

        feat3d_ofs << primaryPlanes[i].ilnGids.size() << '\t';

        for (int j = 0; j < primaryPlanes[i].ilnGids.size(); ++j) feat3d_ofs << primaryPlanes[i].ilnGids[j] << '\t';

        feat3d_ofs << '\n';
    }

    //======== 2. export views =========
    string views_dir = root_dir + "/views";
    QString qviews_dir = QString::fromStdString(views_dir);

    if (QDir(qviews_dir).exists())
        QDir(qviews_dir).removeRecursively();

    QDir().mkdir(qviews_dir);

    for (int i = 0; i < views.size(); ++i)
    {
        string view_fname = views_dir + "/view_" + num2str(i) + ".txt";
        ofstream view_ofs(view_fname.c_str());
        view_ofs << "keyframe_id:\t" << views[i].id << '\n';
        view_ofs << "rawframe_id:\t" << views[i].frameId << '\n';
        view_ofs << "image_path:\t" << views[i].filename << '\n';
        view_ofs << "rotation_mat:\t" << views[i].R.at<double>(0, 0) << '\t' << views[i].R.at<double>(0, 1) << '\t' << views[i].R.at<double>(0, 2) << '\t'
                 << views[i].R.at<double>(1, 0) << '\t' << views[i].R.at<double>(1, 1) << '\t' << views[i].R.at<double>(1, 2) << '\t'
                 << views[i].R.at<double>(2, 0) << '\t' << views[i].R.at<double>(2, 1) << '\t' << views[i].R.at<double>(2, 2) << '\n';
        view_ofs << "translation:\t" << views[i].t.at<double>(0) << '\t' << views[i].t.at<double>(1) << '\t' << views[i].t.at<double>(2) << '\n';

        // === 2d points ===
        view_ofs << "feat_pts_number: " << views[i].featurePoints.size() << '\n';
        view_ofs << "#format: local_id\tglobal_id\tx\ty\tdesc_dim\tdescriptor_vector\n";

        for (int j = 0; j < views[i].featurePoints.size(); ++j)
        {
            view_ofs << views[i].featurePoints[j].lid << '\t' << views[i].featurePoints[j].gid << '\t' << views[i].featurePoints[j].x << '\t' << views[i].featurePoints[j].y << '\t';
            int desc_dim =  views[i].featurePoints[j].siftDesc.rows * views[i].featurePoints[j].siftDesc.cols;
            view_ofs << desc_dim << '\t';

            if (views[i].featurePoints[j].siftDesc.type() == CV_32FC1)
                for (int k = 0; k < desc_dim; ++k) view_ofs << views[i].featurePoints[j].siftDesc.at<float>(k) << '\t';
            else if (views[i].featurePoints[j].siftDesc.type() == CV_64FC1)
                for (int k = 0; k < desc_dim; ++k) view_ofs << views[i].featurePoints[j].siftDesc.at<double>(k) << '\t';
            else
            {
                cout << "pt descriptor type error in exportAll\n";
                exit(0);
            }

            view_ofs << '\n';
        }

        // === line segments ===
        view_ofs << "line_segment_number: " << views[i].lineSegments.size() << '\n';
        view_ofs << "format: local_id\tx1\ty1\tx2\ty2\tvp_lid\tideal_line_lid\tgx\tgy\tdesc_dim\tmsld_desc\n";

        for (int j = 0; j < views[i].lineSegments.size(); ++j)
        {
            view_ofs << views[i].lineSegments[j].lid << '\t' << views[i].lineSegments[j].endpt1.x << '\t' << views[i].lineSegments[j].endpt1.y << '\t'
                     << views[i].lineSegments[j].endpt2.x << '\t' << views[i].lineSegments[j].endpt2.y << '\t'
                     << views[i].lineSegments[j].vpLid << '\t' << views[i].lineSegments[j].idlnLid << '\t'
                     << views[i].lineSegments[j].gradient.x << '\t' << views[i].lineSegments[j].gradient.y << '\t';
            int desc_dim = views[i].lineSegments[j].msldDesc.rows * views[i].lineSegments[j].msldDesc.cols;
            view_ofs << desc_dim << '\t';

            if (views[i].lineSegments[j].msldDesc.type() == CV_32FC1)
                for (int k = 0; k < desc_dim; ++k) view_ofs << views[i].lineSegments[j].msldDesc.at<float>(k) << '\t';
            else if (views[i].lineSegments[j].msldDesc.type() == CV_64FC1)
                for (int k = 0; k < desc_dim; ++k) view_ofs << views[i].lineSegments[j].msldDesc.at<double>(k) << '\t';
            else
            {
                cout << "line descriptor type error in exportAll\n";
                exit(0);
            }

            view_ofs << '\n';
        }

        // === ideal lines ===
        view_ofs << "ideal_line_number: " << views[i].idealLines.size() << '\n';
        view_ofs << "format: local_id\tglobal_id\tvp_lid\tplane_gid\tx1\ty1\tx2\ty2\tgx\tgy\tchild_segment_number\tchild_segment_lids\n";

        for (int j = 0; j < views[i].idealLines.size(); ++j)
        {
            view_ofs << views[i].idealLines[j].lid << '\t' << views[i].idealLines[j].gid << '\t' << views[i].idealLines[j].vpLid << '\t' << views[i].idealLines[j].pGid << '\t'
                     << views[i].idealLines[j].extremity1.x << '\t' << views[i].idealLines[j].extremity1.y << '\t' << views[i].idealLines[j].extremity2.x << '\t' << views[i].idealLines[j].extremity2.y << '\t'
                     << views[i].idealLines[j].gradient.x << '\t' << views[i].idealLines[j].gradient.y << '\t';
            view_ofs << views[i].idealLines[j].lsLids.size() << '\t';

            for (int k = 0; k < views[i].idealLines[j].lsLids.size(); ++k) view_ofs << views[i].idealLines[j].lsLids[k] << '\t';

            view_ofs << '\n';
        }

        // === vanishing points ===
        view_ofs << "vanishing_points_number: " << views[i].vanishPoints.size() << '\n';
        view_ofs << "format: local_id\tglobal_id\tx\ty\tw\tcov_2x2\tchild_iline_number\tchild_iline_lids\n";

        for (int j = 0; j < views[i].vanishPoints.size(); ++j)
        {
            view_ofs << views[i].vanishPoints[j].lid << '\t' << views[i].vanishPoints[j].gid << '\t'
                     << views[i].vanishPoints[j].x << '\t' << views[i].vanishPoints[j].y << '\t' << views[i].vanishPoints[j].w << '\t'
                     << views[i].vanishPoints[j].cov_ab.at<double>(0, 0) << '\t' << views[i].vanishPoints[j].cov_ab.at<double>(0, 1) << '\t'
                     << views[i].vanishPoints[j].cov_ab.at<double>(1, 0) << '\t' << views[i].vanishPoints[j].cov_ab.at<double>(1, 1) << '\t';
            view_ofs << views[i].vanishPoints[j].idlnLids.size() << '\t';

            for (int k = 0; k < views[i].vanishPoints[j].idlnLids.size(); ++k) view_ofs << views[i].vanishPoints[j].idlnLids[k] << '\t';

            view_ofs << '\n';
        }

        // === misc ===
        view_ofs << "angular_velocity: " << views[i].angVel << " deg_per_sec\n";
        view_ofs << "line_segment2d_len_thresh: " << views[i].lsLenThresh << '\n';
    }

    cout << "MFG exported.\n";
}