Esempio n. 1
0
void Slice::drawPolygon(Polygons &pgs, int layer){

    glColor4f(0.0f, 1.0f, 0.0f, 0.25f);
    GLUtesselator* tess = gluNewTess();
    gluTessCallback(tess, GLU_TESS_BEGIN, (GLvoid (__stdcall *) ())&BeginCallback);
    gluTessCallback(tess, GLU_TESS_VERTEX, (GLvoid (__stdcall *) ())&VertexCallback);
    gluTessCallback(tess, GLU_TESS_END, (GLvoid (__stdcall *) ())&EndCallback);
    gluTessCallback(tess, GLU_TESS_COMBINE, (GLvoid (__stdcall *) ())&CombineCallback);
    gluTessCallback(tess, GLU_TESS_ERROR, (GLvoid (__stdcall *) ())&ErrorCallback);
    gluTessNormal(tess, 0.0, 0.0, 1.0);
    gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
    gluTessProperty(tess, GLU_TESS_BOUNDARY_ONLY, GL_FALSE); //GL_FALSE
    gluTessBeginPolygon(tess, NULL);
    glPushMatrix();
    glTranslated(0.0,0.0,this->layerHeight*layer);
    for (Polygons::size_type i = 0; i < pgs.size(); ++i)
    {
        gluTessBeginContour(tess);
        for (ClipperLib::Polygon::size_type j = 0; j < pgs[i].size(); ++j)
        {
            GLdouble *vert =
                    NewVector((GLdouble)pgs[i][j].X/1000, (GLdouble)pgs[i][j].Y/1000);
            gluTessVertex(tess, vert, vert);
        }
        gluTessEndContour(tess);
    }
    gluTessEndPolygon(tess);
    ClearVectors();

    glColor4f(0.0f, 0.6f, 1.0f, 0.5f);
    glLineWidth(1.8f);

    gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
    gluTessProperty(tess, GLU_TESS_BOUNDARY_ONLY, GL_TRUE);
    for (Polygons::size_type i = 0; i < pgs.size(); ++i)
    {
        gluTessBeginPolygon(tess, NULL);
        gluTessBeginContour(tess);
        for (ClipperLib::Polygon::size_type j = 0; j < pgs[i].size(); ++j)
        {
            GLdouble *vert =
                    NewVector((GLdouble)pgs[i][j].X/1000, (GLdouble)pgs[i][j].Y/1000);
            gluTessVertex(tess, vert, vert);
        }

        glColor4f(0.0f, 0.0f, 0.8f, 0.5f);

        gluTessEndContour(tess);
        gluTessEndPolygon(tess);
    }

    //final cleanup ...
    gluDeleteTess(tess);
    ClearVectors();
    glPopMatrix();
}
Esempio n. 2
0
// 向量乘以矩阵,该乘法也可是使用矩阵转置和MtxVecMultiple函数实现,
// 但是考虑到系统矩阵太大,矩阵转置消耗内存,因此不使用
int SprsMtxOperator::VecMtxMultiple(Vector& InVec, const SparseMtx& Mtx, Vector& ResultVec)
{
	int i;
	int iRowNum;
	int iColNum;
	int iTotElemNum;
	int iVecNum;

	iRowNum = Mtx.n_rows;
	iColNum = Mtx.n_cols;
	iTotElemNum = Mtx.n_actual_ELEM;
	iVecNum = InVec.iNum;
	
	if ( iRowNum != iVecNum  || iColNum != ResultVec.iNum )
	{
		printf("Dimensions of matrix and vector mismatch\n");
		return (-1);
	}

	Vector NewVector(iColNum);
	NewVector. Initilize();
		
	for ( i = 0; i < iTotElemNum; i++ )
	{
		NewVector.pdData[Mtx.items[i].col] += Mtx.items[i].val * InVec.pdData[Mtx.items[i].row];
	}

	for ( i = 0; i < ResultVec.iNum; i++ )
	{
		ResultVec.pdData[i] = NewVector.pdData[i];
	}	
	return 0;	
}
Esempio n. 3
0
double *CreateVector(SMatrix M)
{
  long i, j;
  double *b;

  b = NewVector(M.n);

  for (j=0; j<M.n; j++)
    b[j] = 0.0;

  if (M.nz) {
    for (j=0; j<M.n; j++)
      for (i=M.col[j]; i<M.col[j+1]; i++) {
	b[M.row[i]] += M.nz[i];
      }
  }
  else {
    for (j=0; j<M.n; j++)
      for (i=M.col[j]; i<M.col[j+1]; i++) {
	b[M.row[i]] += Value(M.row[i], j);
      }
  }

  return(b);
}
Esempio n. 4
0
VAR * AddUnitVar(VTYPE Type, char * Name, UNIT * Owner)
{
  VAR * pNewVar = malloc(sizeof(VAR));
  pNewVar->Name = myStrCpy(Name);
  pNewVar->Type = Float;

  if (Type == Int)
  {
    int *x = malloc(sizeof(int));
    *x = 0;
    pNewVar->Data = x;
  }
  else if (Type == Float)
  {
    float *x = malloc(sizeof(float));
    *x = 0.0;
    pNewVar->Data = x;
  }
  else if (Type == Vector)
  {
    VECTOR *x = malloc(sizeof(VECTOR));
    *x = NewVector(0, 0);
    pNewVar->Data = x;
  }
  else if (Type == String)
  {
    char **x = malloc(sizeof(char*));
    *x = NULL;
    pNewVar->Data = x;
  }
  else if (Type == Color)
  {
    COLOR newCol = { 1, 1, 1, 1 };
    COLOR *x = malloc(sizeof(COLOR));
    *x = newCol;
    pNewVar->Data = x;
  }
  else if (Type == Bool)
  {
    BOOL *x = malloc(sizeof(BOOL));
    *x = False;
    pNewVar->Data = x;
  }
  else if (Type == Char)
  {
    char *x = malloc(sizeof(char));
    *x = '\0';
    pNewVar->Data = x;
  }
  else if (Type == Matrix)
  {
    MATRIX *temp = (MATRIX*)malloc(sizeof(MATRIX));
    SecureZeroMemory(temp->m, sizeof(float) * 9);
    pNewVar->Data = temp;
  }
  pNewVar->nextVar = Owner->nextVar;
  Owner->nextVar = pNewVar;
  return pNewVar;
  return NULL;
}
Esempio n. 5
0
void BloombergVector::RepackVector(){
    Q_D(BloombergVector);
    if (d->m_VectVal.isEmpty()) {
        d->m_Vector = "";
		return;
	}
	QString NewVector("");
	int StepSize = 1;
	int RampSize = 0;
	double PrevVal;
	double predictedRamp;
	boost::math::tools::eps_tolerance<double> ToleranceMonitor(std::numeric_limits<double>::digits / 2);
    PrevVal = d->m_VectVal.at(0);
    NewVector += QString("%1").arg(PrevVal*d->m_Divisor);
    for (int i = 1; i<d->m_VectVal.size(); i++) {
        if (ToleranceMonitor(d->m_VectVal.at(i), PrevVal) && RampSize == 0) {
            StepSize++;
        }
		else {
			if (StepSize == 1) {
				if (RampSize == 0) {
					RampSize++;
                    predictedRamp = d->m_VectVal.at(i) - PrevVal;
				}
				else {
                    if (ToleranceMonitor(d->m_VectVal.at(i) - d->m_VectVal.at(i - 1), predictedRamp)) {
						RampSize++;
					}
					else { //The Ramp is Over
                        PrevVal = d->m_VectVal.at(--i);
                        NewVector += QString(" %1%2 %3").arg(RampSize).arg(RampSize>1 ? 'R' : 'S').arg(PrevVal*d->m_Divisor);
						RampSize = 0;
					}
				}
			}
			else {
                PrevVal = d->m_VectVal.at(i);
                NewVector += QString(" %1S %2").arg(StepSize).arg(PrevVal*d->m_Divisor);
				StepSize = 1;
			}
		}
	}
    if (RampSize>0) 
        NewVector += QString(" %1%2 %3").arg(RampSize).arg(RampSize>1 ? 'R' : 'S').arg(d->m_VectVal.last()*d->m_Divisor);
    d->m_Vector = NewVector;
}
Esempio n. 6
0
//Creates an empty Level.
LEVEL * AddLevel(GAME * pGame, char *Name, int Order)
{

	LEVEL * pNewLevel = malloc(sizeof(LEVEL));
  CAMERA * pCam = malloc(sizeof(CAMERA));
  pCam->Position = NewVector(0, 0);
  pCam->Zoom = 48;
  
	pNewLevel->Name = myStrCpy(Name);
	pNewLevel->Order = Order;
	pNewLevel->pCamera = pCam;
	pNewLevel->nextUnit = NULL;
  pNewLevel->pGame = pGame;
	pNewLevel->nextLevel = pGame->nextLevel;
	pGame->nextLevel = pNewLevel;

  return pNewLevel;
}
Esempio n. 7
0
// 矩阵乘以向量
int SprsMtxOperator::MtxVecMultiple(const SparseMtx& Mtx, Vector& InVec, Vector& ResultVec)
{
	int i;
	int iRowNum;
	int iColNum;
	int iTotElemNum;
	int iVecNum;
	
	iRowNum = Mtx.n_rows;
	iColNum = Mtx.n_cols;
	iTotElemNum = Mtx.n_actual_ELEM;
	iVecNum = InVec.iNum;
	
	if ( iColNum != iVecNum  || iRowNum != ResultVec.iNum )
	{
		printf("Dimensions of matrix and vector mismatch\n");
		return (-1);
	}
	
	Vector NewVector(iRowNum);
	NewVector.Initilize();
		
	for ( i = 0; i < iTotElemNum; i++ )  //iTotElemNum是2506949 iRowNum是16384 row的最大是为16384 col的最大是为16384 pdData最大值为16384
	{   // cout<<NewVector.pdData[Mtx.items[i].row-1]<<"+";
		NewVector.pdData[Mtx.items[i].row] += Mtx.items[i].val*InVec.pdData[Mtx.items[i].col];



		//cout<<Mtx.items[i].val<<"*"<<InVec.pdData[Mtx.items[i].col-1]<<"="<<NewVector.pdData[Mtx.items[i].row-1]<<endl;
	}
	//cout<<Mtx.items[i].val<<"*"<<InVec.pdData[Mtx.items[i].col-1]<<"="<<NewVector.pdData[Mtx.items[i].row-1]<<endl;
	for ( i = 0; i < ResultVec.iNum; i++ )
	{
		ResultVec.pdData[i] = NewVector.pdData[i];
	}	
	return 0;	
}
Esempio n. 8
0
void InterpretArchetype(FILE * fpArch)
{
    char buffer[MAX_LENGTH];
    ARCHETYPE * pNewArchetype = malloc(sizeof(ARCHETYPE));
    COMPONENT * pCurrComp = NULL;
    pNewArchetype->Name = "Untitled";
    pNewArchetype->nextArchetype = NULL;
    pNewArchetype->nextComponent = NULL;
    pNewArchetype->pGame = pTheGame;
    pNewArchetype->pUnit = NULL;
    pNewArchetype->nextArchetype = pTheGame->nextArchetype;
    pTheGame->nextArchetype = pNewArchetype;
    while (!feof(fpArch))
    {
        if (fgets(buffer, MAX_LENGTH, fpArch))
        {
            char question[MAX_LENGTH];
            int inputInt = 0;
            float inputFloat = 0.0f;
            VECTOR inputVector = NewVector(0, 0);
            AddNull(buffer);
            if (buffer[0] != '#' && strlen(buffer) > 2)
            {
                sscanf(buffer, "%s", &question);
                if (myStrCmp(question, "Name") <= 0)
                {
                    char nameInput[MAX_LENGTH];
                    sscanf(buffer, "Name = %s", nameInput);
                    pNewArchetype->Name = myStrCpy(nameInput);
                    continue;
                }

                if (myStrCmp(question, "Tag") <= 0)
                {
                    char tagInput[MAX_LENGTH];
                    sscanf(buffer, "Tag = %s", tagInput);
                    pNewArchetype->Tag = GetTagFromString(tagInput);
                    continue;
                }

                if (myStrCmp(question, "COMPONENT") <= 0)
                {
                    COMPONENTTYPE theType;
                    char typeInput[MAX_LENGTH];
                    sscanf(buffer, "COMPONENT |%s|", &typeInput);
                    if (myStrCmp(typeInput, "Sprite") <= 0) theType = Sprite;
                    if (myStrCmp(typeInput, "Mesh") <= 0) theType = Mesh;
                    if (myStrCmp(typeInput, "Behavior") <= 0) theType = Behavior;
                    if (myStrCmp(typeInput, "Physics") <= 0) theType = Physics;
                    if (myStrCmp(typeInput, "Collider") <= 0) theType = Collider;
                    if (myStrCmp(typeInput, "KSound") <= 0) theType = KSound;


                    pCurrComp = AddComponent(pNewArchetype, theType);
                    continue;
                }

                if (pCurrComp)
                {
                    if (pCurrComp->Type == Mesh)
                    {
                        MESH * pMesh = (MESH*)pCurrComp->pStruct;
                        if (myStrCmp(question, "Size") <= 0)
                        {
                            sscanf(buffer, "\tSize = (%f, %f)", &inputVector.x, &inputVector.y);
                            pMesh->Size = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "Color") <= 0)
                        {
                            COLOR inputColor;
                            sscanf(buffer, "\tColor = (%f, %f, %f, %f)", &inputColor.r, &inputColor.g, &inputColor.b, &inputColor.a);
                            pMesh->Color = inputColor;
                            continue;
                        }

                        if (myStrCmp(question, "Opacity") <= 0)
                        {
                            sscanf(buffer, "\tOpacity = %f", &inputFloat);
                            pMesh->Opacity = inputFloat;
                            continue;
                        }
                    }

                    if (pCurrComp->Type == Behavior)
                    {
                        BEHAVIOR * pBehavior = (BEHAVIOR*)pCurrComp->pStruct;
                        if (myStrCmp(question, "BehaviorScript") <= 0)
                        {
                            char scriptInput[MAX_LENGTH];
                            sscanf(buffer, "\tBehaviorScript = %s", &scriptInput);
                            pBehavior->BehaviorScript = GetBehaviorFromString(scriptInput);
                            continue;
                        }
                    }

                    if (pCurrComp->Type == Physics)
                    {
                        PHYSICS * pPhysics = (PHYSICS*)pCurrComp->pStruct;
                        if (myStrCmp(question, "Gravity") <= 0)
                        {
                            sscanf(buffer, "\tGravity = %f", &inputFloat);
                            pPhysics->Gravity = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "MaxSpeed") <= 0)
                        {
                            sscanf(buffer, "\tMaxSpeed = %f", &inputFloat);
                            pPhysics->MaxSpeed = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "Friction") <= 0)
                        {
                            sscanf(buffer, "\tFriction = %f", &inputFloat);
                            pPhysics->Friction = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "Velocity") <= 0)
                        {
                            sscanf(buffer, "\tVelocity = (%f, %f)", &inputVector.x, &inputVector.y);
                            pPhysics->Velocity = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "Acceleration") <= 0)
                        {
                            sscanf(buffer, "\tAcceleration = (%f, %f)", &inputVector.x, &inputVector.y);
                            pPhysics->Acceleration = inputVector;
                            continue;
                        }
                    }

                    if (pCurrComp->Type == Collider)
                    {
                        COLLIDER * pCollider = (COLLIDER*)pCurrComp->pStruct;

                        if (myStrCmp(question, "Offset") <= 0)
                        {
                            sscanf(buffer, "\tOffset = (%f, %f)", &inputVector.x, &inputVector.y);
                            pCollider->Offset = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "Height") <= 0)
                        {
                            sscanf(buffer, "\tHeight = %f", &inputFloat);
                            pCollider->Height = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "Width") <= 0)
                        {
                            sscanf(buffer, "\tWidth = %f", &inputFloat);
                            pCollider->Width = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "IsGhosted") <= 0)
                        {
                            sscanf(buffer, "\tIsGhosted = %i", &inputInt);
                            pCollider->IsGhosted = inputInt;
                            continue;
                        }
                    }

                    if (pCurrComp->Type == KSound)
                    {
                        KSOUND * pSound = (KSOUND*)pCurrComp->pStruct;

                        if (myStrCmp(question, "Volume") <= 0)
                        {
                            sscanf(buffer, "\tVolume = %f", &inputFloat);
                            pSound->Volume = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "Positional") <= 0)
                        {
                            sscanf(buffer, "\tPositional = %i", &inputInt);
                            pSound->Positional = inputInt;
                            continue;
                        }

                        if (myStrCmp(question, "MaxReach") <= 0)
                        {
                            sscanf(buffer, "\tMaxReach = %f", &inputFloat);
                            pSound->MaxReach = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "SoundFile") <= 0)
                        {
                            char scriptInput[MAX_LENGTH];
                            sscanf(buffer, "\tSoundFile = %s", &scriptInput);
                            pSound->SoundFile = scriptInput;
                            continue;
                        }

                        if (myStrCmp(question, "PlayOnStart") <= 0)
                        {
                            sscanf(buffer, "\tPlayOnStart = %i", &inputInt);
                            pSound->PlayOnStart = inputInt;
                            continue;
                        }

                        // TODO : Add the rest of the params.
                    }

                    if (pCurrComp->Type == Sprite)
                    {
                        SPRITE * pSprite = (SPRITE*)pCurrComp->pStruct;
                        if (myStrCmp(question, "TextureFile") <= 0)
                        {
                            int temp;
                            char textureInput[MAX_LENGTH];
                            sscanf(buffer, "\tTextureFile = %i , ", &temp);
                            MultipleAnimations(buffer, temp, pSprite);
                            continue;
                        }

                        if (myStrCmp(question, "Animated") <= 0)
                        {
                            sscanf(buffer, "\tAnimated = %i", &inputInt);
                            pSprite->Animated = inputInt;
                            continue;
                        }

                        if (myStrCmp(question, "RowCol") <= 0)
                        {
                            sscanf(buffer, "\tRowCol = (%f, %f)", &inputVector.x, &inputVector.y);
                            pSprite->RowCol = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "Offset") <= 0)
                        {
                            sscanf(buffer, "\tOffset = (%f, %f)", &inputVector.x, &inputVector.y);
                            pSprite->Offset = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "AnimationSpeed") <= 0)
                        {
                            sscanf(buffer, "\tAnimationSpeed = %f", &inputFloat);
                            pSprite->AnimationSpeed = inputFloat;
                            continue;
                        }
                    }

                    if (myStrCmp(question, "EndComponent") <= 0)
                    {
                        pCurrComp = NULL;
                        continue;
                    }
                }
            }
        }
    }
}
Esempio n. 9
0
void InterpretLevel(FILE * fpLevel)
{
    char buffer[MAX_LENGTH];
    LEVEL * pNewLevel = malloc(sizeof(LEVEL));
    CAMERA * pCam = malloc(sizeof(CAMERA));
    UNIT * pCurrUnit = NULL;
    pCam->Position = NewVector(0, 0);
    pCam->Zoom = 48;
    pNewLevel->Name = "Untitled";
    pNewLevel->Order = 0;
    pNewLevel->pCamera = pCam;
    pNewLevel->nextUnit = NULL;
    pNewLevel->pGame = pTheGame;
    pNewLevel->nextLevel = pTheGame->nextLevel;
    pTheGame->nextLevel = pNewLevel;
    while (!feof(fpLevel))
    {
        if (fgets(buffer, MAX_LENGTH, fpLevel))
        {
            char question[MAX_LENGTH];
            int inputInt = 0;
            float inputFloat = 0.0f;
            VECTOR inputVector = NewVector(0, 0);

            AddNull(buffer);
            if (buffer[0] != '#' && strlen(buffer) > 2)
            {
                sscanf(buffer, "%s", &question);
                if ((myStrCmp(question, "Name") <= 0) && pCurrUnit == NULL)
                {
                    char nameInput[MAX_LENGTH];
                    sscanf(buffer, "Name = %s", nameInput);
                    pNewLevel->Name = myStrCpy(nameInput);
                    continue;
                }

                if (myStrCmp(question, "Order") <= 0)
                {
                    char nameInput[MAX_LENGTH];
                    sscanf(buffer, "Order = %i", &inputInt);
                    pNewLevel->Order = inputInt;
                    continue;
                }

                if (myStrCmp(question, "UNIT") <= 0)
                {
                    char archInput[MAX_LENGTH];
                    char nameInput[MAX_LENGTH];
                    ARCHETYPE * pArchetype = NULL;
                    sscanf(buffer, "UNIT < %s > %s", &archInput, &nameInput);
                    pArchetype = FindArchetypeByName(pTheGame, archInput);
                    pCurrUnit = AddUnit(pNewLevel, pArchetype, myStrCpy(nameInput));
                    continue;
                }

                if (pCurrUnit)
                {
                    if (myStrCmp(question, "Tag") <= 0)
                    {
                        char tagInput[MAX_LENGTH];
                        sscanf(buffer, "\tTag = %s", tagInput);
                        pCurrUnit->Tag = GetTagFromString(tagInput);
                        continue;
                    }

                    if (myStrCmp(question, "InitialPosition") <= 0)
                    {
                        sscanf(buffer, "\tInitialPosition = (%f, %f)", &inputVector.x, &inputVector.y);
                        pCurrUnit->pInitTransform->Position = inputVector;
                        continue;
                    }

                    if (myStrCmp(question, "InitialRotation") <= 0)
                    {
                        sscanf(buffer, "\tInitialRotation = %f", &inputFloat);
                        pCurrUnit->pInitTransform->Rotation = inputFloat;
                        continue;
                    }

                    if (myStrCmp(question, "InitialScale") <= 0)
                    {
                        sscanf(buffer, "\tInitialScale = (%f, %f)", &inputVector.x, &inputVector.y);
                        pCurrUnit->pInitTransform->Scale = inputVector;
                        continue;
                    }

                    if (myStrCmp(question, "VAR") <= 0)
                    {
                        VTYPE theType;
                        VAR * newVar;
                        char varInput[MAX_LENGTH];
                        char typeInput[MAX_LENGTH];
                        char dataInput[MAX_LENGTH];
                        void * data;
                        sscanf(buffer, "\tVAR %s : %s = %s", &varInput, &typeInput, &dataInput);
                        theType = GetVTypeFromString(typeInput);

                        newVar = AddUnitVar(theType, varInput, pCurrUnit);

                        if (theType == Float)
                        {
                            float x;
                            sscanf(dataInput, "%f", &x);
                            data = malloc(sizeof(x));
                            *((float*)newVar->Data) = x;
                        }
                        else if (theType == Int)
                        {
                            int x;
                            sscanf(dataInput, "%i", &x);
                            data = malloc(sizeof(x));
                            *(int*)newVar->Data = x;
                        }
                        else if (theType == Vector)
                        {
                            VECTOR x;
                            sscanf(dataInput, "(%f, %f)", &x.x, &x.y);
                            data = malloc(sizeof(x));
                            *(VECTOR*)newVar->Data = x;
                        }
                        else if (theType == String)
                        {
                            char * x;
                            x = myStrCpy(dataInput);
                            data = malloc(sizeof(x));
                            *(char**)newVar->Data = x;
                        }
                        else if (theType == Bool)
                        {
                            BOOL x;
                            sscanf(dataInput, "%i", &x);
                            data = malloc(sizeof(x));
                            *(BOOL*)newVar->Data = x;
                        }
                        else if (theType == Color)
                        {
                            COLOR x;
                            sscanf(dataInput, "(%f, %f, %f, %f)", &x.r, &x.g, &x.b, &x.a);
                            data = malloc(sizeof(x));
                            *(COLOR*)newVar->Data = x;
                        }
                        else if (theType == Char)
                        {
                            char x;
                            sscanf(dataInput, "%c", &x);
                            data = malloc(sizeof(x));
                            *(char*)newVar->Data = x;
                        }
                        else if (theType == Matrix)
                        {
                            MATRIX x;
                            sscanf(dataInput, "{ {%f, %f, %f} {%f, %f, %f} {%f, %f, %f} }",
                                   &x.m[0][0], &x.m[0][1], &x.m[0][2],
                                   &x.m[1][0], &x.m[1][1], &x.m[1][2],
                                   &x.m[2][0], &x.m[2][1], &x.m[2][2]);
                            data = malloc(sizeof(x));
                            *(MATRIX*)newVar->Data = x;
                        }


                    }
                }


                if (myStrCmp(question, "EndUnit") <= 0)
                {

                    pCurrUnit = NULL;
                    continue;
                }

            }
        }
    }
}
Esempio n. 10
0
void __stdcall CombineCallback(GLdouble coords[3],
  GLdouble *data[4], GLfloat weight[4], GLdouble **dataOut )
{
  GLdouble *vert = NewVector(coords[0], coords[1]);
        *dataOut = vert;
}
static void KIM_Malloc(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    int status;

    mxArray *mx_in[3], *mx_out[2];

    int mxiter, msbset, msbsetsub, etachoice, mxnbcf;
    double eta, egamma, ealpha, mxnewtstep, relfunc, fnormtol, scsteptol;
    booleantype verbose, noInitSetup, noMinEps;

    double *constraints;
    N_Vector NVconstraints;

    int ptype;
    int mudq, mldq, mupper, mlower;
    int maxl, maxrs;
    double dqrely;

    /*
     * -----------------------------
     * Find out the vector type and
     * then pass it to the vector
     * library.
     * -----------------------------
     */

    /* Send vec_type and mx_comm */

    InitVectors();

    /*
     * -----------------------------
     * Extract stuff from arguments:
     * - SYS function
     * - problem dimension
     * - solver options
     * - user data
     * -----------------------------
     */

    /* Matlab user-provided function */

    mxDestroyArray(mx_SYSfct);
    mx_SYSfct = mxDuplicateArray(prhs[0]);

    /* problem dimension */

    N = (int) mxGetScalar(prhs[1]);

    /* Solver Options -- optional argument */

    status = get_SolverOptions(prhs[2],
                               &verbose,
                               &mxiter, &msbset, &msbsetsub, &etachoice, &mxnbcf,
                               &eta, &egamma, &ealpha, &mxnewtstep,
                               &relfunc, &fnormtol, &scsteptol,
                               &constraints,
                               &noInitSetup, &noMinEps);


    /* User data -- optional argument */

    mxDestroyArray(mx_data);
    mx_data = mxDuplicateArray(prhs[3]);

    /*
     * -----------------------------------------------------
     * Set solution vector (used as a template to KINMAlloc)
     * -----------------------------------------------------
     */

    y = NewVector(N);

    /*
     * ----------------------------------------
     * Create kinsol object and allocate memory
     * ----------------------------------------
     */

    kin_mem = KINCreate();

    /* attach error handler function */
    status = KINSetErrHandlerFn(kin_mem, mtlb_KINErrHandler, NULL);

    if (verbose) {
        status = KINSetPrintLevel(kin_mem,3);
        /* attach info handler function */
        status = KINSetInfoHandlerFn(kin_mem, mtlb_KINInfoHandler, NULL);
        /* initialize the output window */
        mx_in[0] = mxCreateScalarDouble(0);
        mx_in[1] = mxCreateScalarDouble(0); /* ignored */
        mx_in[2] = mxCreateScalarDouble(0); /* ignored */
        mexCallMATLAB(1,mx_out,3,mx_in,"kim_info");
        fig_handle = (int)*mxGetPr(mx_out[0]);
    }

    /* Call KINMalloc */

    status = KINMalloc(kin_mem, mtlb_KINSys, y);

    /* Redirect output */
    status = KINSetErrFile(kin_mem, stdout);

    /* Optional inputs */

    status = KINSetNumMaxIters(kin_mem,mxiter);
    status = KINSetNoInitSetup(kin_mem,noInitSetup);
    status = KINSetNoMinEps(kin_mem,noMinEps);
    status = KINSetMaxSetupCalls(kin_mem,msbset);
    status = KINSetMaxSubSetupCalls(kin_mem,msbsetsub);
    status = KINSetMaxBetaFails(kin_mem,mxnbcf);
    status = KINSetEtaForm(kin_mem,etachoice);
    status = KINSetEtaConstValue(kin_mem,eta);
    status = KINSetEtaParams(kin_mem,egamma,ealpha);
    status = KINSetMaxNewtonStep(kin_mem,mxnewtstep);
    status = KINSetRelErrFunc(kin_mem,relfunc);
    status = KINSetFuncNormTol(kin_mem,fnormtol);
    status = KINSetScaledStepTol(kin_mem,scsteptol);
    if (constraints != NULL) {
        NVconstraints = N_VCloneEmpty(y);
        N_VSetArrayPointer(constraints, NVconstraints);
        status = KINSetConstraints(kin_mem,NVconstraints);
        N_VDestroy(NVconstraints);
    }

    status = get_LinSolvOptions(prhs[2],
                                &mupper, &mlower,
                                &mudq, &mldq, &dqrely,
                                &ptype, &maxrs, &maxl);

    switch (ls) {

    case LS_NONE:

        mexErrMsgTxt("KINMalloc:: no linear solver specified.");

        break;

    case LS_DENSE:

        status = KINDense(kin_mem, N);
        if (!mxIsEmpty(mx_JACfct))
            status = KINDenseSetJacFn(kin_mem, mtlb_KINDenseJac, NULL);

        break;

    case LS_BAND:

        status = KINBand(kin_mem, N, mupper, mlower);
        if (!mxIsEmpty(mx_JACfct))
            status = KINBandSetJacFn(kin_mem, mtlb_KINBandJac, NULL);

        break;

    case LS_SPGMR:

        switch(pm) {
        case PM_NONE:
            status = KINSpgmr(kin_mem, maxl);
            if (!mxIsEmpty(mx_PSOLfct)) {
                if (!mxIsEmpty(mx_PSETfct))
                    status = KINSpilsSetPreconditioner(kin_mem, mtlb_KINSpilsPset, mtlb_KINSpilsPsol, NULL);
                else
                    status = KINSpilsSetPreconditioner(kin_mem, NULL, mtlb_KINSpilsPsol, NULL);
            }
            break;
        case PM_BBDPRE:
            if (!mxIsEmpty(mx_GCOMfct))
                bbd_data = KINBBDPrecAlloc(kin_mem, N, mudq, mldq, mupper, mlower, dqrely, mtlb_KINGloc, mtlb_KINGcom);
            else
                bbd_data = KINBBDPrecAlloc(kin_mem, N, mudq, mldq, mupper, mlower, dqrely, mtlb_KINGloc, NULL);
            status = KINBBDSpgmr(kin_mem, maxl, bbd_data);
            break;
        }

        status = KINSpilsSetMaxRestarts(kin_mem, maxrs);

        if (!mxIsEmpty(mx_JACfct))
            status = KINSpilsSetJacTimesVecFn(kin_mem, mtlb_KINSpilsJac, NULL);

        break;

    case LS_SPBCG:

        switch(pm) {
        case PM_NONE:
            status = KINSpbcg(kin_mem, maxl);
            if (!mxIsEmpty(mx_PSOLfct)) {
                if (!mxIsEmpty(mx_PSETfct))
                    status = KINSpilsSetPreconditioner(kin_mem, mtlb_KINSpilsPset, mtlb_KINSpilsPsol, NULL);
                else
                    status = KINSpilsSetPreconditioner(kin_mem, NULL, mtlb_KINSpilsPsol, NULL);
            }
            break;
        case PM_BBDPRE:
            if (!mxIsEmpty(mx_GCOMfct))
                bbd_data = KINBBDPrecAlloc(kin_mem, N, mudq, mldq, mupper, mlower, dqrely, mtlb_KINGloc, mtlb_KINGcom);
            else
                bbd_data = KINBBDPrecAlloc(kin_mem, N, mudq, mldq, mupper, mlower, dqrely, mtlb_KINGloc, NULL);
            status = KINBBDSpbcg(kin_mem, maxl, bbd_data);
            break;
        }

        if (!mxIsEmpty(mx_JACfct))
            status = KINSpilsSetJacTimesVecFn(kin_mem, mtlb_KINSpilsJac, NULL);

        break;

    case LS_SPTFQMR:

        switch(pm) {
        case PM_NONE:
            status = KINSptfqmr(kin_mem, maxl);
            if (!mxIsEmpty(mx_PSOLfct)) {
                if (!mxIsEmpty(mx_PSETfct))
                    status = KINSpilsSetPreconditioner(kin_mem, mtlb_KINSpilsPset, mtlb_KINSpilsPsol, NULL);
                else
                    status = KINSpilsSetPreconditioner(kin_mem, NULL, mtlb_KINSpilsPsol, NULL);
            }
            break;
        case PM_BBDPRE:
            if (!mxIsEmpty(mx_GCOMfct))
                bbd_data = KINBBDPrecAlloc(kin_mem, N, mudq, mldq, mupper, mlower, dqrely, mtlb_KINGloc, mtlb_KINGcom);
            else
                bbd_data = KINBBDPrecAlloc(kin_mem, N, mudq, mldq, mupper, mlower, dqrely, mtlb_KINGloc, NULL);
            status = KINBBDSptfqmr(kin_mem, maxl, bbd_data);
            break;
        }

        if (!mxIsEmpty(mx_JACfct))
            status = KINSpilsSetJacTimesVecFn(kin_mem, mtlb_KINSpilsJac, NULL);

        break;

    }

    return;
}
Esempio n. 12
0
void * AddVar(VTYPE Type, char * Name, BEHAVIOR * Owner)
{
  VAR * pNewVar = malloc(sizeof(VAR));
  pNewVar->Name = myStrCpy(Name);
  pNewVar->Type = Float;
  pNewVar->nextVar = NULL;

  // NOTE: SHOULD MAKE A SWITCH CASE. MUCH CLEANER (AND SOMETIMES FASTER!)
  if (Type == Int)
  {
    int *x = malloc(sizeof(int));
    *x = 0;
    pNewVar->Data = x;
  }
  else if (Type == Float)
  {
    float *x = malloc(sizeof(float));
    *x = 0.0;
    pNewVar->Data = x;
  }
  else if (Type == Vector)
  {
    VECTOR *x = malloc(sizeof(VECTOR));
    *x = NewVector(0,0);
    pNewVar->Data = x;
  }
  else if (Type == String)
  {
    char **x = malloc(sizeof(char*));
    *x = NULL;
    pNewVar->Data = x;
  }
  else if (Type == Color)
  {
    COLOR newCol = { 1, 1, 1, 1 };
    COLOR *x = malloc(sizeof(COLOR));
    *x = newCol;
    pNewVar->Data = x;
  }
  else if (Type == Bool)
  {
    BOOL *x = malloc(sizeof(BOOL));
    *x = False;
    pNewVar->Data = x;
  }
  else if (Type == Char)
  {
    char *x = malloc(sizeof(char));
    *x = '\0';
    pNewVar->Data = x;
  }
  else if (Type == Matrix)
  {
    MATRIX *temp = (MATRIX*)malloc(sizeof(MATRIX));
    SecureZeroMemory(temp->m, sizeof(float)* 9);
    pNewVar->Data = temp;
  }
  pNewVar->nextVar = Owner->nextVar;
  Owner->nextVar = pNewVar;
  return pNewVar->Data;
}
Esempio n. 13
0
COMPONENT * AddComponent(ARCHETYPE *pArchetype, COMPONENTTYPE DesiredType)
{
  COMPONENT * pNewComponent = calloc(1, sizeof(COMPONENT));
  pNewComponent->pArchetype = pArchetype;
  pNewComponent->nextComponent = pArchetype->nextComponent;
  pArchetype->nextComponent = pNewComponent;

  if (DesiredType == Sprite) {
	  SPRITE * pNewSprite = calloc(1, sizeof(SPRITE));
	  IMAGE * pImage = calloc(1, sizeof(IMAGE));
    pNewSprite->Visible = True;
	  pImage->pNextImage = NULL;
	  pNewComponent->Type = Sprite;
	  *pNewSprite = *(pArchetype->pGame->pGameStats->pDefaultSprite);
		pNewSprite->pImage = pImage;
		pNewSprite->CurrentAnimation = "Blank.png";
	  pNewComponent->pStruct = pNewSprite;
	  pNewSprite->pImage->TextureFile = NULL;
	  pNewSprite->pComponent = pNewComponent;
	  pNewSprite->pArchetype = pArchetype;
  }

  if (DesiredType == Mesh)
  {
    MESH * pNewMesh = calloc(1, sizeof(MESH));
    pNewComponent->Type = Mesh;
    *pNewMesh = *(pArchetype->pGame->pGameStats->pDefaultMesh);
    pNewMesh->Color = NewColor(1, 1, 1, 1);
    pNewMesh->Opacity = 1.0;
    pNewComponent->pStruct = pNewMesh;
    pNewMesh->pComponent = pNewComponent;
    pNewMesh->pArchetype = pArchetype;
  }

  if (DesiredType == Behavior)
  {
    BEHAVIOR * pNewBehavior = calloc(1, sizeof(BEHAVIOR));
    pNewComponent->Type = Behavior;
    pNewComponent->pStruct = pNewBehavior;
    pNewBehavior->BehaviorScript = DefaultBehavior;
    pNewBehavior->pComponent = pNewComponent;
    pNewBehavior->pArchetype = pArchetype;
  }

  if (DesiredType == Physics)
  {
    PHYSICS * pNewPhysics = calloc(1, sizeof(PHYSICS));

    pNewComponent->Type = Physics;
    pNewComponent->pStruct = pNewPhysics;

    pNewPhysics->Velocity = NewVector(0, 0);
    pNewPhysics->Acceleration = NewVector(0, 0);
    pNewPhysics->Gravity = 0.5;
    pNewPhysics->Friction = 0.1f;
    pNewPhysics->MaxSpeed = 0.5;

    pNewPhysics->pComponent = pNewComponent;
    pNewPhysics->pArchetype = pArchetype;
  }

  if (DesiredType == Collider)
  {
    COLLIDER * pNewCollider = calloc(1, sizeof(COLLIDER));
    
    pNewComponent->Type = Collider;
    pNewComponent->pStruct = pNewCollider;
    
    pNewCollider->Enabled = True;
    pNewCollider->Offset = NewVector(0, 0);
    pNewCollider->Height = 1;
    pNewCollider->Width = 1;
        
    pNewCollider->pComponent = pNewComponent;
    pNewCollider->pArchetype = pArchetype;
  }

  if (DesiredType == KSound)
  {
    KSOUND * pNewSound = calloc(1, sizeof(KSOUND));
	KSOUND_Init(pNewSound);
    
	pNewComponent->Type = KSound;
    pNewComponent->pStruct = pNewSound;

	// Generic component stuff.
    pNewSound->pComponent = pNewComponent;
    pNewSound->pArchetype = pArchetype;
  }

  return pNewComponent;
}