コード例 #1
0
ファイル: TLSPRITE.CPP プロジェクト: 2asoft/xray
void CTLSprite::Render(Fvector &pos, u32 color, float radius, float angle)
{
	FVF::TL			P;

	P.transform     (pos, Device.mFullTransform);
    if (P.p.w<=0) 	return;

	float cx		= Device._x2real(P.p.x);
	float cy		= Device._y2real(P.p.y);

	float sz		= (UI->GetRenderWidth()*radius)/P.p.w;
	if (sz<1.5f) 	return;

	// Rotation
	float			_sin1=_sin(angle),_cos1=_cos(angle);
    float			_sin2=_sin(angle+PI_DIV_2),_cos2=_cos(angle+PI_DIV_2);

	mesh.m[0].p.x = cx+sz*_sin1;	mesh.m[0].p.y = cy+sz*_cos1;
	mesh.m[1].p.x = cx-sz*_sin2;	mesh.m[1].p.y = cy-sz*_cos2;
	mesh.m[2].p.x = cx+sz*_sin2;	mesh.m[2].p.y = cy+sz*_cos2;
	mesh.m[3].p.x = cx-sz*_sin1;	mesh.m[3].p.y = cy-sz*_cos1;

	mesh.setdepth	(P.p.z, P.p.w);
	mesh.setcolor	(color);

    DU_impl.DrawPrimitiveTL(D3DPT_TRIANGLESTRIP,2,(FVF::TL*)&mesh,4,false,false);
}
コード例 #2
0
ファイル: D3DUtils.cpp プロジェクト: galek/xray
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);
}
コード例 #3
0
void CDetailManager::hw_Render()
{
	// Render-prepare
	Fvector4	dir1,dir2;
	float		tm_rot1		= (PI_MUL_2*Device.fTimeGlobal/swing_current.rot1);
	float		tm_rot2		= (PI_MUL_2*Device.fTimeGlobal/swing_current.rot2);
	dir1.set				(_sin(tm_rot1),0,_cos(tm_rot1),0).normalize().mul(swing_current.amp1);
	dir2.set				(_sin(tm_rot2),0,_cos(tm_rot2),0).normalize().mul(swing_current.amp2);

	// Setup geometry and DMA
	RCache.set_Geometry		(hw_Geom);

	// Wave0
	float		scale			=	1.f/float(quant);
	Fvector4	wave;
	wave.set				(1.f/5.f,		1.f/7.f,	1.f/3.f,	Device.fTimeGlobal*swing_current.speed);
	RCache.set_c			(&*hwc_consts,	scale,		scale,		ps_r__Detail_l_aniso,	ps_r__Detail_l_ambient);				// consts
	RCache.set_c			(&*hwc_wave,	wave.div(PI_MUL_2));	// wave
	RCache.set_c			(&*hwc_wind,	dir1);																					// wind-dir
	hw_Render_dump			(&*hwc_array,	1, 0, c_hdr );

	// Wave1
	wave.set				(1.f/3.f,		1.f/7.f,	1.f/5.f,	Device.fTimeGlobal*swing_current.speed);
	RCache.set_c			(&*hwc_wave,	wave.div(PI_MUL_2));	// wave
	RCache.set_c			(&*hwc_wind,	dir2);																					// wind-dir
	hw_Render_dump			(&*hwc_array,	2, 0, c_hdr );

	// Still
	RCache.set_c			(&*hwc_s_consts,scale,		scale,		scale,				1.f);
	RCache.set_c			(&*hwc_s_xform,	Device.mFullTransform);
	hw_Render_dump			(&*hwc_s_array,	0, 1, c_hdr );
}
コード例 #4
0
ファイル: flesh.cpp プロジェクト: OLR-xray/OLR-3.0
////////////////////////////////////////////////////////////////////////////////////////////////
// Функция ConeSphereIntersection
// Пересечение конуса (не ограниченного) со сферой
// Необходима для определения пересечения копыта плоти с баунд-сферой крысы
// Параметры: ConeVertex - вершина конуса, ConeAngle - угол конуса (между поверхностью и высотой)
// ConeDir - направление конуса, SphereCenter - центр сферы, SphereRadius - радиус сферы
bool CAI_Flesh::ConeSphereIntersection(Fvector ConeVertex, float ConeAngle, Fvector ConeDir, Fvector SphereCenter, float SphereRadius)
{
	float fInvSin = 1.0f/_sin(ConeAngle);
	float fCosSqr = _cos(ConeAngle)*_cos(ConeAngle);

	
	Fvector kCmV;	kCmV.sub(SphereCenter,ConeVertex);
	Fvector kD		= kCmV;
	Fvector tempV	= ConeDir;
	tempV.mul		(SphereRadius* fInvSin);
	kD.add			(tempV);

	float fDSqrLen = kD.square_magnitude();
	float fE = kD.dotproduct(ConeDir);
	if ( fE > 0.0f && fE*fE >= fDSqrLen*fCosSqr ) {
		
		float fSinSqr = _sin(ConeAngle)*_sin(ConeAngle);

		fDSqrLen = kCmV.square_magnitude();
		fE = -kCmV.dotproduct(ConeDir);
		if ( fE > 0.0f && fE*fE >= fDSqrLen*fSinSqr ) {
			float fRSqr = SphereRadius*SphereRadius;
			return fDSqrLen <= fRSqr;
		} else return true;
	} 
	
	return false;
}
コード例 #5
0
	void		calculate	()
	{
		dwFrame					= Device.dwFrame;

		// Calc wind-vector3, scale
		float	tm_rot			= PI_MUL_2*Device.fTimeGlobal/ps_r__Tree_w_rot;
		//wind.set				(_sin(tm_rot),0,_cos(tm_rot),0);	wind.normalize	();	wind.mul(ps_r__Tree_w_amp);	// dir1*amplitude

#ifdef TREE_WIND_EFFECT
		CEnvDescriptor&	E = *g_pGamePersistent->Environment().CurrentEnv;
		float fValue = E.m_fTreeAmplitudeIntensity;
		wind.set(_sin(tm_rot), 0, _cos(tm_rot), 0);
		wind.normalize();
#if RENDER!=R_R1
		wind.mul(fValue);	// dir1*amplitude
#else // R1
		wind.mul(ps_r__Tree_w_amp);	// dir1*amplitude
#endif //-RENDER!=R_R1
#else //!TREE_WIND_EFFECT
		wind.set(_sin(tm_rot), 0, _cos(tm_rot), 0);	wind.normalize();	wind.mul(ps_r__Tree_w_amp);	// dir1*amplitude
#endif //-TREE_WIND_EFFECT

		scale					= 1.f/float(FTreeVisual_quant);

		// setup constants
		wave.set				(ps_r__Tree_Wave.x,	ps_r__Tree_Wave.y,	ps_r__Tree_Wave.z,	Device.fTimeGlobal*ps_r__Tree_w_speed);			// wave
		wave.div				(PI_MUL_2);
	}
