Example #1
0
TVector3 Str_Vector3N (const string &s) {
	float x, y, z;
	istringstream is(s);
	is >> x >> y >> z;
	if (is.fail()) return MakeVector (0, 0, 0);
	else return MakeVector (x, y, z);
}
Example #2
0
bool MFCollision_RayBoxTest(const MFVector& rayPos, const MFVector& rayDir, const MFVector& boxPos, const MFVector& boxRadius, MFRayIntersectionResult *pResult)
{
	MFVector plane[6];
	plane[0] = MakeVector(MFVector::up, boxPos.x + boxRadius.x);
	plane[1] = MakeVector(-MFVector::up, boxPos.x - boxRadius.x);
	return false;
}
Example #3
0
bool IntersectPolygon (TPolygon p, TVector3 *v) {
    TRay ray; 
    TVector3 nml, edge_nml, edge_vec;
    TVector3 pt;
    double d, s, nuDotProd, wec;
    double edge_len, t, distsq;
    int i;

    nml = MakeNormal (p, v);
    ray.pt = MakeVector (0., 0., 0.);
    ray.vec = nml;

    nuDotProd = DotProduct (nml, ray.vec);
    if  (fabs(nuDotProd) < EPS)
        return false;

    d = - (nml.x * v[p.vertices[0]].x + 
           nml.y * v[p.vertices[0]].y + 
           nml.z * v[p.vertices[0]].z);

    if  (fabs (d) > 1) return false;

    for  (i=0; i < p.num_vertices; i++) {
		TVector3 *v0, *v1;

		v0 = &v[p.vertices[i]];
		v1 = &v[p.vertices[ (i+1) % p.num_vertices ]]; 

		edge_vec = SubtractVectors (*v1, *v0);
		edge_len = NormVector (&edge_vec);

		t = - DotProduct (*((TVector3 *) v0), edge_vec);

		if  (t < 0) {
			distsq = MAG_SQD2 (*v0);
		} else if  (t > edge_len) {
			distsq = MAG_SQD2 (*v1);
		} else {
			*v0 = AddVectors (*v0, ScaleVector (t, edge_vec));
			distsq = MAG_SQD2 (*v0);
		}

		if  (distsq <= 1) return true;
    }

    s = - (d + DotProduct (nml, MakeVector (ray.pt.x, ray.pt.y, ray.pt.z))) / nuDotProd;
    pt = AddVectors (ray.pt, ScaleVector (s, ray.vec));

    for  (i=0; i < p.num_vertices; i++) {
        edge_nml = CrossProduct (nml, 
            SubtractVectors (v[p.vertices[ (i+1) % p.num_vertices ]], v[p.vertices[i]]));

        wec = DotProduct (SubtractVectors (pt, v[p.vertices[i]]), edge_nml);
        if (wec < 0) return false;
    } 
    return true;
} 
Example #4
0
void make_view_matrix(Vec p1, Vec p2, Matrix m)
{
	Flt d, len, l1;
	Vec up, out, left;
	Vec upv={0,1,0};

	//Log( "make_view_matrix()...\n");
	//Line between p1 and p2 form a LOS Line-of-sight.
	//A rotation matrix is built to transform objects to this LOS.
	//
	//Diana Gruber
	//http://www.makegames.com/3Drotation/
	//
	m[0][0]=1.0; m[0][1]=0.0; m[0][2] =0.0;
	m[1][0]=0.0; m[1][1]=1.0; m[1][2] =0.0;
	m[2][0]=0.0; m[2][1]=0.0; m[2][2] =1.0;
	VecSub(p2, p1, out);
	//
	len = out[0]*out[0] + out[1]*out[1] + out[2]*out[2];
	if (len == 0.0) {
		MakeVector(0.0,0.0,1.0,out);
	}
	else {
		l1 = 1.0 / sqrt(len);
		out[0] *= l1;
		out[1] *= l1;
		out[2] *= l1;
	}
	//
	m[2][0] = out[0];
	m[2][1] = out[1];
	m[2][2] = out[2];
	//
	d = out[0] * upv[0] + out[1] * upv[1] + out[2] * upv[2]; 
	up[0] = upv[0] - d * out[0];
	up[1] = upv[1] - d * out[1];
	up[2] = upv[2] - d * out[2];
	len = up[0]*up[0] + up[1]*up[1] + up[2]*up[2];
	if (len == 0.0) {
		MakeVector(0, 0, 1, up);
	} else {
		l1 = 1.0 / sqrt(len);
		up[0] *= l1;
		up[1] *= l1;
		up[2] *= l1;
	}
	m[1][0] = up[0];
	m[1][1] = up[1];
	m[1][2] = up[2];
	//make left vector.
	VecCross(up, out, left);
	m[0][0] = left[0];
	m[0][1] = left[1];
	m[0][2] = left[2];
}
Example #5
0
float MenuItemColour::ListDraw(bool selected, const MFVector &_pos, float maxWidth)
{
	MFVector pos = _pos;

	MFFont_DrawText(MFFont_GetDebugFont(), pos+MakeVector(0.0f, MENU_FONT_HEIGHT*0.25f, 0.0f), MENU_FONT_HEIGHT, selected ? MakeVector(1,1,0,1) : MFVector::one, MFStr("%s: 0x%08X", name, pData->ToPackedColour()));

	pos += MakeVector(maxWidth - 55.0f, 2.0f, 0.0f);

	MFPrimitive(PT_TriStrip|PT_Untextured);

	MFBegin(4);
	MFSetColourV(MFVector::white);
	MFSetPositionV(pos);
	MFSetPositionV(pos + MakeVector(45.0f, 0.0f, 0.0f));
	MFSetPositionV(pos + MakeVector(0.0f, MENU_FONT_HEIGHT*1.5f-4.0f, 0.0f));
	MFSetPositionV(pos + MakeVector(45.0f, MENU_FONT_HEIGHT*1.5f-4.0f, 0.0f));
	MFEnd();

	pos += MakeVector(2.0f, 2.0f, 0.0f);

	MFBegin(4);
	MFSetColourV(*pData);
	MFSetPositionV(pos);
	MFSetPositionV(pos + MakeVector(41.0f, 0.0f, 0.0f));
	MFSetPositionV(pos + MakeVector(0.0f, MENU_FONT_HEIGHT*1.5f-8.0f, 0.0f));
	MFSetPositionV(pos + MakeVector(41.0f, MENU_FONT_HEIGHT*1.5f-8.0f, 0.0f));
	MFEnd();

	return MENU_FONT_HEIGHT*1.5f;
}
Example #6
0
void EditorScreen::Draw()
{
	GHScreen::DrawScreens();	

	MFRenderer_ClearScreen(MFRCF_Depth);

	MFMatrix mat;
	mat.LookAt(MakeVector(2.0,1.5,-1.0), MakeVector(1.0,0.3f,1.0f));
	MFView_SetCameraMatrix(mat);
//	pScene->Draw();
}
Example #7
0
void MFCallstackInternal_DrawMeterLabel(const MFVector &listPos, const MFVector &colour, const char *pString, const char *pStats)
{
    MFPrimitive_DrawUntexturedQuad(listPos.x, listPos.y + 1.0f, listPos.x + 14.0f, listPos.y + 15.0f, MFVector::one);
    MFPrimitive_DrawUntexturedQuad(listPos.x + 2, listPos.y + 3.0f, listPos.x + 12.0f, listPos.y + 13.0f, colour);
    MFFont_DrawTextf(MFFont_GetDebugFont(), listPos + MakeVector(16.0f, 0.0f, 0.0f), 16.0f, MFVector::one, pString);

    if(pStats)
    {
        float width = (float)MFDisplay_GetDisplaySettings()->width;
        MFFont_DrawTextf(MFFont_GetDebugFont(), listPos + MakeVector((width - listPos.x) - 250.0f, 0.0f, 0.0f), 16.0f, MFVector::one, pStats);
    }
}
Example #8
0
void CCharShape::AdjustOrientation (CControl *ctrl, double dtime,
		 double dist_from_surface, TVector3 surf_nml) {
    TVector3 new_x, new_y, new_z; 
    TMatrix cob_mat, inv_cob_mat;
    TMatrix rot_mat;
    TQuaternion new_orient;
    double time_constant;
    static TVector3 minus_z_vec = { 0, 0, -1};
    static TVector3 y_vec = { 0, 1, 0 };

    if  (dist_from_surface > 0) {
		new_y = ScaleVector (1, ctrl->cvel);
		NormVector (&new_y);
		new_z = ProjectToPlane (new_y, MakeVector(0, -1, 0));
		NormVector (&new_z);
		new_z = AdjustRollvector (ctrl, ctrl->cvel, new_z);
    } else { 
		new_z = ScaleVector (-1, surf_nml);
		new_z = AdjustRollvector (ctrl, ctrl->cvel, new_z);
		new_y = ProjectToPlane (surf_nml, ScaleVector (1, ctrl->cvel));
		NormVector(&new_y);
    }

    new_x = CrossProduct (new_y, new_z);
    MakeBasismatrix_Inv (cob_mat, inv_cob_mat, new_x, new_y, new_z);
    new_orient = MakeQuaternionFromMatrix (cob_mat);

    if (!ctrl->orientation_initialized) {
		ctrl->orientation_initialized = true;
		ctrl->corientation = new_orient;
    }

    time_constant = dist_from_surface > 0 ? TO_AIR_TIME : TO_TIME;

    ctrl->corientation = InterpolateQuaternions (
			ctrl->corientation, new_orient, 
			min (dtime / time_constant, 1.0));

    ctrl->plane_nml = RotateVector (ctrl->corientation, minus_z_vec);
    ctrl->cdirection = RotateVector (ctrl->corientation, y_vec);
    MakeMatrixFromQuaternion (cob_mat, ctrl->corientation);

    // Trick rotations 
    new_y = MakeVector (cob_mat[1][0], cob_mat[1][1], cob_mat[1][2]); 
    RotateAboutVectorMatrix (rot_mat, new_y, (ctrl->roll_factor * 360));
    MultiplyMatrices (cob_mat, rot_mat, cob_mat);
    new_x = MakeVector (cob_mat[0][0], cob_mat[0][1], cob_mat[0][2]); 
    RotateAboutVectorMatrix (rot_mat, new_x, ctrl->flip_factor * 360);
    MultiplyMatrices (cob_mat, rot_mat, cob_mat);

    TransposeMatrix (cob_mat, inv_cob_mat);
    TransformNode (0, cob_mat, inv_cob_mat); 
}
Example #9
0
void ReInitBaseSize(int NewDimBase,int NewOverSampling)
  {
    const int OldPrn=prn;                    /* Ustalenie nowego rozmiaru bazy */
    register int i,AllDim;

    prn=OFF;
    if(AllocStatus==ON)
      {
        CloseRand2D();                       /* Zwolnienie poprzednich zasobow */
        free((void *)sygnal);
        free((void *)OrgSygnal);
        CloseTune();
      }

    DimBase=NewDimBase;
    OverSampling=NewOverSampling;
    SetTuneScale();                         /* Alokcja nowych zasobow */
    if(MallatDiction==ON)
      {
        DictionSize=MakeMallatDictionary(DimBase,OverSampling,OFF);
        if(Heuristic==ON)                       /* Poprawnosc konfiguracji */
          {
            if(StartDictionSize>=DictionSize)
              Heuristic=OFF;
            else if(FastMode==OFF)
              Heuristic=OFF;
            else if(DiadicStructure==OFF)
              Heuristic=OFF;
          }
      }

    if(Heuristic==OFF)
      StartDictionSize=DictionSize;

    if(InicRandom(OFF)==-1)
      {
        fprintf(stderr,"Problems opening randomized dictionary !\n");
        exit(EXIT_FAILURE);
      }

    if((sygnal=MakeVector(AllDim=3*DimBase))==NULL ||
       (OrgSygnal=MakeVector(DimBase))==NULL)
      {
        fprintf(stderr,"Memory allocation error (main) !\n");
        exit(EXIT_FAILURE);
      }

    for(i=0 ; i<AllDim ; i++)
      sygnal[i]=0.0F;
    for(i=0 ; i<DimBase ; i++)
      OrgSygnal[i]=0.0F;
    prn=OldPrn;
  }
