Beispiel #1
0
BOOL RectangleRecordHandler::ReadRectangleComplexRoundedReformed(CXaraFileRecord *pCXaraFileRecord)
{
	BOOL ok = TRUE;

	NodeRegularShape * pRectangle;
	DocCoord MajorAxis;
	DocCoord MinorAxis;
	Matrix TransformMatrix;
	double Curvature;
	
	pRectangle = new NodeRegularShape;

	if (ok) ok = SetupShape(pRectangle);
	if (ok) ok = SetNumberOfSides(pRectangle, NumberOfSides);
	if (ok) ok = SetIsRounded(pRectangle, TRUE);

	if (ok) ok = pCXaraFileRecord->ReadCoordTrans(&MajorAxis,0,0);
	if (ok) ok = SetMajorAxis(pRectangle, MajorAxis);

	if (ok) ok = pCXaraFileRecord->ReadCoordTrans(&MinorAxis,0,0);
	if (ok) ok = SetMinorAxis(pRectangle, MinorAxis);

	if (ok) ok = pCXaraFileRecord->ReadMatrix(&TransformMatrix);
	if (ok) ok = SetTransformMatrix(pRectangle, TransformMatrix);

	if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&Curvature);
	if (ok) ok = SetCurvature(pRectangle, Curvature);

	if (ok) ok = pCXaraFileRecord->ReadPath(&(pRectangle->EdgePath1));

	if (ok) ok = InvalidateCache(pRectangle);
	if (ok) ok = InsertNode(pRectangle);

	return ok;
}
Beispiel #2
0
BOOL RegularShapeRecordHandler::ReadShapeGeneralPhase1(CXaraFileRecord *pCXaraFileRecord)
{
	BOOL ok = TRUE;

	NodeRegularShape * pShape;
	BYTE Flags;
	UINT16 NumberOfSides;
	DocCoord UTCentrePoint;
	DocCoord MajorAxis;
	DocCoord MinorAxis;
	Matrix TransformMatrix;
	double StellationRadius;
	double StellationOffset;
	double PrimaryCurvature;
	double SecondaryCurvature;
	
	pShape = new NodeRegularShape;

	if (ok) ok = SetupShape(pShape);

	if (ok) ok = pCXaraFileRecord->ReadBYTE(&Flags);
	if (ok) ok = SetFlags(pShape, Flags);
	
	if (ok) ok = pCXaraFileRecord->ReadUINT16(&NumberOfSides);
	if (ok) ok = SetNumberOfSides(pShape, NumberOfSides);

	if (ok) ok = pCXaraFileRecord->ReadCoordTrans(&UTCentrePoint,0,0);
	if (ok) ok = SetUTCentrePoint(pShape, UTCentrePoint);

	if (ok) ok = pCXaraFileRecord->ReadCoordTrans(&MajorAxis,0,0);
	if (ok) ok = SetMajorAxis(pShape, MajorAxis);

	if (ok) ok = pCXaraFileRecord->ReadCoordTrans(&MinorAxis,0,0);
	if (ok) ok = SetMinorAxis(pShape, MinorAxis);

	if (ok) ok = pCXaraFileRecord->ReadMatrix(&TransformMatrix);
	if (ok) ok = SetTransformMatrix(pShape, TransformMatrix);

	if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&StellationRadius);
	if (ok) ok = SetStellationRadius(pShape, StellationRadius);

	if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&StellationOffset);
	if (ok) ok = SetStellationOffset(pShape, StellationOffset);

	if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&PrimaryCurvature);
	if (ok) ok = SetPrimaryCurvature(pShape, PrimaryCurvature);

	if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&SecondaryCurvature);
	if (ok) ok = SetSecondaryCurvature(pShape, SecondaryCurvature);

	if (ok) ok = pCXaraFileRecord->ReadPath(&(pShape->EdgePath1));
	if (ok) ok = pCXaraFileRecord->ReadPath(&(pShape->EdgePath2));
	
	if (ok) ok = InvalidateCache(pShape);
	if (ok) ok = InsertNode(pShape);

	return ok;
}
Beispiel #3
0
BOOL RectangleRecordHandler::ReadRectangleComplexRoundedStellatedReformed(CXaraFileRecord *pCXaraFileRecord)
{
	BOOL ok = TRUE;

	NodeRegularShape * pRectangle;
	DocCoord MajorAxis;
	DocCoord MinorAxis;
	Matrix TransformMatrix;
	double StellationRadius;
	double StellationOffset;
	double PrimaryCurvature;
	double SecondaryCurvature;
	
	pRectangle = new NodeRegularShape;

	if (ok) ok = SetupShape(pRectangle);
	if (ok) ok = SetNumberOfSides(pRectangle, NumberOfSides);
	if (ok) ok = SetIsRounded(pRectangle, TRUE);
	if (ok) ok = SetIsStellated(pRectangle, TRUE);

	if (ok) ok = pCXaraFileRecord->ReadCoordTrans(&MajorAxis,0,0);
	if (ok) ok = SetMajorAxis(pRectangle, MajorAxis);

	if (ok) ok = pCXaraFileRecord->ReadCoordTrans(&MinorAxis,0,0);
	if (ok) ok = SetMinorAxis(pRectangle, MinorAxis);

	if (ok) ok = pCXaraFileRecord->ReadMatrix(&TransformMatrix);
	if (ok) ok = SetTransformMatrix(pRectangle, TransformMatrix);

	if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&StellationRadius);
	if (ok) ok = SetStellationRadius(pRectangle, StellationRadius);

	if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&StellationOffset);
	if (ok) ok = SetStellationOffset(pRectangle, StellationOffset);

	if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&PrimaryCurvature);
	if (ok) ok = SetPrimaryCurvature(pRectangle, PrimaryCurvature);

	if (ok) ok = pCXaraFileRecord->ReadDOUBLE(&SecondaryCurvature);
	if (ok) ok = SetSecondaryCurvature(pRectangle, SecondaryCurvature);

	if (ok) ok = pCXaraFileRecord->ReadPath(&(pRectangle->EdgePath1));
	if (ok) ok = pCXaraFileRecord->ReadPath(&(pRectangle->EdgePath2));
	
	if (ok) ok = InvalidateCache(pRectangle);
	if (ok) ok = InsertNode(pRectangle);

	return ok;
}
Beispiel #4
0
void SetModelMatrices()
{
	Matrix matWorld, rotMatrix, transMatrix, scaleMatrix;
	CreateRotationYMatrix(&rotMatrix, (timeGetTime()%2000)*(2.0f*M_PI)/2000.0f);
	CreateTranslationMatrix(&transMatrix, 0.0f, ytranslation, 0.0f);
	CreateScaleMatrix(&scaleMatrix, scaling, scaling, scaling);
	MultiplyMatrices(&matWorld, &rotMatrix, &transMatrix);
	//MultiplyMatrices(&matWorld, &matWorld, &scaleMatrix);
	matWorld *= scaleMatrix;
	Matrix finalmatrix = matWorld;

	Vector3 vEyePt( 0.0f, 18.0f,-20.0f );
	Vector3 vLookatPt( 0.0f, 0.0f, 0.0f );
	Vector3 vUpVec( 0.0f, 1.0f, 0.0f );
	Matrix matView;
	CreateLookAtLHViewMatrix( &matView, &vEyePt, &vLookatPt, &vUpVec );
	finalmatrix *= matView;

	Matrix matProj;
	CreatePerspectiveMatrix( &matProj, M_PI / 4, 1.0f, 1.0f, 100.0f );
	finalmatrix *= matProj;

	SetTransformMatrix(&finalmatrix);
}
Beispiel #5
0
void DrawOOBM()
{
	uint tt = timeGetTime();
	renderer->BeginBatchDrawing();
	SetTransformMatrix(&vpmatrix);
	mshbatch->begin();
	for(int t = 0; t < strMaterials.len; t++)
	{
		int txset = 0;
		for(int a = 0; a < 2; a++)
		{
			int afset = 0;
			GrowList<GameObject*> *l = 0; // = &((oobm[a])[t]);
			for(int i = 0; i < oobm[a].len; i++)
				if(oobm[a].getpnt(i)->tid == t)
					{l = oobm[a].getpnt(i)->objs; break;}
			if(!l) continue;

			for(int i = 0; i < l->len; i++)
			{
				GameObject *o = l->get(i);

				int dif = -1;
				if((o->flags & FGO_SELECTED) || (currentSelection == o))
				{
					if((o->flags & FGO_SELECTED) && (currentSelection == o))
						dif = 0xFFFF00FF;
					else
						dif = (currentSelection==o)?0xFFFF0000:0xFF0000FF;
				}

				//Model *md = o->objdef->subtypes[o->subtype].appear[o->appearance].def;
				Model *md = GetObjectModel(o);
				if(showrepresentations && o->objdef->representation) md = o->objdef->representation;
				md->prepare(); md->mesh->prepare();
				Mesh *msh = md->mesh;
				// If md != md->mesh, this means that md is an Anim!
				SetMatrices(o->scale, -o->orientation, o->position);
				Matrix mWorldCopy = mWorld;

				uint tm = (int)(current_time*1000.0f) - o->animtimeref;
				// If the current task has SYNCH_ANIMATION_TO_FRACTION, use it.
				if(md != md->mesh) if(o->ordercfg.order.len)
				{
					STask *st = &o->ordercfg.order.first->value.task.first->value;
					if(st->type->satf)
					{
						SequenceEnv env; env.self = o;
						tm = st->type->satf->get(&env) * ((Anim*)md)->dur;
						tm = st->lastsatf + (tm - st->lastsatf) * elapsed_time * 0.5f;
						if(tm >= ((Anim*)md)->dur) tm = ((Anim*)md)->dur - 1;
						st->lastsatf = tm;
					}
				}
				if(o->animlooping) if(md != md->mesh)
					tm %= ((Anim*)md)->dur;

				for(int g = 0; g < msh->ngrp; g++)
					if((msh->lstmatflags[g] == a) && (msh->lstmattid[g] == t))
					{
						if(!txset) {txset = 1; SetTexture(0, msh->lstmattex[g]);}
						if(!afset) {afset = 1; if(a) renderer->EnableAlphaTest(); else renderer->DisableAlphaTest();}

						(animsEnabled?md:md->mesh)->drawInBatch(mshbatch, g, o->color, dif, tm);
					}

				for(int j = 0; j < msh->nAttachPnts; j++)
					if(msh->attachPnts[j].model)
					if(md->isAttachPointOn(j, tm))
					{
						Model *apmd = msh->attachPnts[j].model;
						Mesh *apms = apmd->mesh;
						for(int g = 0; g < apms->ngrp; g++)
							if((apms->lstmatflags[g] == a) && (apms->lstmattid[g] == t))
							{
								if(!txset) {txset = 1; SetTexture(0, apms->lstmattex[g]);}
								if(!afset) {afset = 1; if(a) renderer->EnableAlphaTest(); else renderer->DisableAlphaTest();}

								uint aptm = current_time * 1000;
								if(apmd != apmd->mesh)
									aptm %= ((Anim*)apmd)->dur;

								Vector3 p, s;
								md->getAttachPointPos(&s, j, tm);
								TransformVector3(&p, &s, &mWorldCopy);
								SetMatrices(Vector3(1,1,1), Vector3(0,0,0), p);

								(animsEnabled?apmd:apms)->drawInBatch(mshbatch, g, o->color, dif, aptm);
							}
					}
			}

			l->clear();
			mshbatch->flush();
		}
		mshbatch->flush();
	}
	mshbatch->end();
}
Beispiel #6
0
void DrawScene()
{
	BeginMeshDrawing();
	if(fogenabled) SetFog();
	SetConstantMatrices();

	newSelection = -1; SetMatrices(onevector, nullvector, nullvector); CalcRay();
	newSelZ = -1;
	DrawObj(levelobj);
	if(currentSelection.get() != newSelection.get())
	{
		currentSelection = newSelection;
		//printf("New selection: %i\n", newSelection);
	}

	if(meshbatching) DrawOOBM();

if(experimentalKeys) {
	// Stampdown
	CalcStampdownPos();
/*
	int od;
	if((od = FindObjDef(CLASS_CHARACTER, "Archer")) != -1)
	{
		if(stdownvalid)
		{
			renderer->BeginMeshDrawing();
			SetMatrices(onevector, nullvector, stdownpos);
			SetTransformMatrix(&matrix);
			objdef[od].subtypes[0].appear[0].def->draw(0);
			//sprintf(statustextbuf, "stdownpos = (%f, %f, %f)", stdownpos.x, stdownpos.y, stdownpos.z);
			//sprintf(statustextbuf, "raydir = (%f, %f, %f)", raydir.x, raydir.y, raydir.z);
			//sprintf(statustextbuf, "raystart = (%f, %f, %f)", raystart.x, raystart.y, raystart.z);
		}
		//else	strcpy(statustextbuf, "Invalid stampdown position.");
		//statustext = statustextbuf;
	}
*/
	if(objtypeToStampdown)
	if(stdownvalid)
	if(playerToGiveStampdownObj.valid())
	{
		// Align buildings in the grid.
		AlignObjPosToGrid(objtypeToStampdown, stdownpos, stampdownRot);
		Model *m = GetObjTypeDefaultModel(objtypeToStampdown);
		if(m)
		{
			renderer->BeginMeshDrawing();
			SetMatrices(objtypeToStampdown->scale, Vector3(0,-stampdownRot,0), stdownpos);
			SetTransformMatrix(&matrix);
			m->draw(playerToGiveStampdownObj->color);
		}
	}
	int moti;
	if(mousetool == 7)
	if(stdownvalid)
	if(newmanorplayer.valid())
	if((moti = FindObjDef(CLASS_BUILDING, "Manor")) != -1)
	{
		CObjectDefinition *cod = &(objdef[moti]);
		// Align buildings in the grid.
		stdownpos.x = (int)(stdownpos.x / 5) * 5.0f + 2.5f;
		stdownpos.z = (int)(stdownpos.z / 5) * 5.0f + 2.5f;
		stdownpos.y = GetHeight(stdownpos.x, stdownpos.z);
		Model *m = GetObjTypeDefaultModel(cod);
		if(m)
		{
			renderer->BeginMeshDrawing();
			SetMatrices(cod->scale, Vector3(0,-stampdownRot,0), stdownpos);
			SetTransformMatrix(&matrix);
			m->draw(newmanorplayer->color);
		}
	}
}

	if(enableMap)
	{
		SetMatrices(Vector3(5.0f, 1.0f, -5.0f), nullvector, Vector3(-mapedge*5,0,+mapheight*5-mapedge*5));
		SetTransformMatrix(&matrix);
		DrawMap();
		DrawTileHighlights();
		DrawLakes();
	}
	drawdebug = 0;
	if(fogenabled) DisableFog();
}
Beispiel #7
0
void DrawObj(GameObject *o)
{
	float pntz;
	if((o->renderable && o->objdef->subtypes[o->subtype].appear[o->appearance].def)
	  || (showrepresentations && o->objdef->representation))
	{
		if(IsPointOnScreen(o->position, &pntz))
		{
			//Model *md = o->objdef->subtypes[o->subtype].appear[o->appearance].def;
			Model *md = GetObjectModel(o);
			if(showrepresentations && o->objdef->representation) md = o->objdef->representation;
			md->prepare(); md->mesh->prepare();
			Mesh *msh = md->mesh;
			objsdrawn++;
			SetMatrices(o->scale, -o->orientation, o->position);

			Vector3 sphPos = o->position;
			sphPos.y += msh->sphere[1] * o->scale.y;
			if((newSelZ == -1) || (pntz < newSelZ))
			if(SphereIntersectsRay(&sphPos, msh->sphere[3]*o->scale.y/2.0f, &raystart, &raydir))
				{newSelection = o; newSelZ = pntz;}

			if(multiSel)
			{
				Vector3 tdp;
				TransformCoord3(&tdp, &nullvector, &matrix);
				float ba = (float)((mselx<mouseX)?mselx:mouseX) * 2.0f / scrw - 1;
				float bb = (float)((msely<mouseY)?msely:mouseY) * 2.0f / scrh - 1;
				float bc = (float)((mselx>mouseX)?mselx:mouseX) * 2.0f / scrw - 1;
				float bd = (float)((msely>mouseY)?msely:mouseY) * 2.0f / scrh - 1;
				if((tdp.x >= ba) && (tdp.x <= bc) &&
				   (-tdp.y >= bb) && (-tdp.y <= bd))
					msellist.add(o);
			}

			if(!meshbatching)
			{
				if((o->flags & FGO_SELECTED) || (currentSelection == o))
				{
					renderer->EnableColorBlend();
					if((o->flags & FGO_SELECTED) && (currentSelection == o))
						renderer->SetBlendColor(0xFFFF00FF);
					else
						renderer->SetBlendColor((currentSelection==o)?0xFFFF0000:0xFF0000FF);
				}
				SetTransformMatrix(&matrix);
				msh->draw(o->color);
				if((o->flags & FGO_SELECTED) || (currentSelection == o))
					renderer->DisableColorBlend();
			}
			else
			{
			auto f = [o](Mesh *msh)
			{
				msh->prepare();
				for(int i = 0; i < msh->ngrp; i++)
				{
					OOBMTex *ot;
					int f = msh->lstmatflags[i]&1;
					int t = msh->lstmattid[i];
					for(int j = 0; j < oobm[f].len; j++)
					{
						ot = oobm[f].getpnt(j);
						if(ot->tid == t)
							{ot->objs->add(o); goto nextgrp;}
					}
					ot = oobm[f].addp();
					ot->tid = t;
					ot->objs = new GrowList<GameObject*>;
					ot->objs->add(o);
				nextgrp: ;
				}
			};
				f(msh);
				for(int i = 0; i < msh->nAttachPnts; i++)
					if(msh->attachPnts[i].model)
						f(msh->attachPnts[i].model->mesh);
			}
		}
	}

	for(DynListEntry<GameObject> *e = o->children.first; e; e = e->next)
		DrawObj(&e->value);
}