コード例 #6
0
ファイル: gps_math.c プロジェクト: pelrun/CHDK
double cos (double phi) {
	long periode = floor (phi / PIBY2 + 0.125);
	double reduced = phi - PIBY2 * periode;
	switch (periode&3) {
	default:
		return _cos (reduced);
	case 1:
		return -_sin (reduced);
	case 2:
		return -_cos (reduced);
	case 3:
		return _sin (reduced);
	}
}
コード例 #7
0
ファイル: UIMap.cpp プロジェクト: OLR-xray/OLR-3.0
void rotation_(float x, float y, const float angle, float& x_, float& y_)
{
	float _sc = _cos(angle);
	float _sn = _sin(angle);
	x_= x*_sc+y*_sn;
	y_= y*_sc-x*_sn;
}
コード例 #8
0
ファイル: math3d.cpp プロジェクト: vasilenkomike/xray
//
// Generate the derivative of a rotation matrix about a principal axis
//
void rotation_principal_axis_to_deriv_matrix(char axis, float angle, Matrix m)
{
    float cos_a, sin_a;

    ZeroMemory(m,sizeof(Matrix));
    cos_a = _cos(angle);
    sin_a = _sin(angle);

    switch (axis)
    {
    case 'x':
    case 'X':
        m[1][1] = -sin_a;
        m[2][1] = -cos_a;
        m[1][2] = cos_a;
        m[2][2] = -sin_a;
        break;

    case 'y':
    case 'Y':
        m[0][0] = -sin_a;
        m[2][0] = cos_a;
        m[0][2] = -cos_a;
        m[2][2] = -sin_a;
        break;

    default:
        m[0][0] = -sin_a;
        m[1][0] = -cos_a;
        m[0][1] = cos_a;
        m[1][1] = -sin_a;
        break;
    }
}
コード例 #9
0
ファイル: math3d.cpp プロジェクト: vasilenkomike/xray
void rotation_principal_axis_to_matrix(char axis, float angle, Matrix m)
{
    float cos_a, sin_a;

    cpmatrix(m, idmat);
    cos_a = _cos(angle);
    sin_a = _sin(angle);

    switch (axis)
    {
    case 'x':
    case 'X':
        m[1][1] = cos_a;
        m[2][1] = -sin_a;
        m[1][2] = sin_a;
        m[2][2] = cos_a;
        break;

    case 'y':
    case 'Y':
        m[0][0] = cos_a;
        m[2][0] = sin_a;
        m[0][2] = -sin_a;
        m[2][2] = cos_a;
        break;

    default:
        m[0][0] = cos_a;
        m[1][0] = -sin_a;
        m[0][1] = sin_a;
        m[1][1] = cos_a;
        break;
    }
}
コード例 #10
0
ファイル: math3d.cpp プロジェクト: vasilenkomike/xray
//
// Construct a general rotation matrix given an angle and axis
//
void rotation_axis_to_matrix(float axis[3], float angle, Matrix R)
{
    float cos_a, sin_a;
    float s1, s2, s3;

    cos_a = _cos(angle);
    sin_a = _sin(angle);

    // Assume axis is normalized

#if 0
    // float normal[3];
    // cpvector(normal,axis);
    // unitize(normal);

    // s1 = normal[0];
    // s2 = normal[1];
    // s3 = normal[2];
#else

    s1 = axis[0];
    s2 = axis[1];
    s3 = axis[2];

#endif
    float s1s1 = s1*s1;
    float s1s2 = s1*s2;
    float s1s3 = s1*s3;
    float s2s2 = s2*s2;
    float s2s3 = s2*s3;
    float s3s3 = s3*s3;
    float cos_as1s2 = cos_a * s1s2;
    float cos_as1s3 = cos_a * s1s3;
    float cos_as2s3 = cos_a * s2s3;
    float s1sin_a = s1*sin_a;
    float s2sin_a = s2*sin_a;
    float s3sin_a = s3*sin_a;
    float *r = (float *)R;

    *r++ = s1s1 + cos_a * (1 - s1s1);
    *r++ = s1s2 - cos_as1s2 + s3sin_a;
    *r++ = s1s3 - cos_as1s3 - s2sin_a;
    *r++ = 0;

    *r++ = s1s2 - cos_as1s2 - s3sin_a;
    *r++ = s2s2 + cos_a * (1 - s2s2);
    *r++ = s2s3 - cos_as2s3 + s1sin_a;
    *r++ = 0;

    *r++ = s1s3 - cos_as1s3 + s2sin_a;
    *r++ = s2s3 - cos_as2s3 - s1sin_a;
    *r++ = s3s3 + cos_a * (1 - s3s3);
    *r++ = 0;

    *r++ = 0;
    *r++ = 0;
    *r++ = 0;
    *r = 1;

}
コード例 #11
0
ファイル: eina_matrix.c プロジェクト: FlorentRevest/EFL
EAPI void
eina_matrix3_rotate(Eina_Matrix3 *m, double rad)
{
   double c, s;
#if 0
   c = cosf(rad);
   s = sinf(rad);
#else
   /* normalize the angle between -pi,pi */
   rad = fmod(rad + M_PI, 2 * M_PI) - M_PI;
   c = _cos(rad);
   s = _sin(rad);
#endif

   Eina_Matrix3 tmp;
   MATRIX_XX(&tmp) = c;
   MATRIX_XY(&tmp) = -s;
   MATRIX_XZ(&tmp) = 0;
   MATRIX_YX(&tmp) = s;
   MATRIX_YY(&tmp) = c;
   MATRIX_YZ(&tmp) = 0;
   MATRIX_ZX(&tmp) = 0;
   MATRIX_ZY(&tmp) = 0;
   MATRIX_ZZ(&tmp) = 1;
   eina_matrix3_compose(m, &tmp, m);
}
コード例 #12
0
ファイル: DetailManager_VS.cpp プロジェクト: 2asoft/xray-16
void CDetailManager::hw_Render()
{
	// Render-prepare
	//	Update timer
	//	Can't use RDEVICE.fTimeDelta since it is smoothed! Don't know why, but smoothed value looks more choppy!
	float fDelta = RDEVICE.fTimeGlobal-m_global_time_old;
	if ( (fDelta<0) || (fDelta>1))	fDelta = 0.03;
	m_global_time_old = RDEVICE.fTimeGlobal;

	m_time_rot_1	+= (PI_MUL_2*fDelta/swing_current.rot1);
	m_time_rot_2	+= (PI_MUL_2*fDelta/swing_current.rot2);
	m_time_pos		+= fDelta*swing_current.speed;

	//float		tm_rot1		= (PI_MUL_2*RDEVICE.fTimeGlobal/swing_current.rot1);
	//float		tm_rot2		= (PI_MUL_2*RDEVICE.fTimeGlobal/swing_current.rot2);
	float		tm_rot1		= m_time_rot_1;
	float		tm_rot2		= m_time_rot_2;

	Fvector4	dir1,dir2;
	dir1.set				(_sin(tm_rot1),0,_cos(tm_rot1),0).normalize().mul(swing_current.amp1);
	dir2.set				(_sin(tm_rot2),0,_cos(tm_rot2),0).normalize().mul(swing_current.amp2);

	// Setup geometry and DMA
	RCache.set_Geometry		(hw_Geom);

	// Wave0
	float		scale			=	1.f/float(quant);
	Fvector4	wave;
	//wave.set				(1.f/5.f,		1.f/7.f,	1.f/3.f,	RDEVICE.fTimeGlobal*swing_current.speed);
	wave.set				(1.f/5.f,		1.f/7.f,	1.f/3.f,	m_time_pos);
	RCache.set_c			(&*hwc_consts,	scale,		scale,		ps_r__Detail_l_aniso,	ps_r__Detail_l_ambient);				// consts
	RCache.set_c			(&*hwc_wave,	wave.div(PI_MUL_2));	// wave
	RCache.set_c			(&*hwc_wind,	dir1);																					// wind-dir
	hw_Render_dump			(&*hwc_array,	1, 0, c_hdr );

	// Wave1
	//wave.set				(1.f/3.f,		1.f/7.f,	1.f/5.f,	RDEVICE.fTimeGlobal*swing_current.speed);
	wave.set				(1.f/3.f,		1.f/7.f,	1.f/5.f,	m_time_pos);
	RCache.set_c			(&*hwc_wave,	wave.div(PI_MUL_2));	// wave
	RCache.set_c			(&*hwc_wind,	dir2);																					// wind-dir
	hw_Render_dump			(&*hwc_array,	2, 0, c_hdr );

	// Still
	RCache.set_c			(&*hwc_s_consts,scale,		scale,		scale,				1.f);
	RCache.set_c			(&*hwc_s_xform,	RDEVICE.mFullTransform);
	hw_Render_dump			(&*hwc_s_array,	0, 1, c_hdr );
}
コード例 #13
0
float get_circle_equation(const float ee[3], 
			  const float axis[3],
			  const float pos_axis[3],
			  float upper_len,
			  float lower_len,
			  float c[3],
			  float u[3],
			  float v[3],
			  float n[3])
{
    float wn = norm((float *)ee);
    float radius;

    cpvector(n, ee);
    unitize(n);

    
    // Use law of cosines to get angle between first spherical joint
    // and revolute joint

    float alpha; 

    if (!law_of_cosines(wn, upper_len, lower_len, alpha))
	return 0;

    // center of circle (origin is location of first S joint)
    vecscalarmult(c, n, _cos(alpha) * upper_len);

    
    radius = _sin(alpha) * upper_len;

    float temp[3];

    //
    // A little kludgy. If the goal is behind the joint instead
    // of in front of it, we reverse the angle measurement by
    // inverting the normal vector
    //

    if (DOT(n,pos_axis) < 0.0)
	vecscalarmult(n,n,-1.0);

    vecscalarmult(temp, n, DOT(axis,n));
    vecsub(u, (float *)axis, temp);
    unitize(u);

    crossproduct(v, n, u);
#if 0
    printf("Circle equation\n");
    printf("c = [%lf,%lf,%lf]\n", c[0], c[1], c[2]);
    printf("u = [%lf,%lf,%lf]\n", u[0], u[1], u[2]);
    printf("v = [%lf,%lf,%lf]\n", v[0], v[1], v[2]);
    printf("n = [%lf,%lf,%lf]\n", n[0], n[1], n[2]);
    printf("r = %lf\n", radius);
#endif
    return radius;
}
コード例 #14
0
ファイル: math3d.cpp プロジェクト: vasilenkomike/xray
void
axistoq(Quaternion q,float angle,float axis[])
{
    float    f;

    f = (float)_sin(angle/2);
    q[0] = (float)_cos(angle/2);
    q[1] = axis[0] * f;
    q[2] = axis[1] * f;
    q[3] = axis[2] * f;
}
コード例 #15
0
ファイル: D3DUtils.cpp プロジェクト: galek/xray
void CDrawUtilities::DrawFlag(const Fvector& p, float heading, float height, float sz, float sz_fl, u32 clr, BOOL bDrawEntity){
	// fill VB
	_VertexStream*	Stream	= &RCache.Vertex;
	u32			vBase;
	FVF::L*	pv	 	= (FVF::L*)Stream->Lock(2,vs_L->vb_stride,vBase);
    pv->set			(p,clr); pv++;
    pv->set			(p.x,p.y+height,p.z,clr); pv++;
	Stream->Unlock	(2,vs_L->vb_stride);
	// and Render it as triangle list
    DU_DRAW_DP		(D3DPT_LINELIST,vs_L,vBase,1);

    if (bDrawEntity){
		// fill VB
        float rx		= _sin(heading);
        float rz		= _cos(heading);
		FVF::L*	pv	 	= (FVF::L*)Stream->Lock(6,vs_L->vb_stride,vBase);
        sz				*= 0.8f;
        pv->set			(p.x,p.y+height,p.z,clr);											pv++;
        pv->set			(p.x+rx*sz,p.y+height,p.z+rz*sz,clr);                               pv++;
        sz				*= 0.5f;
        pv->set			(p.x,p.y+height*(1.f-sz_fl*.5f),p.z,clr);                           pv++;
        pv->set			(p.x+rx*sz*0.6f,p.y+height*(1.f-sz_fl*.5f),p.z+rz*sz*0.75f,clr);   	pv++;
        pv->set			(p.x,p.y+height*(1.f-sz_fl),p.z,clr);                               pv++;
        pv->set			(p.x+rx*sz,p.y+height*(1.f-sz_fl),p.z+rz*sz,clr);                   pv++;
		Stream->Unlock	(6,vs_L->vb_stride);
		// and Render it as line list
    	DU_DRAW_DP		(D3DPT_LINELIST,vs_L,vBase,3);
    }else{
		// fill VB
		FVF::L*	pv	 	= (FVF::L*)Stream->Lock(6,vs_L->vb_stride,vBase);
	    pv->set			(p.x,p.y+height*(1.f-sz_fl),p.z,clr); 								pv++;
    	pv->set			(p.x,p.y+height,p.z,clr); 											pv++;
	    pv->set			(p.x+_sin(heading)*sz,((pv-2)->p.y+(pv-1)->p.y)/2,p.z+_cos(heading)*sz,clr); pv++;
    	pv->set			(*(pv-3)); 															pv++;
	    pv->set			(*(pv-2)); 															pv++;
    	pv->set			(*(pv-4)); 															pv++;
		Stream->Unlock	(6,vs_L->vb_stride);
		// and Render it as triangle list
    	DU_DRAW_DP		(D3DPT_TRIANGLELIST,vs_L,vBase,2);
    }
}
コード例 #16
0
ファイル: floattrig.c プロジェクト: ruphy/speedcrunch
/* evaluates cos x - 1 for |x| <= pi.
   This function may underflow, which
   is indicated by the return value 0 */