Example #10
0
void init() {
	#ifdef USE_UMBRELLA
	umbrella.pos[0] = 220.0;
	umbrella.pos[1] = (double)(yres-200);
	VecCopy(umbrella.pos, umbrella.lastpos);
	umbrella.width = 200.0;
	umbrella.width2 = umbrella.width * 0.5;
	umbrella.radius = (float)umbrella.width2;
	umbrella.shape = UMBRELLA_FLAT;
	#endif //USE_UMBRELLA
	MakeVector(-150.0,180.0,0.0, bigfoot.pos);
	MakeVector(6.0,0.0,0.0, bigfoot.vel);
}
Example #11
0
void init() {
    kangaroo.pos[0] = 60.0;
    kangaroo.pos[1] = 60.0;
    VecCopy(kangaroo.pos, kangaroo.lastpos);
    kangaroo.width = 200.0;
    kangaroo.width2 = kangaroo.width * 0.5;
    kangaroo.height = 100.0;
    kangaroo.height2 = kangaroo.height * 0.5;
    kangaroo.shape = 1;

    MakeVector(150.0,180.0,0.0, rhino.pos);
    MakeVector(-6.0,0.0,0.0, rhino.vel);
    rhino.height = 200.0;
    rhino.height2 = rhino.height * 0.5;

    MakeVector(150.0,180.0,0.0, animal.pos);
    MakeVector(-6.0,0.0,0.0, animal.vel);
    animal.height = 200.0;
    animal.height2 = animal.height * 0.5;

    MakeVector(150.0,180.0,0.0, apple.pos);//#########################4lin
    MakeVector(-6.0,0.0,0.0, apple.vel);
    apple.height = 200.0;
    apple.height2 = apple.height * 0.5;
//############################################

    MakeVector(300.0,600.0,0.0, ufo.pos);
    MakeVector(0.0,-6.0,0.0, ufo.vel);
}
Example #12
0
void HKUserInterface::ResizeCallback()
{
	HKUserInterface &ui = HKUserInterface::Get();
	if(&ui)
	{
		MFRect rect;
		MFDisplay_GetDisplayRect(&rect);

		ui.pRoot->SetPosition(MakeVector(rect.x, rect.y));
		ui.pRoot->SetSize(MakeVector(rect.width, rect.height));
	}

	if(pChainResizeCallback)
		pChainResizeCallback();
}
Example #13
0
vector3d PolygonCenter(pcs_polygon &polygon)
{

	float TotalArea=0, triarea;
	vector3d Centroid = MakeVector(0,0,0), midpoint;

	for (unsigned int i = 0; i < polygon.verts.size()-2; i++)
	{
		midpoint = polygon.verts[i].point + polygon.verts[i+1].point + polygon.verts[i+2].point;
		midpoint = midpoint/3;

		// Area of Triangle defined by P1, P2, P3 = vector3d(crossProduct(p2-p1, p3-p1)).magnitude()/2

		triarea = Magnitude(CrossProduct(polygon.verts[i+1].point-polygon.verts[i].point, 
										 polygon.verts[i+2].point-polygon.verts[i].point)); // this needs to be area * 2
		if (triarea == 0)
		{
			return PolygonCenterFallback(polygon);
			//exit(1); //panic
		}
		midpoint = triarea*midpoint;
		TotalArea += triarea;
		Centroid += midpoint;

	}

	Centroid = float(1.0 / TotalArea) * Centroid;
	return Centroid;

}
Example #14
0
MFVector MD3DecodeNormal(unsigned short code)
{
	float latitude = ((float)(code & 0xFF)) * (2 * MFPI) / ((float)255);
	float longtitude = ((float)((code >> 8) & 0xFF)) * (2 * MFPI) / ((float)255);

	return MakeVector(-(float)(MFCos(latitude) * MFSin(longtitude)), -(float)(MFSin(latitude) * MFSin(longtitude)), -(float)(MFCos(longtitude)));
}
Example #15
0
void Game_Update()
{
	// calculate a spinning world matrix
	MFMatrix world;
	world.SetTranslation(MakeVector(0, -5, 50));

	static float rotation = 0.0f;
	rotation += MFSystem_TimeDelta();
	world.RotateY(rotation);

	// set world matrix to the model
	MFModel_SetWorldMatrix(pModel, world);

	// advance the animation
	MFAnimation *pAnim = MFModel_GetAnimation(pModel);
	if(pAnim)
	{
		float start, end;
		MFAnimation_GetFrameRange(pAnim, &start, &end);
	
		static float time = 0.f;
		time += MFSystem_TimeDelta();// * 500;
		while(time >= end)
			time -= end;
		MFAnimation_SetFrame(pAnim, time);
	}
}
Example #16
0
void CKeyframe::Update (double timestep, CControl *ctrl) {
	if (!loaded) return;
    double frac;
    TVector3 pos;
	CCharShape *shape = Char.GetShape (g_game.char_id);

	if (!active) return;
    keytime += timestep;
	if (keytime >= frames[keyidx]->val[0]) {
		keyidx++;
		keytime = 0;
	}

    if  (keyidx >= numFrames-1 || numFrames < 2) {
		active = false;
        return;
    } 

    if  (fabs (frames[keyidx]->val[0]) < 0.0001) frac = 1.0;
	else frac = (frames[keyidx]->val[0] - keytime) / frames[keyidx]->val[0];

    pos.x = interp (frac, frames[keyidx]->val[1], frames[keyidx+1]->val[1]) + refpos.x;
    pos.z = interp (frac, frames[keyidx]->val[3], frames[keyidx+1]->val[3]) + refpos.z;
    pos.y = interp (frac, frames[keyidx]->val[2], frames[keyidx+1]->val[2]);
    pos.y += Course.FindYCoord (pos.x, pos.z);

	shape->ResetRoot ();
	shape->ResetJoints ();

    Players.GetCtrl (g_game.player_id)->cpos = pos;
    double disp_y = pos.y + TUX_Y_CORR + heightcorr; 
    shape->ResetNode (0);
    shape->TranslateNode (0, MakeVector (pos.x, disp_y, pos.z));
	InterpolateKeyframe (keyidx, frac, shape);
}
TEST_P(OpModuleProcessedTest, AnyString) {
  const std::string input =
      std::string("OpModuleProcessed \"") + GetParam() + "\"";
  EXPECT_THAT(
      CompiledInstructions(input, SPV_ENV_UNIVERSAL_1_1),
      Eq(MakeInstruction(SpvOpModuleProcessed, MakeVector(GetParam()))));
}
Example #18
0
void CKeyframe::UpdateTest (double timestep, CCharShape *shape) {
    double frac;
    TVector3 pos;

	if (!active) return;
    keytime += timestep;
	if (keytime >= frames[keyidx]->val[0]) {
		keyidx++;
		keytime = 0;
	}
	
    if  (keyidx >= numFrames-1 || numFrames < 2) {
		active = false;
        return;
    } 

    if  (fabs (frames[keyidx]->val[0]) < 0.0001) frac = 1.0;
	else frac = (frames[keyidx]->val[0] - keytime) / frames[keyidx]->val[0];

    pos.x = interp (frac, frames[keyidx]->val[1], frames[keyidx+1]->val[1]) + refpos.x;
    pos.z = interp (frac, frames[keyidx]->val[3], frames[keyidx+1]->val[3]) + refpos.z;
    pos.y = interp (frac, frames[keyidx]->val[2], frames[keyidx+1]->val[2]);

	shape->ResetRoot ();
	shape->ResetJoints ();
    shape->TranslateNode (0, MakeVector (pos.x, pos.y, pos.z));
	InterpolateKeyframe (keyidx, frac, shape);
}
Example #19
0
void init_track_marks (void) {
    track_marks.current_mark = 0;
    track_marks.next_mark = 0;
    track_marks.last_mark_time = -99999;
    track_marks.last_mark_pos = MakeVector(-9999, -9999, -9999);
    continuing_track = false;
}
TEST_P(OpStringTest, AnyString) {
  // TODO(dneto): utf-8, quoting, escaping
  const std::string input =
      std::string("%result = OpString \"") + GetParam() + "\"";
  EXPECT_THAT(CompiledInstructions(input),
              Eq(MakeInstruction(SpvOpString, {1}, MakeVector(GetParam()))));
}
Example #21
0
void Game_Update()
{
	static float rotation = 0.0f;
	rotation += MFSystem_GetTimeDelta();

	// spin the prism
	MFMatrix world;
	world.SetTranslation(MakeVector(0, 0.3f, 3));
	world.RotateY(rotation * 2.3f);
	MFStateBlock_SetMatrix(pPrismStateBlock, MFSCM_World, world);

	// spin the box
	world.SetTranslation(MakeVector(0, 0, 5));
	world.RotateYPR(rotation, rotation * 2.0f, rotation * 0.5f);
	MFStateBlock_SetMatrix(pBoxStateBlock, MFSCM_World, world);
}
Example #22
0
void Game_Init(void *pUserData)
{
	// create the renderer with a single layer that clears before rendering
	MFRenderLayerDescription layers[] = { "Scene" };
	pRenderer = MFRenderer_Create(layers, 1, NULL, NULL);
	MFRenderer_SetCurrent(pRenderer);

	pDefaultStates = MFStateBlock_CreateDefault();
	MFRenderer_SetGlobalStateBlock(pRenderer, pDefaultStates);

	MFRenderLayer *pLayer = MFRenderer_GetLayer(pRenderer, 0);
	MFRenderLayer_SetClear(pLayer, MFRCF_All, MakeVector(0.f, 0.f, 0.2f, 1.f));

	MFRenderLayerSet layerSet;
	MFZeroMemory(&layerSet, sizeof(layerSet));
	layerSet.pSolidLayer = pLayer;
	MFRenderer_SetRenderLayerSet(pRenderer, &layerSet);

	// init HKUserInterface
	HKUserInterface::Init();

	pUI = new HKUserInterface();
	HKUserInterface::SetActiveUI(pUI);

	// load a test UI
	HKWidget *pTestLayout = HKWidget_CreateFromXML("ui-test.xml");
	MFDebug_Assert(pTestLayout != NULL, "Couldn't load UI!");

	pUI->AddTopLevelWidget(pTestLayout, true);
}
Example #23
0
// calculate tractions on one side of crack for this segment
// add forces to material velocity fields on one side of the crack
double CrackSegment::AddTractionForceSegSide(CrackHeader *theCrack,int side,double sign)
{
	int numnds,nds[maxShapeNodes];
    double fn[maxShapeNodes];
    short vfld;
	double fnorm = 0.;
	NodalPoint *ndi;
	int cnum=theCrack->GetNumber();

	Vector cspos = MakeVector(surfx[side-1], surfy[side-1], 0.);
	const ElementBase *elref = theElements[surfInElem[side-1]];
	elref->GetShapeFunctionsForCracks(&numnds,fn,nds,&cspos);
	
	// loop over all nodes seen by this crack surface particle
	for(int i=1;i<=numnds;i++)
	{	// Get velocity field to use
		ndi = nd[nds[i]];
		vfld = ndi->GetFieldForSurfaceParticle(side,cnum,this);
		
		// if has particles (and they see cracks), add force and track normalization
		if(vfld>=0)
		{	ndi->AddFtotSpreadTask3(vfld,FTract(sign*fn[i]));
			fnorm += fn[i];
		}
	}
	
	// return amount used
	return fnorm;
}
Example #24
0
void MenuItemPosition2D::ListUpdate(bool selected)
{
	if(selected)
	{
		MFVector t = *pData;
		float input;

		if(MFInput_WasPressed(Button_XB_B, IDD_Gamepad)) *pData = defaultValue;
		if(MFInput_WasPressed(Button_XB_X, IDD_Gamepad)) *pData = MakeVector(0.0f, 0.0f, 0.0f);

		if((input = MFInput_Read(Axis_RX, IDD_Gamepad)))
		{
			input = input < 0.0f ? -(input*input) : input*input;
			pData->x += input*increment*MFTimeDelta();
		}

		if((input = MFInput_Read(Axis_RY, IDD_Gamepad)))
		{
			input = input < 0.0f ? -(input*input) : input*input;
			pData->y -= input*increment*MFTimeDelta();
		}

		if(pCallback && t != *pData)
			pCallback(this, pUserData);
	}
}
Example #25
0
void TitleScreen::Draw()
{
	GHScreen::Draw();

	MFView_Push();

	MFRect rect;
	rect.x = (MFDisplay_GetAspectRatio() >= 1.5) ? -106.0f : 0.0f;
	rect.y = 0.0f;
	rect.width = (MFDisplay_GetAspectRatio() >= 1.5) ? 852.0f : 640.0f;
	rect.height = 480.0f;
	MFView_SetOrtho(&rect);

	MFPrimitive_DrawUntexturedQuad(20, 20, 640-40, 480-40, MakeVector(0,0,0,0.8f));

	CenterText(30, 34, MFVector::yellow, "Main Menu", pHeading);

	float height = TEXT_HEIGHT;
	float y = 90-height;
	float x = 55.0f;

//	MFFont_DrawText(pText, , y+=height, 20, MFVector::white, "H - Enter help screen");

//	CenterText(rect.height - 20 - 54, 44, MFVector::red, "Press ESC to continue", pFancy);

	MFView_Pop();
}
Example #26
0
MF_API void MFView_TransformPoint3DTo2D(const MFVector& point, MFVector *pResult)
{
	MFMatrix proj, viewProj, view;

	// get the perspective projection matrix
	proj.SetPerspective(pCurrentView->fov, pCurrentView->nearPlane, pCurrentView->farPlane, pCurrentView->aspectRatio);

	// in this special case, we'll make the projection matrix produce a 0-1 value in z across all platforms (some platforms project into different 'z' spaces)
	float zn = pCurrentView->nearPlane;
	float zf = pCurrentView->farPlane;
	float zd = zf-zn;
	float zs = zf/zd;
	proj.m[10] = zs;
	proj.m[14] = -zn*zs;

	// get the view matrix (which we will need to calculate if we are in ortho mode)
	if(!MFView_IsOrtho())
		view = MFView_GetWorldToViewMatrix();
	else
		view.Inverse(MFView_GetCameraMatrix());

	viewProj.Multiply4x4(view, proj);

	// apply the projection and perform the perspective divide
	MFVector transformed;
	transformed = ApplyMatrix(point, viewProj);
	transformed *= MFRcp(transformed.w);

	// and shift the result into the ortho rect
	transformed.x += 1.0f;
	transformed.y = -transformed.y + 1.0f;

	*pResult = transformed * MakeVector(pCurrentView->orthoRect.width*0.5f, pCurrentView->orthoRect.height*0.5f) + MakeVector(pCurrentView->orthoRect.x, pCurrentView->orthoRect.y);
}
Example #27
0
void dBTextProp::Draw()
{
	if(text.NumBytes() > 0)
		MFFont_DrawTextAnchored(pFont, text.CStr(), MakeVector(boundingRect.x, boundingRect.y), justification, boundingRect.width, textHeight, colour, -1, GetMatrix());

	dBEntity::Draw();
}
Example #28
0
FObject MakeVector(uint_t vl, FObject * v, FObject obj)
{
    int_t mf = 0;
    FVector * nv = MakeVector(vl, "make-vector", &mf);

    uint_t idx;
    if (v == 0)
    {
        if (mf && ObjectP(obj))
            for (idx = 0; idx < vl; idx++)
                ModifyVector(nv, idx, obj);
        else
            for (idx = 0; idx < vl; idx++)
                nv->Vector[idx] = obj;
    }
    else
    {
        if (mf)
            for (idx = 0; idx < vl; idx++)
                ModifyVector(nv, idx, v[idx]);
        else
            for (idx = 0; idx < vl; idx++)
                nv->Vector[idx] = v[idx];
    }

    FAssert(VectorLength(nv) == vl);
    return(nv);
}
Example #29
0
bool HKWidgetRenderer::SetProperty(const char *pProperty, const char *pValue, HKWidget *pWidget)
{
	if(!MFString_CaseCmp(pProperty, "background_image"))
	{
		if(pImage)
			MFMaterial_Destroy(pImage);
		pImage = MFMaterial_Create(pValue);
		if(pImage)
		{
			int texW, texH;
			MFTexture *pTex = MFMaterial_GetParameterT(pImage, MFMatStandard_Texture, MFMatStandard_Tex_DifuseMap);
			MFTexture_GetTextureDimensions(pTex, &texW, &texH);

			texWidth = (float)texW;
			texHeight = (float)texH;

			if(pWidget && (pWidget->bAutoWidth || pWidget->bAutoHeight))
			{
				if(pWidget->bAutoWidth && pWidget->bAutoHeight)
					pWidget->Resize(MakeVector(texWidth, texHeight));
				else if(pWidget->bAutoWidth)
					pWidget->UpdateWidth(texWidth);
				else
					pWidget->UpdateHeight(texHeight);
			}
		}
		return true;
	}
	else if(!MFString_CaseCmp(pProperty, "background_align"))
	{
		imageAlignment = (HKWidget::Justification)HKWidget_GetEnumValue(pValue, HKWidget::sJustifyKeys);
		return true;
	}
	else if(!MFString_CaseCmp(pProperty, "background_colour"))
	{
		colour = HKWidget_GetColourFromString(pValue);
		return true;
	}
	else if(!MFString_CaseCmp(pProperty, "background_padding"))
	{
		padding = HKWidget_GetVectorFromString(pValue);
		return true;
	}
	else if(!MFString_CaseCmp(pProperty, "background_9-cell-margin"))
	{
		margin9Cell = MFString_AsciiToFloat(pValue);
		return true;
	}
	else if(!MFString_CaseCmp(pProperty, "border_width"))
	{
		border = HKWidget_GetVectorFromString(pValue);
		return true;
	}
	else if(!MFString_CaseCmp(pProperty, "border_colour"))
	{
		borderColour = HKWidget_GetColourFromString(pValue);
		return true;
	}
	return false;
}
Example #30
0
Vector<String> DropGrid::FindVector(const Value& v) const
{
	int r = list.Find(v, key_col);
	if(r < 0)
		return Vector<String>();

	return MakeVector(r);
}