Пример #1
0
void CParticlesPlayer::StartParticles(const shared_str& particles_name, u16 bone_num, const Fmatrix& xform, u16 sender_id, int life_time, bool auto_stop)
{

    VERIFY(fis_zero(xform.c.magnitude()));
    R_ASSERT(*particles_name);

    CObject* object					= m_self_object;
    VERIFY(object);

    SBoneInfo* pBoneInfo			=  get_nearest_bone_info(smart_cast<CKinematics*>(object->Visual()),bone_num);
    if(!pBoneInfo) return;

    SParticlesInfo &particles_info	=*pBoneInfo->AppendParticles(object,particles_name);

    particles_info.sender_id		= sender_id;

    particles_info.life_time=auto_stop ? life_time : u32(-1);
    xform.getHPB(particles_info.angles);

    Fmatrix m;
    m.setHPB(particles_info.angles.x,particles_info.angles.y,particles_info.angles.z);
    GetBonePos(object,pBoneInfo->index,pBoneInfo->offset,m.c);
    particles_info.ps->UpdateParent(m,zero_vel);
    if(!particles_info.ps->IsPlaying())
        particles_info.ps->Play		();

    m_bActiveBones = true;
}
Пример #2
0
void CDrawUtilities::DrawCross(const Fvector& p, float szx1, float szy1, float szz1, float szx2, float szy2, float szz2, u32 clr, BOOL bRot45)
{
	_VertexStream*	Stream	= &RCache.Vertex;
	// actual rendering
	u32			vBase;
	FVF::L*	pv	 	= (FVF::L*)Stream->Lock(bRot45?12:6,vs_L->vb_stride,vBase);
    pv->set(p.x+szx2,p.y,p.z,clr); pv++;
    pv->set(p.x-szx1,p.y,p.z,clr); pv++;
    pv->set(p.x,p.y+szy2,p.z,clr); pv++;
    pv->set(p.x,p.y-szy1,p.z,clr); pv++;
    pv->set(p.x,p.y,p.z+szz2,clr); pv++;
    pv->set(p.x,p.y,p.z-szz1,clr); pv++;
    if (bRot45){
    	Fmatrix M;
        M.setHPB(PI_DIV_4,PI_DIV_4,PI_DIV_4);
	    for(int i=0;i<6;i++,pv++){
        	pv->p.sub((pv-6)->p,p);
        	M.transform_dir(pv->p);
        	pv->p.add(p);
            pv->color = clr;
        }
    }
	// unlock VB and Render it as triangle list
	Stream->Unlock(bRot45?12:6,vs_L->vb_stride);
    DU_DRAW_DP			(D3DPT_LINELIST,vs_L,vBase,bRot45?6:3);
}
Пример #3
0
void CDrawUtilities::DrawSpotLight(const Fvector& p, const Fvector& d, float range, float phi, u32 clr)
{
    Fmatrix T;
	Fvector p1;
    float H,P;
    float da	= PI_MUL_2/LINE_DIVISION;
	float b		= range*_cos(PI_DIV_2-phi/2);
	float a		= range*_sin(PI_DIV_2-phi/2);
    d.getHP		(H,P);
    T.setHPB	(H,P,0);     
    T.translate_over(p);
    _VertexStream*	Stream	= &RCache.Vertex;
    u32				vBase;
    FVF::L*	pv	 	= (FVF::L*)Stream->Lock(LINE_DIVISION*2+2,vs_L->vb_stride,vBase);
	for (float angle=0; angle<PI_MUL_2; angle+=da){
        float _sa	=_sin(angle);
        float _ca	=_cos(angle);
		p1.x		= b * _ca;
		p1.y		= b * _sa;
        p1.z		= a;
        T.transform_tiny(p1);
        // fill VB
        pv->set		(p,clr); pv++;
        pv->set		(p1,clr); pv++;
    }
    p1.mad			(p,d,range);
    pv->set			(p,clr); pv++;
    pv->set			(p1,clr); pv++;
    Stream->Unlock	(LINE_DIVISION*2+2,vs_L->vb_stride);
    // and Render it as triangle list
    DU_DRAW_DP		(D3DPT_LINELIST,vs_L,vBase,LINE_DIVISION+1);
}
Пример #4
0
void CDrawUtilities::DrawPlane  (const Fvector& center, const Fvector2& scale, const Fvector& rotate, u32 clr_s, u32 clr_w, BOOL bCull, BOOL bSolid, BOOL bWire)
{
    Fmatrix M;
    M.setHPB		(rotate.y,rotate.x,rotate.z);
    M.translate_over(center);
	// fill VB
	_VertexStream*	Stream	= &RCache.Vertex;
	u32			vBase;
    
    if (bSolid){
	    DU_DRAW_SH(dxRenderDeviceRender::Instance().m_SelectionShader);
        FVF::L*	pv	 = (FVF::L*)Stream->Lock(5,vs_L->vb_stride,vBase);
        pv->set		(-scale.x, 0, -scale.y, clr_s); M.transform_tiny(pv->p); pv++;
        pv->set		(-scale.x, 0, +scale.y, clr_s); M.transform_tiny(pv->p); pv++;
        pv->set		(+scale.x, 0, +scale.y, clr_s); M.transform_tiny(pv->p); pv++;
        pv->set		(+scale.x, 0, -scale.y, clr_s); M.transform_tiny(pv->p); pv++;
        pv->set		(*(pv-4));
        Stream->Unlock(5,vs_L->vb_stride);
        if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_NONE);
        DU_DRAW_DP		(D3DPT_TRIANGLEFAN,vs_L,vBase,2);
        if (!bCull) DU_DRAW_RS(D3DRS_CULLMODE,D3DCULL_CCW);
    }

    if (bWire){
	    DU_DRAW_SH(dxRenderDeviceRender::Instance().m_WireShader);
        FVF::L*	pv	 = (FVF::L*)Stream->Lock(5,vs_L->vb_stride,vBase);
        pv->set		(-scale.x, 0, -scale.y, clr_w); M.transform_tiny(pv->p); pv++;
        pv->set		(+scale.x, 0, -scale.y, clr_w); M.transform_tiny(pv->p); pv++;
        pv->set		(+scale.x, 0, +scale.y, clr_w); M.transform_tiny(pv->p); pv++;
        pv->set		(-scale.x, 0, +scale.y, clr_w); M.transform_tiny(pv->p); pv++;
        pv->set		(*(pv-4));
        Stream->Unlock(5,vs_L->vb_stride);
	    DU_DRAW_DP	(D3DPT_LINESTRIP,vs_L,vBase,4);
    }
}
Пример #5
0
void CCameraLook::Update(Fvector& point, Fvector& /**noise_dangle/**/)
{
	vPosition.set		(point);
	Fmatrix mR;
	mR.setHPB			(-yaw,-pitch,-roll);

	vDirection.set		(mR.k);
	vNormal.set			(mR.j);

	if (m_Flags.is(flRelativeLink)){
		parent->XFORM().transform_dir(vDirection);
		parent->XFORM().transform_dir(vNormal);
	}
	Fvector				vDir;
	collide::rq_result	R;

	float				covariance = VIEWPORT_NEAR*6.f;
	vDir.invert			(vDirection);
	g_pGameLevel->ObjectSpace.RayPick( point, vDir, dist+covariance, collide::rqtBoth, R, parent);

	float d				= psCamSlideInert*prev_d+(1.f-psCamSlideInert)*(R.range-covariance);
	prev_d = d;
	
	vPosition.mul		(vDirection,-d-VIEWPORT_NEAR);
	vPosition.add		(point);

}
Пример #6
0
void  CAI_Boar::BoneCallback(CBoneInstance *B)
{
	CAI_Boar	*P = static_cast<CAI_Boar*>(B->Callback_Param);

	if (!P->look_at_enemy) return;
	
	Fmatrix M;
	M.setHPB (0.0f,-P->_cur_delta,0.0f);
	B->mTransform.mulB_43(M);
}
Пример #7
0
void CCameraLook2::Update(Fvector& point, Fvector&)
{
	if(!m_locked_enemy)
	{//autoaim
		if( pInput->iGetAsyncKeyState(cam_dik) )
		{
			const CVisualMemoryManager::VISIBLES& vVisibles = Actor()->memory().visual().objects();
			CVisualMemoryManager::VISIBLES::const_iterator v_it = vVisibles.begin();
			float _nearest_dst	= flt_max;

			for (; v_it!=vVisibles.end(); ++v_it)
			{
				const CObject*	_object_			= (*v_it).m_object;
				if (!Actor()->memory().visual().visible_now(smart_cast<const CGameObject*>(_object_)))	continue;

				CObject* object_ = const_cast<CObject*>(_object_);
				

				CEntityAlive*	EA					= smart_cast<CEntityAlive*>(object_);
				if(!EA || !EA->g_Alive())			continue;
				
				float d = object_->Position().distance_to_xz(Actor()->Position());
				if( !m_locked_enemy || d<_nearest_dst)
				{
					m_locked_enemy	= object_;
					_nearest_dst	= d;
				}
			}
//.			if(m_locked_enemy) Msg("enemy is %s", *m_locked_enemy->cNameSect() );
		}
	}else
	{
		if( !pInput->iGetAsyncKeyState(cam_dik) ){
			m_locked_enemy	= NULL;
//.			Msg				("enemy is NILL");
		}
	}

	if(m_locked_enemy)
		UpdateAutoAim	();


	Fmatrix mR;
	mR.setHPB						(-yaw,-pitch,-roll);

	vDirection.set					(mR.k);
	vNormal.set						(mR.j);

	Fmatrix							a_xform;
	a_xform.setXYZ					(0, -yaw, 0);
	a_xform.translate_over			(point);
	Fvector _off					= m_cam_offset;
	a_xform.transform_tiny			(_off);
	vPosition.set					(_off);
}
Пример #8
0
void  CActor::VehicleHeadCallback(CBoneInstance* B)
{
	CActor*	A			= static_cast<CActor*>(B->Callback_Param);	VERIFY	(A);
	Fmatrix				spin;
	float				bone_yaw	= angle_normalize_signed(A->r_torso.yaw)*0.75f;
	float				bone_pitch	= angle_normalize_signed(A->r_torso.pitch)*0.75f;
	float				bone_roll	= angle_normalize_signed(A->r_torso.roll)*r_head_factor;
	Fvector c			= B->mTransform.c;
	spin.setHPB			(bone_yaw,bone_pitch,-bone_roll);
	B->mTransform.mulA_43(spin);
	B->mTransform.c		= c;
}
Пример #9
0
void bonesBone::Apply()
{
	float x = 0.f, y = 0.f, z = 0.f;

	if ((axis & AXIS_X) == AXIS_X) x = params.cur_yaw;
	if ((axis & AXIS_Y) == AXIS_Y) y = params.cur_yaw;
	if ((axis & AXIS_Z) == AXIS_Z) z = params.cur_yaw;

	// создать матрицу вращения и умножить на mTransform боны
	Fmatrix M;
	M.setHPB (-y, -x, -z);
	bone->mTransform.mulB_43	(M);
}
Пример #10
0
void CAI_Trader::LookAtActor(CBoneInstance *B)
{
	Fvector dir;
	dir.sub(Level().CurrentEntity()->Position(),Position());

	float yaw,pitch;
	dir.getHP(yaw, pitch);

	float h,p,b;
	XFORM().getHPB(h,p,b);
	float cur_yaw	= h;
	float dy		= _abs(angle_normalize_signed(yaw - cur_yaw));

	if (angle_normalize_signed(yaw - cur_yaw) > 0) dy *= -1.f;

	Fmatrix M;
	M.setHPB (0.f, -dy, 0.f);
	B->mTransform.mulB_43(M);
}
Пример #11
0
void CParticlesPlayer::UpdateParticles()
{
    if	(!m_bActiveBones)	return;
    m_bActiveBones			= false;

    CObject* object			= m_self_object;
    VERIFY	(object);

    for(BoneInfoVecIt b_it=m_Bones.begin(); b_it!=m_Bones.end(); b_it++) {
        SBoneInfo& b_info	= *b_it;

        for (ParticlesInfoListIt p_it=b_info.particles.begin(); p_it!=b_info.particles.end(); p_it++) {
            SParticlesInfo& p_info	= *p_it;
            if(!p_info.ps) continue;
            //обновить позицию партиклов
            Fmatrix xform;
            xform.setHPB(p_info.angles.x,p_info.angles.y,p_info.angles.z);
            GetBonePos(object,b_info.index,b_info.offset,xform.c);
            p_info.ps->UpdateParent(xform, parent_vel);

            //обновить время существования
            if(p_info.life_time!=u32(-1))
            {
                if(p_info.life_time>Device.dwTimeDelta)	p_info.life_time-=Device.dwTimeDelta;
                else
                {
                    p_info.ps->Stop();
                    p_info.life_time=u32(-1);
                }
            }
            if(!p_info.ps->IsPlaying()) {
                CParticlesObject::Destroy(p_info.ps);
            }
            else
                m_bActiveBones  = true;
        }

        ParticlesInfoListIt RI=std::remove_if(b_info.particles.begin(),b_info.particles.end(),SRP());
        b_info.particles.erase(RI,b_info.particles.end());
    }
}
Пример #12
0
BOOL CMonsterEffectorHit::ProcessCam(SCamEffectorInfo& info)
{
    fLifeTime -= Device.fTimeDelta;
    if(fLifeTime<0) return FALSE;

    // процент оставшегос¤ времени
    float time_left_perc = fLifeTime / total;

    // »нициализаци¤
    Fmatrix	Mdef;
    Mdef.identity		();
    Mdef.j.set			(info.n);
    Mdef.k.set			(info.d);
    Mdef.i.crossproduct	(info.n,info.d);
    Mdef.c.set			(info.p);

    float period_all	= period_number * PI_MUL_2;		// макс. значение цикла
    float cur_amp		= max_amp * (PI / 180) * time_left_perc;


    Fvector dangle;
    dangle.x = cur_amp/offset.x	* _sin(period_all/offset.x	* (1.0f - time_left_perc));
    dangle.y = cur_amp/offset.y	* _cos(period_all/offset.y	* (1.0f - time_left_perc));
    dangle.z = cur_amp/offset.z	* _sin(period_all/offset.z	* (1.0f - time_left_perc));

    // ”становить углы смещени¤
    Fmatrix			R;
    R.setHPB		(dangle.x,dangle.y,dangle.z);

    Fmatrix			mR;
    mR.mul			(Mdef,R);

    info.d.set		(mR.k);
    info.n.set		(mR.j);

    return TRUE;
}
BOOL CPseudogigantStepEffector::Process(Fvector &p, Fvector &d, Fvector &n, float& fFov, float& fFar, float& fAspect)
{
	fLifeTime -= Device.fTimeDelta; if(fLifeTime<0) return FALSE;

	// процент оставшегос¤ времени
	float time_left_perc = fLifeTime / total;

	// »нициализаци¤
	Fmatrix	Mdef;
	Mdef.identity		();
	Mdef.j.set			(n);
	Mdef.k.set			(d);
	Mdef.i.crossproduct	(n,d);
	Mdef.c.set			(p);

	float period_all	= period_number * PI_MUL_2;		// макс. значение цикла
	float k				= 1 - time_left_perc + EPS_L + (1 - power);
	float cur_amp		= max_amp * (PI / 180) / (10 * k * k);

	Fvector dangle; 
	dangle.x = cur_amp/2	* _sin(period_all	* (1.0f - time_left_perc));
	dangle.y = cur_amp		* _cos(period_all/2 * (1.0f - time_left_perc));
	dangle.z = cur_amp/4	* _sin(period_all/4	* (1.0f - time_left_perc));

	// ”становить углы смещени¤
	Fmatrix		R;
	R.setHPB	(dangle.x,dangle.y,dangle.z);

	Fmatrix		mR;
	mR.mul		(Mdef,R);

	d.set		(mR.k);
	n.set		(mR.j);

	return TRUE;
}
Пример #14
0
BOOL CAlienEffector::ProcessCam(SCamEffectorInfo& info)
{
	// »нициализаци¤
	Fmatrix	Mdef;
	Mdef.identity		();
	Mdef.j.set			(info.n);
	Mdef.k.set			(info.d);
	Mdef.i.crossproduct	(info.n, info.d);
	Mdef.c.set			(info.p);


	// set angle 
	if (angle_lerp(dangle_current.x, dangle_target.x, ANGLE_SPEED, Device.fTimeDelta)) {
		dangle_target.x = angle_normalize(Random.randFs(DELTA_ANGLE_X));
	}

	if (angle_lerp(dangle_current.y, dangle_target.y, ANGLE_SPEED, Device.fTimeDelta)) {
		dangle_target.y = angle_normalize(Random.randFs(DELTA_ANGLE_Y));
	}

	if (angle_lerp(dangle_current.z, dangle_target.z, ANGLE_SPEED, Device.fTimeDelta)) {
		dangle_target.z = angle_normalize(Random.randFs(DELTA_ANGLE_Z));
	}

	// update inertion
	Fmatrix cur_matrix;
	cur_matrix.k = monster->Direction();
	cur_matrix.c = get_head_position(monster);

	float	rel_dist = m_prev_eye_matrix.c.distance_to(cur_matrix.c) / MAX_CAMERA_DIST;
	clamp	(rel_dist, 0.f, 1.f);

	def_lerp(m_inertion, 1 - rel_dist, rel_dist, Device.fTimeDelta);

	// set pos and dir with inertion
	m_prev_eye_matrix.c.inertion(cur_matrix.c, m_inertion);
	m_prev_eye_matrix.k.inertion(cur_matrix.k, m_inertion);
	Fvector::generate_orthonormal_basis_normalized(m_prev_eye_matrix.k,m_prev_eye_matrix.j,m_prev_eye_matrix.i);	

	// apply position and direction
	Mdef = m_prev_eye_matrix;

	//set fov
	float	rel_speed = monster->m_fCurSpeed / 15.f;
	clamp	(rel_speed,0.f,1.f);

	float	m_target_fov = MIN_FOV + (MAX_FOV-MIN_FOV) * rel_speed;
	def_lerp(m_current_fov, m_target_fov, FOV_SPEED, Device.fTimeDelta);
	
	info.fFov = m_current_fov;
	//////////////////////////////////////////////////////////////////////////

	// ”становить углы смещени¤
	Fmatrix		R;
	R.setHPB	(dangle_current.x,dangle_current.y,dangle_current.z);

	Fmatrix		mR;
	mR.mul		(Mdef,R);

	info.d.set		(mR.k);
	info.n.set		(mR.j);
	info.p.set		(mR.c);

	return TRUE;
}
Пример #15
0
BOOL CEffectorBobbing::Process		(Fvector &p, Fvector &d, Fvector &n, float& /**fFov/**/, float& /**fFar/**/, float& /**fAspect/**/)
{
	fTime			+= Device.fTimeDelta;
	if (dwMState&ACTOR_DEFS::mcAnyMove){
		if (fReminderFactor<1.f)	fReminderFactor += SPEED_REMINDER*Device.fTimeDelta;
		else						fReminderFactor = 1.f;
	}else{
		if (fReminderFactor>0.f)	fReminderFactor -= SPEED_REMINDER*Device.fTimeDelta;
		else						fReminderFactor = 0.f;
	}
	if (!fsimilar(fReminderFactor,0)){
		Fmatrix		M;
		M.identity	();
		M.j.set		(n);
		M.k.set		(d);
		M.i.crossproduct(n,d);
		M.c.set		(p);
		
		// apply footstep bobbing effect
		Fvector dangle;
		float k		= ((dwMState& ACTOR_DEFS::mcCrouch)?CROUCH_FACTOR:1.f);

		float A, ST;

		if(isActorAccelerated(dwMState, m_bZoomMode))
		{
			A	= m_fAmplitudeRun*k;
			ST	= m_fSpeedRun*fTime*k;
		}
		else if(is_limping)
		{
			A	= m_fAmplitudeLimp*k;
			ST	= m_fSpeedLimp*fTime*k;
		}
		else
		{
			A	= m_fAmplitudeWalk*k;
			ST	= m_fSpeedWalk*fTime*k;
		}
	
		float _sinA	= _abs(_sin(ST)*A)*fReminderFactor;
		float _cosA	= _cos(ST)*A*fReminderFactor;

		p.y			+=	_sinA;
		dangle.x	=	_cosA;
		dangle.z	=	_cosA;
		dangle.y	=	_sinA;

		Fmatrix		R;
		R.setHPB	(dangle.x,dangle.y,dangle.z);

		Fmatrix		mR;
		mR.mul		(M,R);
		
		d.set		(mR.k);
		n.set		(mR.j);
	}
//	else{
//		fTime		= 0;
//	}
	return TRUE;
}