Beispiel #1
0
/*
 * Function:
 *	ResizeChildren
 *
 * Parameters:
 *	w - form widget
 *
 * Description:
 *	Resizes all children to new_x and new_y.
 */
static void
ResizeChildren(Widget w)
{
    FormWidget fw = (FormWidget)w;
    int num_children = fw->composite.num_children;
    WidgetList children = fw->composite.children;
    Widget *childP;

    for (childP = children; childP - children < num_children; childP++) {
	FormConstraints form;
	Position x, y;

	if (!XtIsManaged(*childP))
	    continue;

	form = (FormConstraints)(*childP)->core.constraints;

	if (fw->form.old_width && fw->form.old_height) {
	    x = TransformCoord(form->form.new_x, fw->form.old_width,
			       XtWidth(fw), form->form.left);
	    y = TransformCoord(form->form.new_y, fw->form.old_height,
			       XtHeight(fw), form->form.top);
	}
	else {
	    x = form->form.new_x;
	    y = form->form.new_y;
	}

	if (fw->form.no_refigure) {
	   /*
	    * I am changing the widget wrapper w/o modifing the window.  This is
	    * risky, but I can get away with it since I am the parent of this
	    * widget, and he must ask me for any geometry changes
	    *
	    * The window will be updated when no_refigure is set back to False
	    */
	    XtX(*childP) = x;
	    XtY(*childP) = y;
	}
	else
	    XtMoveWidget(*childP, x, y);
    }
}
Beispiel #2
0
void Camera::RotateLocalY(float angle){
	Matrix4x4 matRot;
	matRot = Rotate(m_Up, angle);

	Vector3 newDst;
	newDst = TransformCoord(m_View, matRot);
	newDst += m_Eye;

	SetView(m_Eye, newDst, m_Up);
}
Beispiel #3
0
BOOL PSPrintDC::OutputCoord(DocCoord& Coord, EPSAccuracy Accuracy)
{
	// We need a view to scale the coords.
	ERROR2IF(pView == NULL, FALSE, "No view attached to PostScript DC!");

	WinCoord PSCoord = TransformCoord(Coord);

	// Output to PostScript stream.
	BOOL Ok = (OutputValue(PSCoord.x) && OutputValue(PSCoord.y));

	return Ok;
}
Beispiel #4
0
void Camera::Render()
{
	VectorType up, position, lookAt;
	float yaw, pitch, roll;
	float rotationMatrix[9];


	// Setup the vector that points upwards.
	up.position.x = 0.0f;
	up.position.y = 1.0f;
	up.position.z = 0.0f;

	// Setup the position of the camera in the world.
	position.position = m_position;

	// Setup where the camera is looking by default.
	lookAt.position.x = 0.0f;
	lookAt.position.y = 0.0f;
	lookAt.position.z = 1.0f;

	// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
	pitch = m_rotation.x * RADIAN;
	yaw   = m_rotation.y * RADIAN;
	roll  = m_rotation.z * RADIAN;

	// Create the rotation matrix from the yaw, pitch, and roll values.
	MatrixRotationYawPitchRoll(rotationMatrix, yaw, pitch, roll);

	// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
	TransformCoord(lookAt, rotationMatrix);
	TransformCoord(up, rotationMatrix);
	
	// Translate the rotated camera position to the location of the viewer.
	lookAt.position.x = position.position.x + lookAt.position.x;
	lookAt.position.y = position.position.y + lookAt.position.y;
	lookAt.position.z = position.position.z + lookAt.position.z;

	// Finally create the view matrix from the three updated vectors.
	BuildViewMatrix(position, lookAt, up);
}
Beispiel #5
0
void EffectTwist::apply()
{
	D3DXVECTOR3 posO, posC, pos;
	D3DXMATRIX mat;
	for (int i = 0; i < count; i++)
	{
		float offset = (float)i * 2*3.14159f / (float)count;
		D3DXMatrixRotationYawPitchRoll(&mat, 0,0,m_pSettings->frame*rotate + offset);
		posC.x = 0.4f*minscale * sin(m_pSettings->frame*modulate);
		posC.y = 0;
		TransformCoord(&posC,&posC,&mat);

		D3DXMatrixRotationYawPitchRoll(&mat, 0,0,m_pSettings->frame*speed);
		posO.x = minscale/36.5f;
		posO.y = minscale/36.5f;
		TransformCoord(&posO,&posO,&mat);
		pos.x = posC.x+posO.x;
		pos.y = posC.y+posO.y;
		m_pSettings->waterField->SetHeight(posC.x+posO.x,posC.y+posO.y,1.0,-2.5,palette[0+2*i]);
		m_pSettings->waterField->SetHeight(posC.x-posO.x,posC.y-posO.y,1.0,-2.5,palette[1+2*i]);
	}
}
rvector ZRangeWeaponHitDice::ReturnShotDir()
{
	MakeHitProbability();

	rvector vTargetPos = m_TargetPosition;
	float fRandX=0.0f, fRandY=0.0f;

	float fRandMaxX = m_fTargetWidth+50.0f;
	float fRandMaxY = m_fTargetHeight+20.0f;

	
	if (RandomNumber(0.0f, 1.0f) <= m_fHitProbability)
	{
		float fHeight = m_fTargetHeight * 0.6f * 0.5f;
		float fWidth = m_fTargetWidth * 0.6f * 0.5f;
		// ИэСп
		fRandX = RandomNumber(-fWidth, fWidth);
		fRandY = RandomNumber(-fHeight, fHeight);
	}
	else
	{
		float fHeight = m_fTargetHeight * 0.8f * 0.5f;
		float fWidth = m_fTargetWidth * 0.8f * 0.5f;

		fRandX = RandomNumber(fWidth, fRandMaxX);
		fRandY = RandomNumber(fHeight, fRandMaxY);

		int dice = Dice(1, 2, 0);
		if (dice == 1) fRandX = -fRandX;
		dice = Dice(1, 2, 0);
		if (dice == 1) fRandY = -fRandY;
	}

	rmatrix mat;
	rvector modelDir = vTargetPos - m_SourcePosition;
	Normalize(modelDir);

	rvector tar(0,0,0);
	tar.x += fRandX;
	tar.y += fRandY;

	MakeWorldMatrix(&mat, m_TargetPosition, modelDir, rvector(0,0,1));
	tar = TransformCoord(tar, mat);

	rvector dir = tar - m_SourcePosition;
	Normalize(dir);

	return dir;
}
Beispiel #7
0
void EffectSwirl::apply()
{
	D3DXVECTOR3 pos;
	D3DXMATRIX mat;
	for (int i = 0; i < swirlImages; i++)
	{
		float offset = (float)i * 2*3.14159f / (float)swirlImages;
		D3DXMatrixRotationYawPitchRoll(&mat, 0,0,offset);
		pos.z = 3.0f+2.5f*sin(m_pSettings->frame*0.007f+offset);
		//Pretty sinusoidal swimming
		pos.x = minx + scalex/2.0f + (float)7.0f/20.0f*minscale*sin(m_pSettings->frame*0.035f);
		pos.y = miny + scaley/2.0f +(float)7.0f/20.0f*minscale*cos(m_pSettings->frame*0.045f);
		TransformCoord(&pos,&pos,&mat);
		m_pSettings->waterField->SetHeight(pos.x,pos.y,2.5f,-2.5f*(invertSwirls ? (i%2)*2-1:1), palette[i]);
	}
}
bool ZEffectShadowList::Draw()
{
	if(!m_pVB) return false;

	if( empty() ) return true;

	BeginState();

	HRESULT		hr;

	DWORD	dwRemainNum = (DWORD)size();

	iterator itr=begin();

	while(dwRemainNum)
	{
		if(m_dwBase >= EFFECTBASE_DISCARD_COUNT)
			m_dwBase = 0;

		DWORD dwThisNum = min( dwRemainNum , static_cast<DWORD>(BILLBOARD_FLUSH_COUNT) );

		dwThisNum = min( dwThisNum , EFFECTBASE_DISCARD_COUNT - m_dwBase );	

		BYTE* pVertices;

		if( FAILED( hr = m_pVB->Lock( m_dwBase * sizeof(ZEFFECTCUSTOMVERTEX) * 4, dwThisNum * sizeof(ZEFFECTCUSTOMVERTEX) * 4,
			(VOID**)&pVertices, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ) ) )
		{
			return false;
		}

		BYTE *pInd;

		if( FAILED( hr = m_pIB->Lock( m_dwBase * sizeof(WORD) * 6, dwThisNum * sizeof(WORD) * 6,
			(VOID**)&pInd, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ) ) )
		{
			return false;
		}

		for(DWORD j=0;j<dwThisNum;j++)
		{
			ZEFFECTSHADOWITEM *p = (ZEFFECTSHADOWITEM*)*itr;

			static ZEFFECTCUSTOMVERTEX v[] = {
				{{-0.5f, -0.5f, 0.f}, 0xFFFFFFFF, 0.f, 0.f },
				{{ 0.5f, -0.5f, 0.f}, 0xFFFFFFFF, 1.f, 0.f },
				{{-0.5f,  0.5f, 0.f}, 0xFFFFFFFF, 0.f, 1.f},
				{{ 0.5f,  0.5f, 0.f}, 0xFFFFFFFF, 1.f, 1.f},
			};

			static rvector sv[4] = { 
				rvector(-0.5f,-0.5f , 0.f) , 
				rvector( 0.5f,-0.5f , 0.f) , 
				rvector(-0.5f, 0.5f , 0.f) , 
				rvector( 0.5f, 0.5f , 0.f) ,
			};

			for (size_t i{}; i < 4; ++i)
				v[i].pos = TransformCoord(sv[i], p->worldmat);

			v[0].color = v[1].color = v[2].color = v[3].color = p->dwColor;

			memcpy(pVertices, v, sizeof(ZEFFECTCUSTOMVERTEX) * 4);

			pVertices+=sizeof(ZEFFECTCUSTOMVERTEX)*4;

			WORD inds[] = { 0,1,2,2,1,3 };

			for(int k=0;k<6;k++)
			{
				inds[k]+=(m_dwBase+j)*4;
			}

			memcpy(pInd,inds,sizeof(inds));

			pInd+=sizeof(inds);

			itr++;
		}

		m_pVB->Unlock();
		m_pIB->Unlock();

		if(FAILED( hr = RGetDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,m_dwBase*4,dwThisNum*4,m_dwBase*6,dwThisNum*2) ))
			return false;

		m_dwBase+=dwThisNum;
		dwRemainNum-=dwThisNum;

	}

	RGetDevice()->SetStreamSource( 0, NULL , 0,0 );	
	RGetDevice()->SetIndices(NULL);

	EndState();

	Clear();

	return true;	
}
bool ZEffectBillboardTexAniList::Draw()
{
	if(!m_pVB) return false;

	if( size()==0 ) return true;

	BeginState();

	RSetFog(FALSE);

	HRESULT	hr;

	DWORD	dwRemainNum = (DWORD)size();

	iterator itr = begin();

	while(dwRemainNum)
	{
		if(m_dwBase >= EFFECTBASE_DISCARD_COUNT)
			m_dwBase = 0;

		DWORD dwThisNum = min( dwRemainNum , static_cast<DWORD>(BILLBOARD_FLUSH_COUNT) );

		dwThisNum = min( dwThisNum , EFFECTBASE_DISCARD_COUNT - m_dwBase );	

		BYTE *pVertices;

		if( FAILED( hr = m_pVB->Lock( m_dwBase * sizeof(ZEFFECTCUSTOMVERTEX) * 4, dwThisNum * sizeof(ZEFFECTCUSTOMVERTEX) * 4,
			(VOID**)&pVertices, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ) ) )
		{
			return false;
		}

		BYTE *pInd;
		if( FAILED( hr = m_pIB->Lock( m_dwBase * sizeof(WORD) * 6, dwThisNum * sizeof(WORD) * 6,
			(VOID**)&pInd, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ) ) )
		{
			return false;
		}

		int nRenderCnt = 0;

		ZCharacter* pChar = NULL;

		for(DWORD j=0;j<dwThisNum;j++)
		{
			ZEFFECTBILLBOARDTEXANIITEM *p = (ZEFFECTBILLBOARDTEXANIITEM*)*itr;

			if(p->fElapsedTime < p->fAddTime ) {
				itr++;
				continue;
			}

			pChar = ZGetCharacterManager()->Find(p->CharUID);

			if( pChar ) {
				if( pChar->m_pVMesh ) {
					if( pChar->m_pVMesh->m_bIsRender==false) {
						itr++;
						continue;
					}
				}
			}

			nRenderCnt++;

			// Transform
			rmatrix matTranslation;
			rmatrix matScaling;
			rmatrix matWorld;

			rvector dir = p->normal;

			rvector up = p->up;
			rvector right;

			if (IS_EQ(dir.z, 1.f)) up = rvector(1, 0, 0);

			right = Normalized(CrossProduct(up, dir));
			up = Normalized(CrossProduct(right, dir));

			rmatrix mat;
			GetIdentityMatrix(mat);
			mat._11 = right.x; mat._12 = right.y; mat._13 = right.z;
			mat._21 = up.x; mat._22 = up.y; mat._23 = up.z;
			mat._31 = dir.x; mat._32 = dir.y; mat._33 = dir.z;

			rvector pos = p->position;

			float fInt = min(1.f, max(0.f, (p->fLifeTime - p->fElapsedTime) / p->fLifeTime));
			float fScale=p->fStartSize * fInt + p->fEndSize * (1.f - fInt);

			matScaling = ScalingMatrix(fScale * m_Scale);
			matTranslation = TranslationMatrix(pos);

			matWorld = matScaling * mat;
			matWorld *= matTranslation;

			DWORD color = ((DWORD)(p->fOpacity * 255))<<24 | p->dwColor;

			static ZEFFECTCUSTOMVERTEX v[] = {
				{{-1, -1, 0}, 0xFFFFFFFF, 1, 0 },
				{{-1,  1, 0}, 0xFFFFFFFF, 1, 1},
				{{ 1,  1, 0}, 0xFFFFFFFF, 0, 1},
				{{ 1, -1, 0}, 0xFFFFFFFF, 0, 0},
			};

			static rvector sv[4] = { rvector(-1,-1,0) , rvector(-1,1,0) , rvector(1,1,0) , rvector(1,-1,0) };

			GetFrameUV( min( p->frame,m_nMaxFrame-1) );

			v[0].tu = m_fUV[0];
			v[0].tv = m_fUV[1];
			v[1].tu = m_fUV[2];
			v[1].tv = m_fUV[3];
			v[2].tu = m_fUV[4];
			v[2].tv = m_fUV[5];
			v[3].tu = m_fUV[6];
			v[3].tv = m_fUV[7];

			for (size_t i{}; i < 4; ++i)
				v[i].pos = TransformCoord(sv[i], matWorld);

			v[0].color=v[1].color=v[2].color=v[3].color=color;

			memcpy(pVertices,v,sizeof(ZEFFECTCUSTOMVERTEX)*4);
			pVertices+=sizeof(ZEFFECTCUSTOMVERTEX)*4;

			WORD inds[] = { 0,1,2,0,2,3 };
			for(int k=0;k<6;k++)
			{
				inds[k]+=(m_dwBase+j)*4;
			}
			memcpy(pInd,inds,sizeof(inds));
			pInd+=sizeof(inds);

			itr++;
		}

		m_pVB->Unlock();
		m_pIB->Unlock();

		if(FAILED( hr = RGetDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,m_dwBase*4,nRenderCnt*4,m_dwBase*6,nRenderCnt*2) ))
			return false;

		m_dwBase+=dwThisNum;
		dwRemainNum-=dwThisNum;

	}

	RGetDevice()->SetStreamSource( 0, NULL , 0,0 );	
	RGetDevice()->SetIndices(NULL);

	if(ZGetWorld()) {
		ZGetWorld()->SetFog(true);
	}

	EndState();

	return true;
}
bool ZEffectBillboardList::Draw()
{
	if(!m_pVB) return false;

	if( size()==0 ) return true;

	BeginState();

	HRESULT		hr;

	DWORD		dwRemainNum = (DWORD)size();

	iterator itr=begin();

	while(dwRemainNum)
	{
		if(m_dwBase >= EFFECTBASE_DISCARD_COUNT)
			m_dwBase = 0;

		DWORD dwThisNum = min( dwRemainNum , static_cast<DWORD>(BILLBOARD_FLUSH_COUNT) );

		dwThisNum = min( dwThisNum , EFFECTBASE_DISCARD_COUNT - m_dwBase );	


		BYTE		*pVertices;
		if( FAILED( hr = m_pVB->Lock( m_dwBase * sizeof(ZEFFECTCUSTOMVERTEX) * 4, dwThisNum * sizeof(ZEFFECTCUSTOMVERTEX) * 4,
			(VOID**)&pVertices, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ) ) )
		{
			return false;
		}

		BYTE *pInd;
		if( FAILED( hr = m_pIB->Lock( m_dwBase * sizeof(WORD) * 6, dwThisNum * sizeof(WORD) * 6,
			(VOID**)&pInd, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ) ) )
		{
			return false;
		}

		for(DWORD j=0;j<dwThisNum;j++)
		{
			ZEFFECTBILLBOARDITEM *p = (ZEFFECTBILLBOARDITEM*)*itr;

			// Transform
			rmatrix matTranslation;
			rmatrix matScaling;
			rmatrix matWorld;

			rvector dir = p->normal;

			rvector up=p->up;
			rvector right;

			if(IS_EQ(dir.z,1.f)) up=rvector(1,0,0);

			right = Normalized(CrossProduct(up, dir));
			up = Normalized(CrossProduct(right, dir));

			rmatrix mat;
			GetIdentityMatrix(mat);
			mat._11=right.x;mat._12=right.y;mat._13=right.z;
			mat._21=up.x;mat._22=up.y;mat._23=up.z;
			mat._31=dir.x;mat._32=dir.y;mat._33=dir.z;

			rvector pos=p->position;

			float fInt = min(1.f, max(0.f, (p->fLifeTime - p->fElapsedTime) / p->fLifeTime));

			float fScale=p->fStartSize * fInt + p->fEndSize * (1.f - fInt);

			if( p->bUseTrainSmoke ) {

				float fRatio = GetLifeRatio(p);
				float fAddScale = (p->fEndSize - p->fStartSize) / p->fLifeTime;

				if(fRatio < 0.1f ) {
					fAddScale *= 0.001f;
				}
				else if(fRatio < 0.4) {
					fAddScale *= 0.02f;
				}
				else {
					fAddScale *= 0.05f;
				}

				p->fCurScale += fAddScale;

				if(p->fCurScale > p->fEndSize)
					p->fCurScale = p->fEndSize;

				fScale = p->fCurScale;
			}

			matScaling = ScalingMatrix(fScale * m_Scale);
			matTranslation = TranslationMatrix(pos);

			matWorld = matScaling * mat;
			matWorld *= matTranslation;

			DWORD color = ((DWORD)(p->fOpacity * 255))<<24 | p->dwColor;

			static ZEFFECTCUSTOMVERTEX v[] = {
				{{-1, -1, 0}, 0xFFFFFFFF, 1, 0 },
				{{-1,  1, 0}, 0xFFFFFFFF, 1, 1 },
				{{ 1,  1, 0 }, 0xFFFFFFFF, 0, 1},
				{ { 1, -1, 0}, 0xFFFFFFFF, 0, 0 },
			};

			static const rvector sv[4] = { rvector(-1,-1,0) , rvector(-1,1,0) , rvector(1,1,0) , rvector(1,-1,0) };

			for (size_t i{}; i < 4; ++i)
				v[i].pos = TransformCoord(sv[i], matWorld);

			v[0].color=v[1].color=v[2].color=v[3].color=color;

			memcpy(pVertices,v,sizeof(ZEFFECTCUSTOMVERTEX)*4);
			pVertices+=sizeof(ZEFFECTCUSTOMVERTEX)*4;

			WORD inds[] = { 0,1,2,0,2,3 };
			for(int k=0;k<6;k++)
			{
				inds[k]+=(m_dwBase+j)*4;
			}
			memcpy(pInd,inds,sizeof(inds));
			pInd+=sizeof(inds);

			itr++;
		}

		m_pVB->Unlock();
		m_pIB->Unlock();

		if(FAILED( hr = RGetDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,m_dwBase*4,dwThisNum*4,m_dwBase*6,dwThisNum*2) ))
			return false;

		m_dwBase+=dwThisNum;
		dwRemainNum-=dwThisNum;

	}

	RGetDevice()->SetStreamSource( 0, NULL , 0,0 );	
	RGetDevice()->SetIndices(NULL);

	EndState();

	return true;
}
Beispiel #11
0
static void
XawFormResize(Widget w)
{
    FormWidget fw = (FormWidget)w;
    WidgetList children = fw->composite.children;
    int num_children = fw->composite.num_children;
    Widget *childP;
    int x, y;
    int width, height;
    Boolean unmap = XtIsRealized(w) && w->core.mapped_when_managed &&
		    XtIsManaged(w);

    if (unmap)
	XtUnmapWidget(w);

    if (!fw->form.resize_is_no_op)
	for (childP = children; childP - children < num_children; childP++) {
	    FormConstraints form = (FormConstraints)(*childP)->core.constraints;

	    if (!XtIsManaged(*childP))
		continue;

#ifndef OLDXAW
	    x = TransformCoord(form->form.virtual_x, fw->form.old_width,
			       XtWidth(fw), form->form.left);
	    y = TransformCoord(form->form.virtual_y, fw->form.old_height,
			       XtHeight(fw), form->form.top);
	    width = TransformCoord(form->form.virtual_x +
				   form->form.virtual_width +
				   (XtBorderWidth(*childP) << 1),
				   fw->form.old_width, XtWidth(fw),
				   form->form.right) -
				   (x + (XtBorderWidth(*childP) << 1));
	    height = TransformCoord(form->form.virtual_y +
				    form->form.virtual_height +
				    (XtBorderWidth(*childP) << 1),
				    fw->form.old_height, XtHeight(fw),
				    form->form.bottom) -
				    (y + (XtBorderWidth(*childP) << 1));
#else
	    x = TransformCoord(XtX(*childP), fw->form.old_width,
			      XtWidth(fw), form->form.left);
	    y = TransformCoord(XtY(*childP), fw->form.old_height,
			       XtHeight(fw), form->form.top);
	    width = TransformCoord(XtX(*childP) + form->form.virtual_width +
				   (XtBorderWidth(*childP) << 1),
				   fw->form.old_width, XtWidth(fw),
				   form->form.right) -
				   (x + (XtBorderWidth(*childP) << 1));
	    height = TransformCoord(XtY(*childP) + form->form.virtual_height +
				    (XtBorderWidth(*childP) << 1),
				    fw->form.old_height, XtHeight(fw),
				    form->form.bottom) -
				    (y + (XtBorderWidth(*childP) << 1));
	    form->form.virtual_width = width;
	    form->form.virtual_height = height;
#endif

	    width = width < 1 ? 1 : width;
	    height = height < 1 ? 1 : height;

	    XtConfigureWidget(*childP, x, y, width, height,
			      XtBorderWidth(*childP));
	}

    if (unmap)
	XtMapWidget(w);

#ifdef OLDXAW
    fw->form.old_width = XtWidth(fw);
    fw->form.old_height = XtHeight(fw);
#endif
}