char
_cosminus1(
  floatnum x,
  int digits)
{
  float_abs(x);
  if (float_cmp(x, &cPiDiv4) <= 0)
    return _cosminus1ltPiDiv4(x, digits);
  _cos(x, digits);
  float_sub(x, x, &c1, digits);
  return 1;
}
コード例 #17
0
ファイル: nv_algebra.cpp プロジェクト: 2asoft/xray
/*
    Given an axis and angle, compute quaternion.
 */
quat & axis_to_quat(quat& q, const vec3& a, const nv_scalar phi)
{
    vec3 tmp(a.x, a.y, a.z);

    normalize(tmp);
	nv_scalar s = _sin(phi/nv_two);
    q.x = s * tmp.x;
    q.y = s * tmp.y;
    q.z = s * tmp.z;
    q.w = _cos(phi/nv_two);
    return q;
}
コード例 #18
0
ファイル: floathmath.c プロジェクト: 0pq76r/SpeedCrunch
char
float_cos(
  floatnum x,
  int digits)
{
  if (!chckmathparam(x, digits))
    return 0;
  if (float_getexponent(x) >= DECPRECISION - 1 || !_trigreduce(x, digits))
    return _seterror(x, EvalUnstable);
  _cos(x, digits);
  return 1;
}
コード例 #19
0
ファイル: xrDeflector.cpp プロジェクト: NeoAnomaly/xray
BOOL CDeflector::OA_Place	(Face *owner)
{
	// It is not correct to rely solely on normal-split-angle for lmaps - imagine smooth sphere
	float cosa = normal.dotproduct(owner->N);
	if (cosa<_cos(deg2rad(g_params.m_sm_angle+1))) return FALSE;

	UVtri				T;
	T.owner				= owner;
	owner->pDeflector	= this;
	UVpolys.push_back	(T);
	return TRUE;
}
コード例 #20
0
ファイル: tgi_arc.c プロジェクト: cc65/cc65
void __fastcall__ tgi_arc (int x, int y, unsigned char rx, unsigned char ry,
                           unsigned sa, unsigned ea)
