コード例 #1
0
ファイル: bigint_en.c プロジェクト: xkuga/bigint
int main()
{
    // printf("hello, world");

    char result[BUFFER_SIZE];
    char remainder[BUFFER_SIZE];

    // please make sure the bit length is enough before calculate
    // especially when you do a large power operation
    // you can change it by define: BIG_INT_BIT_LEN
    // the default bit length for BigInt is 1024

    // routine test
    puts(Add("2010", "4", result));
    puts(Sub("0", "2014", result));
    puts(Mul("2", "43", result));
    puts(Div("86", "10", result, remainder));
    puts(remainder);
    puts(Mod("-86", "10", result));
    puts(PowMod("7", "80", "86", result));

    // BigInt test
    puts(Sub("233333333333333333333333333333333333333333333333", "33", result));
    puts(Mul("2333333333333333333333333333333", "2333333333333333333", result));
    puts(Div("2333333333333333333333333333333", "2333333333333333332", result, remainder));
    puts(remainder);
    puts(Pow("8", "86", result));

    return 0;
}
コード例 #2
0
ファイル: RopeJoint.cpp プロジェクト: ZhuangChun/Box2D
bool RopeJoint::SolvePositionConstraints(const SolverData& data)
{
	Vec2 cA = data.positions[m_indexA].c;
	float32 aA = data.positions[m_indexA].a;
	Vec2 cB = data.positions[m_indexB].c;
	float32 aB = data.positions[m_indexB].a;

	Rot qA(aA), qB(aB);

	Vec2 rA = Mul(qA, m_localAnchorA - m_localCenterA);
	Vec2 rB = Mul(qB, m_localAnchorB - m_localCenterB);
	Vec2 u = cB + rB - cA - rA;

	float32 length = u.Normalize();
	float32 C = length - m_maxLength;

	C = Clamp(C, 0.0f, maxLinearCorrection);

	float32 impulse = -m_mass * C;
	Vec2 P = impulse * u;

	cA -= m_invMassA * P;
	aA -= m_invIA * Cross(rA, P);
	cB += m_invMassB * P;
	aB += m_invIB * Cross(rB, P);

	data.positions[m_indexA].c = cA;
	data.positions[m_indexA].a = aA;
	data.positions[m_indexB].c = cB;
	data.positions[m_indexB].a = aB;

	return length - m_maxLength < linearSlop;
}
コード例 #3
0
ファイル: vec3n.cpp プロジェクト: Ochakko/MameBake3D
int  ConjGradientMod(float3N &X, float3Nx3N &A, float3N &B,int3 hack)
{
// obsolete!!!
       // Solves for unknown X in equation AX=B
       conjgrad_loopcount=0;
       int n=B.count;
       float3N q(n),d(n),tmp(n),r(n);
       r = B - Mul(tmp,A,X);    // just use B if X known to be zero
       r[hack[0]] = r[hack[1]] = r[hack[2]] = float3(0,0,0);
       d = r;
       float s = dot(r,r);
       float starget = s * squared(conjgrad_epsilon);
       while( s>starget && conjgrad_loopcount++ < conjgrad_looplimit)
       {
               Mul(q,A,d); // q = A*d;
               q[hack[0]] = q[hack[1]] = q[hack[2]] = float3(0,0,0);
               float a = s/dot(d,q);
               X = X + d*a;
               if(conjgrad_loopcount%50==0)
               {
                       r = B - Mul(tmp,A,X);
                       r[hack[0]] = r[hack[1]] = r[hack[2]] = float3(0,0,0);
               }
               else
               {
                       r = r - q*a;
               }
               float s_prev = s;
               s = dot(r,r);
               d = r+d*(s/s_prev);
               d[hack[0]] = d[hack[1]] = d[hack[2]] = float3(0,0,0);
       }
       conjgrad_lasterror = s;
       return conjgrad_loopcount<conjgrad_looplimit;  // true means we reached desired accuracy in given time - ie stable
}
コード例 #4
0
ファイル: vec3n.cpp プロジェクト: Ochakko/MameBake3D
int  ConjGradientFiltered(float3N &X, const float3Nx3N &A, const float3N &B,const float3Nx3N &S)
{
       // Solves for unknown X in equation AX=B
       conjgrad_loopcount=0;
       int n=B.count;
       float3N q(n),d(n),tmp(n),r(n);
       r = B - Mul(tmp,A,X);    // just use B if X known to be zero
       filter(r,S);
       d = r;
       float s = dot(r,r);
       float starget = s * squared(conjgrad_epsilon);
       while( s>starget && conjgrad_loopcount++ < conjgrad_looplimit)
       {
               Mul(q,A,d); // q = A*d;
               filter(q,S);
               float a = s/dot(d,q);
               X = X + d*a;
               if(conjgrad_loopcount%50==0)
               {
                       r = B - Mul(tmp,A,X);
                       filter(r,S);
               }
               else
               {
                       r = r - q*a;
               }
               float s_prev = s;
               s = dot(r,r);
               d = r+d*(s/s_prev);
               filter(d,S);
       }
       conjgrad_lasterror = s;
       return conjgrad_loopcount<conjgrad_looplimit;  // true means we reached desired accuracy in given time - ie stable
}
コード例 #5
0
ファイル: quat.C プロジェクト: fluffels/straylight
void Intermediate ( Quaternion* q0, Quaternion* q1, Quaternion* q2,
   Quaternion* a, Quaternion* b)
{
   /* assert:  q0, q1, q2 are unit quaternions */
   /*Quaternion q0inv = q0.UnitInverse();
   Quaternion q1inv = q1.UnitInverse();
   Quaternion p0 = q0inv*q1;
   Quaternion p1 = q1inv*q2;
   Quaternion arg = 0.25*(p0.Log()-p1.Log());
   Quaternion marg = -arg;
 
   a = q1*arg.Exp();
   b = q1*marg.Exp();
   */

   Quaternion p0, p1;
   UnitInverse(&p0, q0);
   UnitInverse(&p1, q1);
   MulSelf(&p0, q1);
   MulSelf(&p1, q2);
   LogSelf(&p0);
   LogSelf(&p1);
   Sub(a,&p0, &p1);
   MulScalSelf(a, 0.25);
   Neg(b, a);

   ExpSelf(a);
   ExpSelf(b);
   Mul(a, q1, a);
   Mul(b, q1, b);
}
コード例 #6
0
ファイル: sum.cpp プロジェクト: StrausMG/learning
u64 SumOfDivisorsOfBinomialCoefficient(u64 n, u64 k) {
    if (n == 2) {
        return k == 1 ? 3 : 1;
    } else if (n < 2) {
        return 1;
    }

    Vector primes = GetPrimes(n);
    Vector powers;
    for (auto x: primes) {
        powers.push_back(
            PowerOfDivisor(x, n) -
            PowerOfDivisor(x, k) -
            PowerOfDivisor(x, n - k) 
        );
    }

    u64 result = 1;
    for (u64 i = 0; i < primes.size(); ++i) {
        u64 sum_of_powers = 0;
        u64 x = 1;
        for (u64 p = 0; p <= powers[i]; ++p) {
            sum_of_powers = Sum(sum_of_powers, x);
            x = Mul(x, primes[i]);
        }
        result = Mul(result, sum_of_powers);
    }
    return result;
}
コード例 #7
0
ファイル: Ring_Element.cpp プロジェクト: lance6716/SPDZ-2
void mul(Ring_Element& ans,const Ring_Element& a,const Ring_Element& b)
{
  if (a.rep!=b.rep)   { throw rep_mismatch(); }
  if (a.FFTD!=b.FFTD) { throw pr_mismatch();  }
  ans.partial_assign(a);
  if (ans.rep==evaluation)
    { // In evaluation representation, so we can just multiply componentwise
      for (int i=0; i<(*ans.FFTD).phi_m(); i++)
        { Mul(ans.element[i],a.element[i],b.element[i],(*a.FFTD).get_prD()); }
    }
  else if ((*ans.FFTD).get_twop()!=0)
    { // This is the case where m is not a power of two

      // Here we have to do a poly mult followed by a reduction
      // We could be clever (e.g. use Karatsuba etc), but instead
      // we do the school book method followed by term re-writing

      // School book mult
      vector<modp> aa(2*(*a.FFTD).phi_m());
      for (int i=0; i<2*(*a.FFTD).phi_m(); i++)
        { assignZero(aa[i],(*a.FFTD).get_prD()); }
      modp temp;
      for (int i=0; i<(*a.FFTD).phi_m(); i++)
        { for (int j=0; j<(*a.FFTD).phi_m(); j++)
	    { Mul(temp,a.element[i],b.element[j],(*a.FFTD).get_prD()); 
              int k=i+j;
              Add(aa[k],aa[k],temp,(*a.FFTD).get_prD());
            }
        }
      // Now apply reduction, assumes Ring.poly is monic
      for (int i=2*(*a.FFTD).phi_m()-1; i>=(*a.FFTD).phi_m(); i--)
        { reduce_step(aa,i,*a.FFTD);
          assignZero(aa[i],(*a.FFTD).get_prD()); 
        }
     // Now stick into answer
     for (int i=0; i<(*ans.FFTD).phi_m(); i++)
       { ans.element[i]=aa[i]; }
    }
  else if ((*ans.FFTD).get_twop()==0)
    { // m a power of two case
      Ring_Element aa(*ans.FFTD,ans.rep);
      modp temp;
      for (int i=0; i<(*ans.FFTD).phi_m(); i++)
        { for (int j=0; j<(*ans.FFTD).phi_m(); j++)
            { Mul(temp,a.element[i],b.element[j],(*a.FFTD).get_prD());
              int k=i+j;
              if (k>=(*ans.FFTD).phi_m())
                 { k-=(*ans.FFTD).phi_m();
                   Negate(temp,temp,(*a.FFTD).get_prD());
                 }
              Add(aa.element[k],aa.element[k],temp,(*a.FFTD).get_prD());
            }
        }
      ans=aa;
    }
  else
    { throw not_implemented(); }
}
コード例 #8
0
ファイル: UtilTime.cpp プロジェクト: agran147/FieldWorks
/*----------------------------------------------------------------------------------------------
	Core routine to map between local and Utc. This assumes that DST doesn't kick in
	near a year boundary so that when the switch happens, the DST and STD times are in the
	same year.
----------------------------------------------------------------------------------------------*/
int64 TimeMapper::MapMsec(int64 msecSrc, bool fToUtc)
{
	int64 msecT;
	int msecDay;
	int day;
	int dayMin;
	int dyear;
	int yday;
	int yt;
	int ymin;

	// First determines the year type and minute within the year.

	// Mod to 400 year period.
	msecT = ModPos(msecSrc, kmsecPerPeriod);

	// Find the day within the 400 year period.
	day = (int)(msecT / kmsecPerDay);
	Assert(0 <= day && day < kdayPerPeriod);

	// Get the time within the day.
	msecDay = (int)(msecT - day * (int64)kmsecPerDay);
	Assert(0 <= msecDay && msecDay < kmsecPerDay);

	// Find the year within the 400 year period (dyear) and the day within that year (yday).
	Assert(0 <= day && day < 146097);
	dyear = YearFromDayInPeriod(day, &yday);
	Assert(0 <= dyear && dyear < 400);
	Assert(0 <= yday && (yday < 365 || yday == 365 && SilTime::IsLeapYear(dyear + kyearBase)));

	// Calculate the day number (within the 400 year period) of the first day of
	// the year (dayMin).
	dayMin = day - yday;
	Assert(dayMin == DayFromYearInPeriod(dyear));

	// Get the year type. kdayMonday is used because T0 is a Monday.
	yt = ModPos(dayMin + kwdayMonday, kdayPerWeek);
	if (SilTime::IsLeapYear(dyear + kyearBase))
		yt += kdayPerWeek;

	// Calculate the minute within the year.
	ymin = yday * kminPerDay + msecDay / kmsecPerMin;

	if (!fToUtc)
	{
		// Mapping from utc to local.
		if (m_rgyminMin[yt] <= ymin && ymin < m_rgyminLim[yt])
			return msecSrc + Mul(m_dminTz2, kmsecPerMin);
		return msecSrc + Mul(m_dminTz1, kmsecPerMin);
	}

	// The overlap is always ambiguous and there's nothing we can do about it.
	ymin -= m_dminTz2;
	if (m_rgyminMin[yt] <= ymin && ymin < m_rgyminLim[yt])
		return msecSrc - Mul(m_dminTz2, kmsecPerMin);
	return msecSrc - Mul(m_dminTz1, kmsecPerMin);
}
コード例 #9
0
//If you ever call something with 1 octave, call this instead
 void plainSIMD3d(SIMD* out, Settings*  S,ISIMDNoise3d noise )
{

	SIMD vfx = Mul(S->x.m, S->frequency);
	SIMD vfy = Mul(S->y.m, S->frequency);
	SIMD vfz = Mul(S->z.m, S->frequency);

	*out = noise(&vfx, &vfy, &vfz);
}
コード例 #10
0
ファイル: Rect.cpp プロジェクト: AzureCrab/StarEngine
	Rect Rect::operator*(mat4 matrix) const
	{
		matrix = Transpose(matrix);
		vec4 returnVec1 = Mul(vec4(m_LeftBottom.x, m_LeftBottom.y, 0, 1), matrix);
		vec4 returnVec2 = Mul(vec4(m_RightBottom.x, m_RightBottom.y, 0, 1), matrix);
		vec4 returnVec3 = Mul(vec4(m_LeftTop.x, m_LeftTop.y, 0, 1), matrix);
		vec4 returnVec4 = Mul(vec4(m_RightTop.x, m_RightTop.y, 0, 1), matrix);

		return Rect(vec2(returnVec1.x , returnVec1.y),
					vec2(returnVec2.x , returnVec2.y),
					vec2(returnVec3.x , returnVec3.y),
					vec2(returnVec4.x , returnVec4.y));
	}
