Ejemplo n.º 1
0
void UIStaticText::Draw(const UIGeometricData &geometricData)
{
	textBlock->SetRectSize(size);
	textBlock->SetPosition(geometricData.position);
	textBlock->SetPivotPoint(geometricData.pivotPoint);
	PrepareSprite();
	textBlock->PreDraw();

    UIControl::Draw(geometricData);

    if(!FLOAT_EQUAL(shadowBg->GetDrawColor().a, 0.0f) && (!FLOAT_EQUAL(shadowOffset.dx, 0.0f) || !FLOAT_EQUAL(shadowOffset.dy, 0.0f)))
    {
		textBlock->Draw(GetShadowColor(), &shadowOffset);
        UIGeometricData shadowGeomData;
        shadowGeomData.position = shadowOffset;
        shadowGeomData.size = GetSize();
        shadowGeomData.AddToGeometricData(geometricData);

        shadowBg->SetAlign(textBg->GetAlign());
        shadowBg->SetPerPixelAccuracyType(background->GetPerPixelAccuracyType());
        shadowBg->Draw(shadowGeomData);
    }

    textBlock->Draw(GetTextColor());
    textBg->SetPerPixelAccuracyType(background->GetPerPixelAccuracyType());
    textBg->Draw(geometricData);
}
Ejemplo n.º 2
0
bool EdgeAdjacency::IsPointsEqual(const Vector3 & p0, const Vector3 & p1)
{
	if(FLOAT_EQUAL(p0.x, p1.x) && FLOAT_EQUAL(p0.y, p1.y) && FLOAT_EQUAL(p0.z, p1.z))
	{
		return true;
	}
	else
	{
		return false;
	}
}
Ejemplo n.º 3
0
bool Shader::Uniform::ValidateCacheColor3(const Color & value)
{
	Color& cachedColor = *(Color*)cacheValue;
	bool result = (FLOAT_EQUAL(cachedColor.r, value.r) &&
				   FLOAT_EQUAL(cachedColor.g, value.g) &&
				   FLOAT_EQUAL(cachedColor.b, value.b));
	
	if(!result)
	{
		DVASSERT(sizeof(value) - sizeof(float32) == cacheValueSize);
		memcpy(cacheValue, &value, cacheValueSize);
	}
	
	return result;
}
Ejemplo n.º 4
0
bool Collisions::IsSegmentIntersectsSegment(	
									   const Vector2 & p1, const Vector2 & p2, 
									   const Vector2 & p3, const Vector2 & p4, 
										  Vector2 & inters)
{
	float x1 = p1.x;
	float y1 = p1.y;
	
	float x2 = p2.x;
	float y2 = p2.y;
	
	float x3 = p3.x;
	float y3 = p3.y;
	
	float x4 = p4.x;
	float y4 = p4.y;
	
	float determ = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
	if (FLOAT_EQUAL(determ, 0.0f))
	{
		return false;
	}
	
	float t1 = ( (x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3) ) / determ;
	float t2 = ( (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3) ) / determ;
	
	if ((t1 >= 0.0f) && (t1 <= 1.0f))
		if ((t2 >= 0.0f) && (t2 <= 1.0f))
		{
			inters.x = x1 + (x2 - x1) * t1;
			inters.y = y1 + (y2 - y1) * t1;
			return true;
		}
	return false;
}
Ejemplo n.º 5
0
static inline gboolean
colors_equal (const gfloat   *col1,
              const gfloat   *col2,
              gint            components,
              gboolean        has_alpha)
{
  if (has_alpha &&
      FLOAT_IS_ZERO (col1[components - 1]) &&
      FLOAT_IS_ZERO (col2[components - 1]))
    {
      return TRUE;
    }
  else
    {
      gint b;

      for (b = 0; b < components; b++)
        {
          if (! FLOAT_EQUAL (col1[b], col2[b]))
            return FALSE;
        }

      return TRUE;
    }
}
Ejemplo n.º 6
0
int main()
{
	// simple pass case
	CHECK((int)false == 0);
	
	// simple error case
	CHECK(42 == 43);
	
	// special check for float equality
	CHECK(FLOAT_EQUAL(2.0f, 2.000001f));
	
	// other float test
	CHECK(FLOAT_EQUAL(2.0f, 42.0f));
	
	return 0;
}
Ejemplo n.º 7
0
f32 MyRandom::RandFloat(f32 fMin, f32 fMax)
{
	if( FLOAT_EQUAL( fMin, fMax))
		return fMin;

	if( fMin > fMax )
		std::swap( fMin, fMax);

	return fMin + (fMax - fMin) * RandFloat();
}
Ejemplo n.º 8
0
bool Shader::Uniform::ValidateCache(float32 value)
{
	bool result = FLOAT_EQUAL(*((float32*)cacheValue), value);
	
	if(!result)
	{
		DVASSERT(sizeof(value) == cacheValueSize);
		memcpy(cacheValue, &value, cacheValueSize);
	}
	
	return result;
}
Ejemplo n.º 9
0
void RenderHelper::DrawCircle3D(const Vector3 & center, const Vector3 &emissionVector, float32 radius, bool useFilling)
{
	Polygon3 pts;
    float32 angle = SEGMENT_LENGTH / radius;
	int ptsCount = (int)(PI_2 / (DegToRad(angle))) + 1;

	for (int k = 0; k < ptsCount; ++k)
	{
		float32 angleA = ((float)k / (ptsCount - 1)) * PI_2;
		float sinAngle = 0.0f;
		float cosAngle = 0.0f;
		SinCosFast(angleA, sinAngle, cosAngle);

		Vector3 directionVector(radius * cosAngle,
								radius * sinAngle,
								0.0f);
		
		// Rotate the direction vector according to the current emission vector value.
		Vector3 zNormalVector(0.0f, 0.0f, 1.0f);
		Vector3 curEmissionVector = emissionVector;
		curEmissionVector.Normalize();
		
		// This code rotates the (XY) plane with the particles to the direction vector.
		// Taking into account that a normal vector to the (XY) plane is (0,0,1) this
		// code is very simplified version of the generic "plane rotation" code.
		float32 length = curEmissionVector.Length();
		if (FLOAT_EQUAL(length, 0.0f) == false)
		{
			float32 cosAngleRot = curEmissionVector.z / length;
			float32 angleRot = acos(cosAngleRot);
			Vector3 axisRot(curEmissionVector.y, -curEmissionVector.x, 0);

			Matrix3 planeRotMatrix;
			planeRotMatrix.CreateRotation(axisRot, angleRot);
			Vector3 rotatedVector = directionVector * planeRotMatrix;
			directionVector = rotatedVector;
		}
		
		Vector3 pos = center - directionVector;
		pts.AddPoint(pos);
	}
	
	if (useFilling)
	{
		FillPolygon(pts);
	}
	else
	{
    	DrawPolygon(pts, false);
	}
}
Ejemplo n.º 10
0
void ParticleEmitter3D::CalculateParticlePositionForCircle(Particle* particle, const Vector3& tempPosition,
														   const Matrix3& rotationMatrix)
{
	float32 curRadius = 1.0f;
	if (radius)
	{
		curRadius = radius->GetValue(time);
	}

	float32 curAngle = PI_2 * (float32)Random::Instance()->RandFloat();
	if (emitterType == EMITTER_ONCIRCLE_VOLUME)
	{
		// "Volume" means we have to emit particles from the whole circle.
		curRadius *= (float32)Random::Instance()->RandFloat();
	}

	float sinAngle = 0.0f;
	float cosAngle = 0.0f;
	SinCosFast(curAngle, sinAngle, cosAngle);

	Vector3 directionVector(curRadius * cosAngle,
							curRadius * sinAngle,
							0.0f);
		
	// Rotate the direction vector according to the current emission vector value.
	Vector3 zNormalVector(0.0f, 0.0f, 1.0f);
	Vector3 curEmissionVector;
	if (emissionVector)
	{
		curEmissionVector = emissionVector->GetValue(time);
		curEmissionVector.Normalize();
	}
		
	// This code rotates the (XY) plane with the particles to the direction vector.
	// Taking into account that a normal vector to the (XY) plane is (0,0,1) this
	// code is very simplified version of the generic "plane rotation" code.
	float32 length = curEmissionVector.Length();
	if (FLOAT_EQUAL(length, 0.0f) == false)
	{
		float32 cosAngleRot = curEmissionVector.z / length;
		float32 angleRot = acos(cosAngleRot);
		Vector3 axisRot(curEmissionVector.y, -curEmissionVector.x, 0);

		Matrix3 planeRotMatrix;
		planeRotMatrix.CreateRotation(axisRot, angleRot);
		Vector3 rotatedVector = directionVector * planeRotMatrix;
		directionVector = rotatedVector;
	}
		
	particle->position = tempPosition + TransformPerserveLength(directionVector, rotationMatrix);	
}
Ejemplo n.º 11
0
void SceneValidator::ValidateScalesInternal(Entity *sceneNode, Set<String> &errorsLog)
{
//  Basic algorithm is here
// 	Matrix4 S, T, R; //Scale Transpose Rotation
// 	S.CreateScale(Vector3(1.5, 0.5, 2.0));
// 	T.CreateTranslation(Vector3(100, 50, 20));
// 	R.CreateRotation(Vector3(0, 1, 0), 2.0);
// 
// 	Matrix4 t = R*S*T; //Calculate complex matrix
// 
//	//Calculate Scale components from complex matrix
// 	float32 sx = sqrt(t._00 * t._00 + t._10 * t._10 + t._20 * t._20);
// 	float32 sy = sqrt(t._01 * t._01 + t._11 * t._11 + t._21 * t._21);
// 	float32 sz = sqrt(t._02 * t._02 + t._12 * t._12 + t._22 * t._22);
// 	Vector3 sCalculated(sx, sy, sz);

	if(!sceneNode) return;

	const Matrix4 & t = sceneNode->GetLocalTransform();
	float32 sx = sqrt(t._00 * t._00 + t._10 * t._10 + t._20 * t._20);
	float32 sy = sqrt(t._01 * t._01 + t._11 * t._11 + t._21 * t._21);
	float32 sz = sqrt(t._02 * t._02 + t._12 * t._12 + t._22 * t._22);

	if ((!FLOAT_EQUAL(sx, 1.0f)) 
		|| (!FLOAT_EQUAL(sy, 1.0f))
		|| (!FLOAT_EQUAL(sz, 1.0f)))
	{
 		errorsLog.insert(Format("Node %s: has scale (%.3f, %.3f, %.3f) ! Re-design level.", sceneNode->GetName().c_str(), sx, sy, sz));
	}

	int32 count = sceneNode->GetChildrenCount();
	for(int32 i = 0; i < count; ++i)
	{
		ValidateScalesInternal(sceneNode->GetChild(i), errorsLog);
	}
}
Ejemplo n.º 12
0
//! Check if point lays inside polygon (polygon must be in one plane)
bool Polygon3::IsPointInside(const Vector3 & pt)
{
    // Do not check if this is not a polygon
    if (pointCount <= 2)return false;

    UpdatePlaneFromPoints();

    float planeDist = plane.DistanceToPoint(pt);
    // if not on plane exit
    if (!FLOAT_EQUAL(planeDist, 0.0f))return false;

    int intersectionsCount = 0;
    Vector2 ray0(pt.x, pt.y);
    Vector2 ray1(((points[0].x + points[1].x) / 2.0f) + 1000000.0f, ((points[0].y + points[1].y) / 2.0f) + 100000.0f);

    /*
     If you enabling debug intersections do not forget to call this function inside Draw of your application.
     If you'll call it inside update or mouse or keyboard input functions you can not get any output.
     */
//#define DEBUG_DRAW_INTERSECTIONS
#if defined(DEBUG_DRAW_INTERSECTIONS)
    RenderManager::Instance()->SetColor(0.0f, 1.0f, 0.0f, 1.0f);
    RenderHelper::DrawLine(ray0, ray1);
#endif

    for (int i = 0; i < pointCount; ++i)
    {
        int32 i2 = (i == pointCount - 1) ? (0) : (i + 1);
        Vector2 pt1(points[i].x, points[i].y);
        Vector2 pt2(points[i2].x, points[i2].y);

        Vector2 result;
        if (Collisions::Instance()->IsSegmentIntersectsSegment(pt1, pt2, ray0, ray1, result))
        {

#if defined(DEBUG_DRAW_INTERSECTIONS)
            RenderManager::Instance()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
            RenderHelper::DrawPoint(result, 5.0f);
#endif

            intersectionsCount++;
        }
    }
    return intersectionsCount & 1;
}
Ejemplo n.º 13
0
bool Collisions::Is2DLineIntersects2DLine
								(const Vector2 & p1, const Vector2 & p2, 
								 const Vector2 & p3, const Vector2 & p4, 
								 Vector2 & inters)
{
	float a1 = p2.y - p1.y;
	float b1 = p1.x - p2.x;
	float c1 = -a1 * p1.x - b1 * p1.y; 
	
	float a2 = p4.y - p3.y;
	float b2 = p3.x - p4.x;
	float c2 = -a2 * p3.x - b2 * p3.y; 
	
	float determ = (a1 * b2 - a2 * b1);
	if (FLOAT_EQUAL(determ, 0.0f))
	{
		return false;
	}
	
	inters.x = (b1 * c2 - b2 * c1) / determ;
	inters.y = (a2 * c1 - a1 * c2) / determ;
	return true;
}
Ejemplo n.º 14
0
void Zone::OnCollide(Zone* other, unsigned long deltaTime)
{
	Vector3f p = m_WorldTransform.GetPosition();
	Vector3f p2 = other->WorldTransform().GetPosition();
	float r = other->m_Radius + this->m_Radius;

	// 两球相交
	if (r*r > (p - p2).SquaredLength())
	{
		if (FLOAT_EQUAL(other->m_Radius, this->m_Radius)) return;

		if (other->m_Radius > this->m_Radius)
		{
			SetRadius(this->m_Radius - 0.001f * deltaTime);
			other->SetRadius(other->m_Radius + 0.001f * deltaTime);
		}
		else
		{
			other->SetRadius(other->m_Radius - 0.001f * deltaTime);
			SetRadius(this->m_Radius + 0.001f * deltaTime);
		}
	}
}
Ejemplo n.º 15
0
/* note transcription, the inpyt is pitch vector, and the note sequence is generated */
int STranscribeQueryNote(float* fPitchArray,int& Len,SNote *&Query, int &nNoteLen){
	int i;
	int startindex=0; 

	for (i=1;i<Len-1;i++){
		/* remove the pitch jitter and the transition pitch value */
		if (((fPitchArray[i]-fPitchArray[i-1])>0.01 && (fPitchArray[i+1]-fPitchArray[i])>0.01)
	         || ((fPitchArray[i]-fPitchArray[i-1])<-0.01 && (fPitchArray[i+1]-fPitchArray[i])<-0.01)){
			float DistPre=(float)fabs(fPitchArray[i]-fPitchArray[i-1]);
			float DistAfter=(float)fabs(fPitchArray[i]-fPitchArray[i+1]);
	        if (DistPre<DistAfter)
	     		fPitchArray[i]=fPitchArray[i-1];
			else
		    	fPitchArray[i]=fPitchArray[i+1];
		}
	}

    /* combine the note by significant pitch change */
	for (i=0;i<Len;i++){
		if (fabs(fPitchArray[i+1]-fPitchArray[i])>0.05 || i==Len-1) {
			int nth=i+1-startindex;
			float *fTempMedian=new float[nth];
			memcpy(fTempMedian,fPitchArray+startindex,sizeof(float)*nth);
			
			if(nth>2){
				qsort(fTempMedian,nth, sizeof(float),_compareFloat);
				for(int j=0;j<nth;j++){
					fPitchArray[startindex+j]=fTempMedian[(nth+1)/2];
				}
			}
			startindex=i+1; 
			delete[] fTempMedian;
		} 
	}

	SNoteSequenceStru *retVal=new SNoteSequenceStru;
	retVal->Next=NULL;
	SNoteSequenceStru *CurrentNote=retVal;
	SNote Note;
	float OldPitch;
	Note.fNoteValue=fPitchArray[0]; 
	OldPitch=Note.fNoteValue;
	Note.fNoteDuration=1;

	/* post processing the note sequence */
	for (i=1;i<Len;i++){
		if (!FLOAT_EQUAL(fPitchArray[i],OldPitch)){
			if (Note.fNoteDuration<=2){
				float PrePitch;
      			if (NULL==retVal->Next)
					PrePitch=(float)MAX_NUMBER;
				else{
					SNoteSequenceStru *tmp=retVal;
					while(NULL!=tmp->Next){
						tmp=tmp->Next;
					}
					PrePitch=tmp->fNote.fNoteValue;
				}
				
				float OldPitch=fPitchArray[i];
				
				/* combine with the following note */
				if (fabs(Note.fNoteValue-PrePitch)<fabs(Note.fNoteValue-OldPitch)){
					SNoteSequenceStru *tmp=retVal;
					while(NULL!=tmp->Next){
						tmp=tmp->Next;
					}
					
					tmp->fNote.fNoteDuration+=Note.fNoteDuration;
					float TempVal=tmp->fNote.fNoteValue;
					for(int j=i-(int)Note.fNoteDuration;j<i;j++){
						fPitchArray[j]=TempVal;
					}
					Note.fNoteValue=fPitchArray[i];
					Note.fNoteDuration=1;
				}else{/* combine with the previous note */
					Note.fNoteValue=fPitchArray[i];
					for(int j=i-(int)Note.fNoteDuration;j<i;j++){
						fPitchArray[j]=Note.fNoteValue;
					}
					Note.fNoteDuration+=1;
				}
			}else{
				/* new note begin */
				SNoteSequenceStru *tmpNotes=new SNoteSequenceStru;
				tmpNotes->fNote=Note;
				tmpNotes->Next=NULL;
				CurrentNote->Next=tmpNotes;
				CurrentNote=CurrentNote->Next;
				Note.fNoteValue=fPitchArray[i];
				Note.fNoteDuration=1;
				nNoteLen++;
			}	
			OldPitch=fPitchArray[i];
		}else
			Note.fNoteDuration+=1;
	}
	SNoteSequenceStru *tmpNotes=new SNoteSequenceStru;
	tmpNotes->fNote=Note;
	tmpNotes->Next=NULL;
	CurrentNote->Next=tmpNotes;
	nNoteLen++;

	Query=new SNote[nNoteLen];
	nNoteLen=0;	

	/* convert the note sequence into MIDI format */
	CurrentNote=retVal->Next;
	if (Note.fNoteValue>0 && Note.fNoteValue<10){
		while(NULL!=CurrentNote){
			CurrentNote->fNote.fNoteValue=(float)(12.0f*(CurrentNote->fNote.fNoteValue-log(440.0f)/log(2.0f))+69.0f);
			Query[nNoteLen].fNoteValue=CurrentNote->fNote.fNoteValue;
			Query[nNoteLen].fNoteDuration=CurrentNote->fNote.fNoteDuration;
			CurrentNote=CurrentNote->Next;
			nNoteLen++;
		}
	}

	return 0;
}
Ejemplo n.º 16
0
void UISlider::SaveBackground(const char* prefix, UIControlBackground* background, YamlNode* rootNode, UIYamlLoader * loader)
{
    if (!background)
    {
        return;
    }

    ScopedPtr<UIControlBackground> baseBackground(new UIControlBackground());

    // Color.
    Color color = background->GetColor();
    if (baseBackground->GetColor() != color)
    {
        VariantType* nodeValue = new VariantType();
        nodeValue->SetColor(color);
        rootNode->Set(Format("%scolor", prefix), nodeValue);
        SafeDelete(nodeValue);
    }

    // Sprite.
    Sprite *sprite = background->GetSprite();
    if (sprite)
    {
        rootNode->Set(Format("%ssprite", prefix), Sprite::GetPathString(sprite));
    }
    int32 frame = background->GetFrame();
    if (baseBackground->GetFrame() != frame)
    {
        rootNode->Set(Format("%sframe", prefix), frame);
    }

    // Align
    int32 align = background->GetAlign();
    if (baseBackground->GetAlign() != align)
    {
        rootNode->AddNodeToMap(Format("%salign", prefix), loader->GetAlignNodeValue(align));
    }

    // Color inherit
    UIControlBackground::eColorInheritType colorInheritType =  background->GetColorInheritType();
    if (baseBackground->GetColorInheritType() != colorInheritType)
    {
        rootNode->Set(Format("%scolorInherit", prefix), loader->GetColorInheritTypeNodeValue(colorInheritType));
    }

    // Draw type.
    UIControlBackground::eDrawType drawType = background->GetDrawType();
    rootNode->Set(Format("%sdrawType", prefix), loader->GetDrawTypeNodeValue(drawType));

    // Stretch Cap.
    float32 leftRightStretchCap = background->GetLeftRightStretchCap();
    if (!FLOAT_EQUAL(baseBackground->GetLeftRightStretchCap(), leftRightStretchCap))
    {
        rootNode->Set(Format("%sleftRightStretchCap", prefix), leftRightStretchCap);
    }

    float32 topBottomStretchCap = background->GetTopBottomStretchCap();
    if (!FLOAT_EQUAL(baseBackground->GetTopBottomStretchCap(), topBottomStretchCap))
    {
        rootNode->Set(Format("%stopBottomStretchCap", prefix), topBottomStretchCap);
    }

    // spriteModification
    int32 modification = background->GetModification();
    if (baseBackground->GetModification() != modification)
    {
        rootNode->Set(Format("%sspriteModification", prefix), modification);
    }
}