/* Draw an ellipse arc with center at x/y and radii rx/ry using the current
** drawing color. The arc covers the angle between sa and ea (startangle and
** endangle), which must be in the range 0..360 (otherwise the function may
** bevave unextectedly).
*/
{
    int x1, y1, x2, y2;
    unsigned char inc;
    unsigned char done = 0;

    /* Bail out if there's nothing to do */
    if (sa > ea) {
        return;
    }

    /* Determine the number of segments to use. This may be refined ... */
    if (rx + ry >= 25) {
        inc = 12;
    } else {
        inc = 24;
    }

    /* Calculate the start coords */
    x1 = x + tgi_imulround (rx, _cos (sa));
    y1 = y - tgi_imulround (ry, _sin (sa));
    do {
        sa += inc;
        if (sa >= ea) {
            sa = ea;
            done = 1;
        }
        x2 = x + tgi_imulround (rx, _cos (sa));
        y2 = y - tgi_imulround (ry, _sin (sa));
        tgi_line (x1, y1, x2, y2);
        x1 = x2;
        y1 = y2;
    } while (!done);
}
コード例 #21
0
ファイル: nv_algebra.cpp プロジェクト: 2asoft/xray
quat::quat(const vec3& axis, nv_scalar angle)
{
	nv_scalar len = axis.norm();
	if (len) {
		nv_scalar invLen = 1 / len;
		nv_scalar angle2 = angle / 2;
		nv_scalar scale = _sin(angle2) * invLen;
		x = scale * axis[0];
		y = scale * axis[1];
		z = scale * axis[2];
		w = _cos(angle2);
	}
}
コード例 #22
0
ファイル: FTreeVisual.cpp プロジェクト: 2asoft/xray-16
	void		calculate	()
	{
		dwFrame					= Device.dwFrame;

		// Calc wind-vector3, scale
		float	tm_rot			= PI_MUL_2*Device.fTimeGlobal/ps_r__Tree_w_rot;
		wind.set				(_sin(tm_rot),0,_cos(tm_rot),0);	wind.normalize	();	wind.mul(ps_r__Tree_w_amp);	// dir1*amplitude
		scale					= 1.f/float(FTreeVisual_quant);

		// setup constants
		wave.set				(ps_r__Tree_Wave.x,	ps_r__Tree_Wave.y,	ps_r__Tree_Wave.z,	Device.fTimeGlobal*ps_r__Tree_w_speed);			// wave
		wave.div				(PI_MUL_2);
	}