コード例 #11
0
ファイル: 10_03_02_08_C_0592.CPP プロジェクト: hrnn/olymp
void Power( Matrix A, int P )
{
  Matrix R;
  memset(R, 0, sizeof(R));
  for (int i = 0; i < N; i++)
    R[i][i] = 1;
  for (; P; P >>= 1)
  {
    if (P & 1)
      Mul(R, A);
    Mul(A, A);
  }
  A = R;
}
コード例 #12
0
ファイル: template5.C プロジェクト: 0day-ci/gcc
void f ()
{
   Matrix<2, 3> q;
   Matrix<2, 4> a;
   Matrix<4, 3> b;
   q = Mul (q, a, b);
}
コード例 #13
0
ファイル: IP.cpp プロジェクト: neochang/PictView
/****************************************************
	FFT()

	参数:

		TD为时域值
		FD为频域值
		power为2的幂数

	返回值:

		无

	说明:

		本函数实现快速傅立叶变换
****************************************************/
void FFT(COMPLEX * TD, COMPLEX * FD, int power)
{
	int count;
	int i,j,k,bfsize,p;
	double angle;
	COMPLEX *W,*X1,*X2,*X;

	/*计算傅立叶变换点数*/
	count=1<<power;
	
	/*分配运算所需存储器*/
	W=(COMPLEX *)malloc(sizeof(COMPLEX)*count/2);
	X1=(COMPLEX *)malloc(sizeof(COMPLEX)*count);
	X2=(COMPLEX *)malloc(sizeof(COMPLEX)*count);
	
	/*计算加权系数*/
	for(i=0;i<count/2;i++)
	{
		angle=-i*PI*2/count;
		W[i].re=cos(angle);
		W[i].im=sin(angle);
	}
	
	/*将时域点写入存储器*/
	memcpy(X1,TD,sizeof(COMPLEX)*count);
	
	/*蝶形运算*/
	for(k=0;k<power;k++)
	{
		for(j=0;j<1<<k;j++)
		{
			bfsize=1<<(power-k);
			for(i=0;i<bfsize/2;i++)
			{
				p=j*bfsize;
				X2[i+p]=Add(X1[i+p],X1[i+p+bfsize/2]);
				X2[i+p+bfsize/2]=Mul(Sub(X1[i+p],X1[i+p+bfsize/2]),W[i*(1<<k)]);
			}
		}
		X=X1;
		X1=X2;
		X2=X;
	}
	
	/*重新排序*/
	for(j=0;j<count;j++)
	{
		p=0;
		for(i=0;i<power;i++)
		{
			if (j&(1<<i)) p+=1<<(power-i-1);
		}
		FD[j]=X1[p];
	}
	
	/*释放存储器*/
	free(W);
	free(X1);
	free(X2);
}
コード例 #14
0
ファイル: fhtmul.cpp プロジェクト: smarthaert/d-edit
void FastMul(const BigInt &A,const BigInt &B, BigInt &C) {
	ulong Len = 2;
	while ( Len <  A.Size + B.Size ) Len *=2;

	if ( Len < 40 ) {
		BigInt Atmp(A), Btmp(B);
		Mul(Atmp,Btmp,C);
		return;
	}

	ulong x;
	const ushort *a=A.Coef, *b=B.Coef;

	for (x = 0; x < A.Size; x++)    LongNum1[x] = a[x];
	for (; x < Len; x++) 		LongNum1[x] = 0.0;

	FHT_F(LongNum1,Len);

	if (a == b) {
		FHTConvolution(LongNum1,LongNum1,Len);
	} else {
		for (x = 0; x < B.Size; x++)    LongNum2[x] = b[x];
		for (; x < Len; x++) 		LongNum2[x] = 0.0;
		FHT_F(LongNum2,Len);
		FHTConvolution(LongNum1,LongNum2,Len);
	 }

	FHT_T(LongNum1,Len);

	CarryNormalize(LongNum1, Len, C);
}
コード例 #15
0
ファイル: funzioni.c プロジェクト: esalvucci/corso_algoritmi
char *Ricerca_e_deriva(char *funzione_1, char *funzione_2, char *operatore, char *output)
	{
		output = (char *)malloc(sizeof(char)*10000);
		if ( strcmp(operatore,"x") == 0 || ( strcmp(operatore,"plus") != 0 && strcmp(operatore,"mul") != 0 && strcmp(operatore,"sot") != 0 && strcmp(operatore,"pow") != 0 ))
			output = D_Fondamentali(operatore); // Se il primo operando è una x oppure non è nessuna delle funzioni previste allora chiama D_Fondamentali 	
	
		if(strcmp(operatore,"pow") == 0)	//	Potenza
			output = Pow(funzione_1,funzione_2, output);
	
		if(strcmp(operatore,"mul") ==  0)	//	Prodotto
			output = Mul(funzione_1 ,funzione_2, output);	
		
		if(strcmp(operatore,"div") == 0)	//	Rapporto
			output = Div(funzione_1 ,funzione_2, output);	
		
		if(strcmp(operatore,"plus") == 0)	//	Somma
			output = Sum(funzione_1,funzione_2, output);
		
		if(strcmp(operatore,"sot") == 0)	//	Differenza
			output = Sot(funzione_1,funzione_2, output);

		if(strcmp(operatore,"sin") == 0)	//	Seno
			output = Sin(funzione_1, "", output);
		
		if(strcmp(operatore,"cos") == 0)	//	Coseno
			output = Cos(funzione_1, "", output);
		
		
		return output;		// Ritorno la funzione già derivata	
}
コード例 #16
0
ファイル: BigData.cpp プロジェクト: LI8023NING/Linux-Network
BigData BigData::operator*(const BigData& bigData)
{
	if (0 == m_llValue || 0 == bigData.m_llValue)
	{
		return BigData(INT64(0));
	}

	if (!IsINT64Owerflow() && !bigData.IsINT64Owerflow())
	{
		if (m_strData[0] == bigData.m_strData[0])//同号
		{
			// 10 /2 = 5 >= 1 2 3 4 5
			// 10 /-2 = -5 <= -5 -4 -3 -2 -1 
			if (('+' == m_strData[0] && MAX_INT64 / m_llValue >= bigData.m_llValue) ||
				('-' == m_strData[0] && MAX_INT64 / m_llValue <= bigData.m_llValue))
			{
				return BigData(m_llValue*bigData.m_llValue);
			}
		}
		else//不同号
		{
			// -10 /2 = -5 <= 
			// -10/-2 = 5 >
			if (('+' == m_strData[0] && MIN_INT64 / m_llValue <= bigData.m_llValue) ||
				('-' == m_strData[0] && MIN_INT64 / m_llValue >= bigData.m_llValue))
			{
				return BigData(m_llValue*bigData.m_llValue);
			}
		}
	}

	return BigData(Mul(m_strData, bigData.m_strData).c_str());
}
コード例 #17
0
ファイル: BigData.cpp プロジェクト: xyzbaihaiping/BigData
BigData BigData::operator*(const BigData& bigData)
{
	if (m_llValue == 0 || bigData.m_llValue == 0)
	{
		return BigData(INT64(0));
	}
	if (!IsINT64Overflow() && !bigData.IsINT64Overflow())
	{
		if (m_strData[0] == bigData.m_strData[0])
		{
			if ((m_strData[0] == '+' && MAX_INT64 / m_llValue >= bigData.m_llValue)
				|| (m_strData[0] == '-' && MAX_INT64 / m_llValue <= bigData.m_llValue))
			{
				return BigData(m_llValue * bigData.m_llValue);
			}
		}
		else
		{
			if ((m_strData[0] == '+' && MIN_INT64 / m_llValue <= bigData.m_llValue)
				|| (m_strData[0] == '-' && MIN_INT64 / m_llValue >= bigData.m_llValue))
			{
				return BigData(m_llValue * bigData.m_llValue);
			}
		}
	}
	return BigData(Mul(m_strData, bigData.m_strData).c_str());
}
コード例 #18
0
ファイル: BigData.cpp プロジェクト: Stonelog/project
BigData BigData::operator* (const BigData& bigdata)
{
	if (!IsOverFlowINT64() && !bigdata.IsOverFlowINT64())
	{
		if (_value == 0 || bigdata._value == 0)
		{
			return BigData((INT64) 0);
		}
		//10 /2  = 5 >= 3     10 / -2  = -5 <= -4
		if (_pData[0] == bigdata._pData[0]) 
		{
			if ((_pData[0] == '+' && LLONG_MAX / _value >= bigdata._value) ||
				(_pData[0] == '-' && LLONG_MAX / _value <= bigdata._value))
			{
				return BigData(_value * bigdata._value);
			}
		}
		else
		{
			// -10 / 2 = -5 <= -4  -10 / -2 = 5 >= 4 
			if ((_pData[0] == '+' && (LLONG_MIN /_value <= bigdata._value)) ||
				(_pData[0] == '-' && (LLONG_MIN / _value >= bigdata._value)))
			{
				return BigData(_value * bigdata._value);
			}
		}
	}

	return BigData((char *)Mul(_pData, bigdata._pData).c_str());
}
コード例 #19
0
BigData BigData::operator*(const BigData& bigdata)
{
	if ((0 == _value) || (0 == bigdata._value))
	{
		return BigData(INT64(0));
	}
	if (IsINT64OverFlow() && bigdata.IsINT64OverFlow())
	{
		if (_strData[0] == bigdata._strData[0])
		{
			if (((_value > 0) && ((long long)MAX_INT64 / _value >= bigdata._value)) ||
				((_value < 0) && ((long long)MAX_INT64 / _value <= bigdata._value)))   //同号相乘 结果为正
			{
				return BigData(_value*bigdata._value);
			}
		}
		else
		{
			if (((_value > 0) && ((long long)MIN_INT64 / _value <= bigdata._value)) ||
				((_value < 0) && ((long long)MIN_INT64 / _value >= bigdata._value)))      //异号相乘 结果为负
			{
				return BigData(_value*bigdata._value);
			}
		}
	}

	return BigData(Mul(_strData, bigdata._strData).c_str());
}
コード例 #20
0
ファイル: collision.c プロジェクト: Narcolapser/LittleLibs
int IntersectRayAABB(Point p, Point d, AABB a, float *tmin, Point *q)
{
	(*tmin) = 0.0f;
	float tmax = FLT_MAX;

	//for all three slabs
	int i;
	for (i = 0; i < 3; ++i)
	{
		if (Abs(d[i]) < EPSILON)
			if (p[i] < a.min[i] || p[i] > a.max[i]) return 0;
		else
		{
			float ood = 1.0f / d[i];
			float t1 = (a.min[i] - p[i]) * ood;
			float t2 = (a.max[i] - p[i]) * ood;
			if(t1 > t2) Swap(t1,t2);
			(*tmin) = Max(tmin, t1);
			tmax = Max(tmax, t2);

			if((*tmin) > tmax) return 0;
		}
	}

	(*q) = p + Mul(d,(*tmin));
	return 1;
}
コード例 #21
0
ファイル: ofxObject.cpp プロジェクト: Surfincolin/ofxSoso
float* ofxObject::updateMatrix(float *iParentMatrix)
{
	// if the object has multiple parents, the hierarchy tree matrix needs to be set to dirty, using mMatrixDirty.
	if (parents.size() > 1) matrixDirty = true;
  
	if (matrixDirty  ||  localMatrixDirty  || alwaysMatrixDirty) {
		if (localMatrixDirty) {
			updateLocalMatrix();
		}
    
		//matrix multiplication
		Mul(localMatrix, iParentMatrix, matrix);
    
		/*
     if(id==1)
     printf("matrix:\n%f\t%f\t%f\t%f\n%f\t%f\t%f\t%f\n%f\t%f\t%f\t%f\n%f\t%f\t%f\t%f\n",
     matrix[0], matrix[1], matrix[2], matrix[3],
     matrix[4], matrix[5], matrix[6], matrix[7],
     matrix[8], matrix[9], matrix[10], matrix[11],
     matrix[12], matrix[13], matrix[14], matrix[15]);
     */
    
		// set matrix dirty flags of all children
		for (unsigned int i = 0; i < children.size(); i++)
			children[i]->matrixDirty = true;
    
		//if(id == 1) printf("updateMatrix() %f\n", ofGetElapsedTimef());
    
		//reset matrix dirty flag
		matrixDirty = false;
	}
  
	return matrix;
}
コード例 #22
0
ファイル: Main.cpp プロジェクト: Venomic/CPURasterizer
	void RenderFrame(Application &app, LockBufferInfo &frame_info)
	{
		app.render_scene_time = GetTime(app.api);

		// Calculate view_projection matrix.
		float4 camera_transform[4], camera_projection[4], view_projection[4];
		CreateCameraTransform(camera_transform, app.camera.pos, app.camera.axis);
		CreatePerspectiveProjection(camera_projection, app.camera.fov, float(app.framebuffer.width) / float(app.framebuffer.height), 0.5f, 100.0f);
		Mul(view_projection, camera_transform, camera_projection);

		// Build rasterizer input commands.
		Build(app.rasterizer_input, app.scene, view_projection);

		app.frame_info = &frame_info;

		// Start the rasterizer threads
		U32 event_id = app.rasterizer_event_id;
		SetEvent(app.start_rasterization_event[event_id]);

		// Wait for the threads to finish.
		WaitForMultipleObjects(DefaultThreadAmount, app.rasterization_finished_event, TRUE, INFINITE);
		ResetEvent(app.start_rasterization_event[event_id]);
		app.rasterizer_event_id = (event_id + 1) % 2;

		app.frame_info = NULL;

		app.render_scene_time = GetTime(app.api) - app.render_scene_time;
	}