コード例 #23
0
ファイル: WeaponFire.cpp プロジェクト: 2asoft/xray
void random_dir(Fvector& tgt_dir, const Fvector& src_dir, float dispersion)
{
	float sigma			= dispersion/3.f;
	float alpha			= clampr		(_nrand(sigma),-dispersion,dispersion);
	float theta			= Random.randF	(0,PI);
	float r 			= tan			(alpha);
	Fvector 			U,V,T;
	Fvector::generate_orthonormal_basis	(src_dir,U,V);
	U.mul				(r*_sin(theta));
	V.mul				(r*_cos(theta));
	T.add				(U,V);
	tgt_dir.add			(src_dir,T).normalize();
}
コード例 #24
0
ファイル: atcd.c プロジェクト: pcostesi/tp1-so-2015b
static void _set_plane_x_y(struct atc_plane *plane, int time_dif)
{
	int aux = ((int)(_cos(plane->heading) * plane->speed * time_dif + plane->x ) ) % MAX_LEN;
	if( aux < 0 ){
		aux = MAX_LEN + aux;
	}
	plane->x = aux;
	aux = (int)(_sin(plane->heading) * plane->speed * time_dif + plane->y ) % MAX_HEIGHT;
	if( aux < 0 ){
		aux = MAX_HEIGHT + aux;
	}
	plane->y = aux;

}
コード例 #25
0
ファイル: ai_monster_bones.cpp プロジェクト: 2asoft/xray
void bonesBone::Turn(u32 dt)
{
	float PI_DIV_2m		= 8 * PI_DIV_6 / 3;		
	float PIm			= PI_DIV_2m * 2;

	float cur_speed = params.r_speed * _cos(PI_DIV_2m - PIm * _abs(params.target_yaw - params.cur_yaw) / params.dist_yaw);

	float dy;
	dy =  cur_speed * dt / 1000;  // учитываем милисек и радианную меры

	if (_abs(params.target_yaw - params.cur_yaw) < dy) params.cur_yaw = params.target_yaw;
	else params.cur_yaw += ((params.target_yaw > params.cur_yaw) ? dy : -dy);

}
コード例 #26
0
ファイル: D3DUtils.cpp プロジェクト: galek/xray
void CDrawUtilities::OnDeviceCreate()
{
	Device.seqRender.Add			(this,REG_PRIORITY_LOW-1000);

	m_SolidBox.CreateFromData		(D3DPT_TRIANGLELIST,DU_BOX_NUMFACES,		D3DFVF_XYZ|D3DFVF_DIFFUSE,du_box_vertices,			DU_BOX_NUMVERTEX,			du_box_faces,			DU_BOX_NUMFACES*3);
	m_SolidCone.CreateFromData		(D3DPT_TRIANGLELIST,DU_CONE_NUMFACES,		D3DFVF_XYZ|D3DFVF_DIFFUSE,du_cone_vertices,		DU_CONE_NUMVERTEX,			du_cone_faces,			DU_CONE_NUMFACES*3);
	m_SolidSphere.CreateFromData	(D3DPT_TRIANGLELIST,DU_SPHERE_NUMFACES,		D3DFVF_XYZ|D3DFVF_DIFFUSE,du_sphere_vertices,		DU_SPHERE_NUMVERTEX,		du_sphere_faces,		DU_SPHERE_NUMFACES*3);
	m_SolidSpherePart.CreateFromData(D3DPT_TRIANGLELIST,DU_SPHERE_PART_NUMFACES,D3DFVF_XYZ|D3DFVF_DIFFUSE,du_sphere_part_vertices,	DU_SPHERE_PART_NUMVERTEX,	du_sphere_part_faces,	DU_SPHERE_PART_NUMFACES*3);
    m_SolidCylinder.CreateFromData	(D3DPT_TRIANGLELIST,DU_CYLINDER_NUMFACES,	D3DFVF_XYZ|D3DFVF_DIFFUSE,du_cylinder_vertices,	DU_CYLINDER_NUMVERTEX,		du_cylinder_faces,		DU_CYLINDER_NUMFACES*3);
    m_WireBox.CreateFromData		(D3DPT_LINELIST,	DU_BOX_NUMLINES,		D3DFVF_XYZ|D3DFVF_DIFFUSE,du_box_vertices,			DU_BOX_NUMVERTEX,			du_box_lines,			DU_BOX_NUMLINES*2);
	m_WireCone.CreateFromData		(D3DPT_LINELIST,	DU_CONE_NUMLINES,		D3DFVF_XYZ|D3DFVF_DIFFUSE,du_cone_vertices,		DU_CONE_NUMVERTEX,			du_cone_lines,			DU_CONE_NUMLINES*2);
	m_WireSphere.CreateFromData		(D3DPT_LINELIST,	DU_SPHERE_NUMLINES,		D3DFVF_XYZ|D3DFVF_DIFFUSE,du_sphere_verticesl,		DU_SPHERE_NUMVERTEXL,		du_sphere_lines,		DU_SPHERE_NUMLINES*2);
	m_WireSpherePart.CreateFromData	(D3DPT_LINELIST,	DU_SPHERE_PART_NUMLINES,D3DFVF_XYZ|D3DFVF_DIFFUSE,du_sphere_part_vertices,	DU_SPHERE_PART_NUMVERTEX,	du_sphere_part_lines,	DU_SPHERE_PART_NUMLINES*2);
    m_WireCylinder.CreateFromData	(D3DPT_LINELIST,	DU_CYLINDER_NUMLINES,	D3DFVF_XYZ|D3DFVF_DIFFUSE,du_cylinder_vertices,	DU_CYLINDER_NUMVERTEX,		du_cylinder_lines,		DU_CYLINDER_NUMLINES*2);

	for(int i=0;i<LINE_DIVISION;i++){                                
		float angle = M_PI * 2.f * (i / (float)LINE_DIVISION);
        float _sa=_sin(angle), _ca=_cos(angle);
		circledef1[i].x = _ca;
		circledef1[i].y = _sa;
		circledef1[i].z = 0;
		circledef2[i].x = 0;
		circledef2[i].y = _ca;
		circledef2[i].z = _sa;
		circledef3[i].x = _sa;
		circledef3[i].y = 0;
		circledef3[i].z = _ca;
	}
    // initialize identity box
	Fbox bb;
	bb.set(-0.505f,-0.505f,-0.505f, 0.505f,0.505f,0.505f);
	for (i=0; i<8; i++){
    	Fvector S;
    	Fvector p;
        bb.getpoint(i,p);
        S.set((float)SIGN(p.x),(float)SIGN(p.y),(float)SIGN(p.z));
    	boxvert[i*6+0].set(p);
    	boxvert[i*6+1].set(p.x-S.x*0.25f,p.y,p.z);
    	boxvert[i*6+2].set(p);
    	boxvert[i*6+3].set(p.x,p.y-S.y*0.25f,p.z);
    	boxvert[i*6+4].set(p);
    	boxvert[i*6+5].set(p.x,p.y,p.z-S.z*0.25f);
    }
    // create render stream
	vs_L.create		(FVF::F_L,RCache.Vertex.Buffer(),RCache.Index.Buffer());
    vs_TL.create	(FVF::F_TL,RCache.Vertex.Buffer(),RCache.Index.Buffer());
    vs_LIT.create	(FVF::F_LIT,RCache.Vertex.Buffer(),RCache.Index.Buffer());

	m_Font						= new CGameFont("stat_font");
}
コード例 #27
0
ファイル: ascend.cpp プロジェクト: cjnoyes/astroweb
void setup_obliquity( JULIAN *ptr )
{
 double temp, eps;

 temp = ( -1.81e-3 * ptr->jd_cent ) + 5.9e-3;
 temp *= ptr->jd_cent;
 temp += 4.6845e1;
 temp *= ptr->jd_cent;
 eps = 2.345229444e1 - ( temp / 3600.0 );
 obliquity = eps;
 eps = d2r( eps );
 sin_obliquity = _sin( eps );
 cos_obliquity = _cos( eps );
 tan_obliquity = _tan( eps );
}
コード例 #28
0
ファイル: atcd.c プロジェクト: pcostesi/tp1-so-2015b
/*Returns 0 if plane crashed or landed, else returns 1, also calculates plane position and modifies it on the plane tuple*/
int calculate_position(struct atc_plane* plane, time_t new_time)
{
	int time_dif = new_time - plane->time;
	int aux = (int)(_cos(plane->elevation) * plane->speed * time_dif + plane->z ) ;
	if( aux < 0 ){
		int time_of_crash = new_time - plane->time - ( (aux*(-1))/(_sin(plane->elevation) * plane->speed) );
		plane->time = time_of_crash;
		_set_plane_x_y(plane, time_of_crash);
		_crashed_or_landed(plane);
		return 0;
	}
	else{
		plane->z = aux;
		_set_plane_x_y(plane, time_dif);
		return 1;
	}
}
コード例 #29
0
inline void evalcircle(const float c[3],
		       const float u[3],
		       const float v[3],
		       float radius,
		       float angle,
		       float p[3])
{
    // p = o + r*cos(f)*u + r*sin(f)*v

    float temp[3];

    cpvector(p, c);
    vecscalarmult(temp, (float*)u, radius*_cos(angle));
    vecadd(p, p, temp);
    vecscalarmult(temp, (float*)v, radius*_sin(angle));
    vecadd(p, p, temp);
}
コード例 #30
0
ファイル: light.cpp プロジェクト: 2asoft/xray
void	light::spatial_move			()
{
	switch(flags.type)	{
	case IRender_Light::REFLECTED	:	
	case IRender_Light::POINT		:	
		{
			spatial.sphere.set		(position, range);
		} 
		break;
	case IRender_Light::SPOT		:	
		{
			// minimal enclosing sphere around cone
			VERIFY2						(cone < deg2rad(121.f), "Too large light-cone angle. Maybe you have passed it in 'degrees'?");
			if (cone>=PI_DIV_2)			{
				// obtused-angled
				spatial.sphere.P.mad	(position,direction,range);
				spatial.sphere.R		= range * tanf(cone/2.f);
			} else {
				// acute-angled
				spatial.sphere.R		= range / (2.f * _sqr(_cos(cone/2.f)));
				spatial.sphere.P.mad	(position,direction,spatial.sphere.R);
			}
		}
		break;
	case IRender_Light::OMNIPART	:
		{
			// is it optimal? seems to be...
			//spatial.sphere.P.mad		(position,direction,range);
			//spatial.sphere.R			= range;
			// This is optimal.
			const float fSphereR		= range*RSQRTDIV2;
			spatial.sphere.P.mad		(position,direction,fSphereR);
			spatial.sphere.R			= fSphereR;
		}
		break;
	}

	// update spatial DB
	ISpatial::spatial_move			();

#if (RENDER==R_R2) || (RENDER==R_R3)
	if (flags.bActive) gi_generate	();
	svis.invalidate					();
#endif
}