コード例 #23
0
ファイル: BigData.cpp プロジェクト: hhhh93/Vector
BigData BigData::operator*(const BigData& bigData)
{
	if (0 == m_llValue || 0 == bigData.m_llValue)
	{
		return BigData(INT64(0));
	}
	if (!IsINT64Owerflow() && !bigData.IsINT64Owerflow())
	{
		if (m_strData[0] == bigData.m_strData[0])
		{
			if (('+' == m_strData[0] && MAX_INT64 / m_llValue >= bigData.m_llValue) || ('-' == m_strData[0] && MAX_INT64 / m_llValue <= bigData.m_llValue))
			{
				return BigData(m_llValue*bigData.m_llValue);
			}
		}
		else
		{
			//-10/2   
			//-10/-2
			if (('+' == m_strData[0] && MIN_INT64 / m_llValue <= bigData.m_llValue) || ('-' == m_strData[0] && MIN_INT64 / m_llValue >= bigData.m_llValue))
			{
				return BigData(m_llValue*bigData.m_llValue);
			}
		}
	}
	return BigData(Mul(m_strData, bigData.m_strData).c_str());
}
コード例 #24
0
ファイル: Quaternion.cpp プロジェクト: q4r/QEngine
void Quaternion::Set(const D3DXVECTOR3& vector, float angle){
	x = vector.x;
	y = vector.y;
	z = vector.z;
	Mul(sin(angle / 2));
	w = cos(angle / 2);
}
コード例 #25
0
int main()
{
	int num = 101;
	Mul mul(11);
	std::cout << run(num, mul) << std::endl;
	std::cout << run(num,Mul(101)) << std::endl;
	return 0;
}
コード例 #26
0
ファイル: svm1-interp.c プロジェクト: barak/mit-scheme
static word_t
multiply_with_overflow (long x, long y)
{
  word_t ans = (Mul ((LONG_TO_FIXNUM (x)), (LONG_TO_FIXNUM (y))));
  return (ans == SHARP_F
	  ? SHARP_T   /* This need only be !NFIX for overflow-test. */
	  : FIXNUM_TO_LONG (ans));
}
コード例 #27
0
void MtlBlinnSW3D::Transmit(ShadeContext3D &sc)
{
	BlinnBlock &block = (BlinnBlock &) sc.GetMaterialBlock(this);
	const Vector4f &vertexColor = IsSet(block.VertexColor) ? *block.VertexColor : WHITE4F;

	Color4f diffuseMtl;

	if (DiffuseMtl)
	{
		DiffuseMtl->Shade(sc);
		diffuseMtl = *block.Color;
	}
	else
		diffuseMtl = WHITE4F;

	Color4f Kd = Mul(PreDiffuse, Mul(diffuseMtl, vertexColor));

	if (fabs(Kd.A) < 0.0001f)
		Kd = Color4f(1.0f, 1.0f, 1.0f, 0.0f);
	else
	{
		Kd.R /= Kd.A;
		Kd.G /= Kd.A;
		Kd.B /= Kd.A;
	}

	float32 y = Kd.Luminance();
	Color4f satColor = Lerp(Color4f(y, y, y, 1.0f), Kd, Saturation);
	satColor.A = 1.0f;

	Color4f textureDetail = Lerp(Color4f(0.0f, 0.0f, 0.0f, 1.0f), satColor, ColorDetail);
	textureDetail.A = 1.0f;

	float32 alphaDetail = Lerp(0.0f, 1.0f - Kd.A, AlphaDetail);
	Color4f outTrans = (1.0f - alphaDetail) * textureDetail + Color4f(alphaDetail);			// compute 1 - (1 - ad) * (1 - td)

	outTrans = Color4f(1.0f) - Mul(Color4f(1.0f) - outTrans, Color4f(1.0f) - Transmittance);

	sc.Transmittance.R = max(min(outTrans.R, 1.0f), 0.0f);
	sc.Transmittance.G = max(min(outTrans.G, 1.0f), 0.0f);
	sc.Transmittance.B = max(min(outTrans.B, 1.0f), 0.0f);
	sc.Transmittance.A = outTrans.A;

	FuASSERT(sc.Transmittance.A >= 0.0f && sc.Transmittance.A <= 1.002f, (""));
}
コード例 #28
0
ファイル: ch7_32.c プロジェクト: mysticTot/learn_c
void main(void) {
    int a = 1, b = 2, c = 3, d = 4;
    int result1, result2;
    result1 = Sum(a * b, c * d);
    result2 = Mul(a + b, c + d);
    printf("result1=%d\n", result1);
    printf("result2=%d\n", result2);
    /*  system("pause");  */
}
コード例 #29
0
ファイル: Quaternion.cpp プロジェクト: q4r/QEngine
Quaternion::Quaternion(const D3DXVECTOR3& vector, float angle):
	x(vector.x),
	y(vector.y),
	z(vector.z), 
	w(0)
{
	Mul(sin(angle / 2));
	w = cos(angle / 2);
}
コード例 #30
0
ファイル: Body.hpp プロジェクト: ZhuangChun/Box2D
inline void Body::Advance(float32 alpha)
{
	// Advance to the new safe time. This doesn't sync the broad-phase.
	m_sweep.Advance(alpha);
	m_sweep.c = m_sweep.c0;
	m_sweep.a = m_sweep.a0;
	m_xf.q.Set(m_sweep.a);
	m_xf.p = m_sweep.c - Mul(m_xf.q, m_sweep.localCenter);
}