Ejemplo n.º 1
0
	void Node::SetScale(float x, float y, float z)
	{
		D3DXMatrixScaling( &this->matScale, x, y, z);        // Pitch
	}
Ejemplo n.º 2
0
void star::starDraw(void)//this draws a Star to the Background will eventually include arguments to set stars X Y coords, size and color of star
{

	
	D3DXMATRIX matTranslateStar;    // a matrix to store the translation information
	D3DXMATRIX matSpikeRotation;	//matrix used to rotate drawn spikes
	D3DXMATRIX matScaleStar;			//matrix used to scale stars down
	D3DXMATRIX matTwinkle;

	starTwinkle();
	
	D3DXMatrixTranslation(&matTranslateStar, xStar, yStar, -5.0f);//set star transformation here
	D3DXMatrixScaling(&matScaleStar,scale,scale,scale);
	D3DXMatrixRotationZ(&matTwinkle,D3DXToRadian(twinkle));

	starBase();
	// set the world transform

	
    dev->d3ddev->SetTransform(D3DTS_WORLD, &(matScaleStar*matTwinkle*matTranslateStar));    // set the world transform
	
	// select the vertex buffer to display
    dev->d3ddev->SetStreamSource(0, dev->v_buffer, 0, sizeof(CUSTOMVERTEX));
    dev->d3ddev->SetIndices(dev->i_buffer);
	// draw
    dev->d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 18, 0, 32);
	dev->cleanBuffers();


	starAngle();
	for(float i=0;i<=3;i+=1)//draws 4 spikes at equal areas
	{
	// set the world transform
	D3DXMatrixRotationZ(&matSpikeRotation, D3DXToRadian(90*i));
    dev->d3ddev->SetTransform(D3DTS_WORLD, &(matSpikeRotation*matScaleStar*matTwinkle*matTranslateStar));    // set the world transform
	 
	// select the vertex buffer to display
    dev->d3ddev->SetStreamSource(0, dev->v_buffer, 0, sizeof(CUSTOMVERTEX));
    dev->d3ddev->SetIndices(dev->i_buffer);
	// draw
    dev->d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 5, 0, 4);
	}
	dev->cleanBuffers();

	starHV();
	for(float i=0;i<=3;i+=1)//draws 4 spikes at equal areas
	{
	// set the world transform
	D3DXMatrixRotationZ(&matSpikeRotation, D3DXToRadian(90*i));
    dev->d3ddev->SetTransform(D3DTS_WORLD, &(matSpikeRotation*matScaleStar*matTwinkle*matTranslateStar));    // set the world transform
	
	// select the vertex buffer to display
    dev->d3ddev->SetStreamSource(0, dev->v_buffer, 0, sizeof(CUSTOMVERTEX));
    dev->d3ddev->SetIndices(dev->i_buffer);
	// draw
    dev->d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 5, 0, 4);
	}
	dev->cleanBuffers();


	return;
}
Ejemplo n.º 3
0
void MegaExtrudeOperator::process(int tick)
{
    if (mesh != 0)
        delete mesh;

    float distance = getFloatProperty(0);
    unsigned char count = getByteProperty(1);
    D3DXVECTOR3 scaleVector = getVectorProperty(2);
    D3DXVECTOR3 rotationVector = getVectorProperty(3);
    D3DXMATRIX scaleMatrix;
    D3DXMatrixScaling(&scaleMatrix,
                      scaleVector.x,
                      scaleVector.y,
                      scaleVector.z);
    D3DXMATRIX rotationXMatrix;
    D3DXMatrixRotationX(&rotationXMatrix, rotationVector.x);
    D3DXMATRIX rotationYMatrix;
    D3DXMatrixRotationY(&rotationYMatrix, rotationVector.y);
    D3DXMATRIX rotationZMatrix;
    D3DXMatrixRotationZ(&rotationZMatrix, rotationVector.z);
    D3DXMATRIX translationMatrix;
    D3DXMatrixTranslation(&translationMatrix,
                          0.0f,
                          distance / (float)count,
                          0.0f);
    D3DXMATRIX extrudeMatrix = scaleMatrix * rotationXMatrix * rotationYMatrix * rotationZMatrix * translationMatrix;

    Mesh *srcMesh = getInput(0)->mesh;

    int numberOfVertices = srcMesh->getNumVertices();
    int numberOfQuads = srcMesh->getNumQuads();

    // Calculate the new number of quads and vertices.
    // The number of triangles will be unchanged.
    for (int i = 0; i < srcMesh->getNumFaces(); i++)
    {
        int n;
        int *face = srcMesh->face(i, n);

        if (srcMesh->faceSelected(i))
        {
            numberOfQuads += n * count;
            numberOfVertices += n * count;
        }
    }

    mesh = new Mesh(numberOfVertices, srcMesh->getNumTriangles(), numberOfQuads, 1);

    int triangleIndex = 0;
    int quadIndex = 0;

    // Copy the src mesh vertices.
    for (int i = 0; i < srcMesh->getNumVertices(); i++)
    {
        mesh->pos(i) = srcMesh->pos(i);
    }

    int vertexIndex = srcMesh->getNumVertices();
    // Extrude each selected face and add triangles and quads.

    Vec3* lastPositions = new Vec3[4];
    int* lastIndices = new int[4];
    int* currentIndices = new int[4];

    for (int i = 0; i < srcMesh->getNumFaces(); i++)
    {
        int n;
        int *face = srcMesh->face(i, n);

        for (int f = 0; f < n; f++)
        {
            lastPositions[f] = srcMesh->pos(face[f]);
            lastIndices[f] = face[f];
        }

        if (srcMesh->faceSelected(i))
        {
            // Get our base vectors.
            Vec3 pos1 = srcMesh->pos(face[1]);
            Vec3 pos0 = srcMesh->pos(face[0]);
            Vec3 faceBase1 = normalize(pos1 - pos0);
            Vec3 faceBase2 = normalize(srcMesh->getFaceNormal(i));
            Vec3 faceBase3 = normalize(cross(faceBase2, faceBase1));

            D3DXMATRIX fromFaceBaseMatrix = D3DXMATRIX(faceBase1.x, faceBase1.y, faceBase1.z, 0.0f,
                                            faceBase2.x, faceBase2.y, faceBase2.z, 0.0f,
                                            faceBase3.x, faceBase3.y, faceBase3.z, 0.0f,
                                            0.0f,               0.0f,        0.0f, 1.0f);
            D3DXMATRIX toFaceBaseMatrix = D3DXMATRIX(faceBase1.x, faceBase2.x, faceBase3.x, 0.0f,
                                          faceBase1.y, faceBase2.y, faceBase3.y, 0.0f,
                                          faceBase1.z, faceBase2.z, faceBase3.z, 0.0f,
                                          0.0f,               0.0f,        0.0f, 1.0f);

            D3DXMATRIX toFaceBaseAndOrigoMatrix = toFaceBaseMatrix;
            D3DXMATRIX fromFaceBaseAndToFaceMatrix = extrudeMatrix * fromFaceBaseMatrix;

            for (int c = 0; c < count; c++)
            {
                for (int f = 0; f < n; f++)
                {
                    Vec3 pos = lastPositions[f];
                    Vec3 posInFaceBase;
                    D3DXVec3TransformCoord(&posInFaceBase, &pos, &toFaceBaseAndOrigoMatrix);
                    Vec3 posTransformed;
                    D3DXVec3TransformCoord(&posTransformed, &posInFaceBase, &fromFaceBaseAndToFaceMatrix);
                    mesh->pos(vertexIndex) = posTransformed;
                    currentIndices[f] = vertexIndex;
                    lastPositions[f] = posTransformed;
                    vertexIndex++;
                }

                for (int f = 0; f < n; f++)
                {
                    mesh->setQuad(quadIndex,
                                  lastIndices[f],
                                  lastIndices[(f + 1) % n],
                                  currentIndices[(f + 1) % n],
                                  currentIndices[f]);
                    quadIndex++;
                }

                for (int f = 0; f < n; f++)
                {
                    lastIndices[f] = currentIndices[f];
                }
            }
        }


        if (n == 3)
        {
            mesh->setTriangle(triangleIndex, lastIndices[0], lastIndices[1], lastIndices[2]);
            triangleIndex++;
        }
        else
        {
            mesh->setQuad(quadIndex, lastIndices[0], lastIndices[1], lastIndices[2],  lastIndices[3]);
            quadIndex++;
        }
    }

    delete[] lastIndices;
    delete[] currentIndices;
    delete[] lastPositions;

    mesh->recalculateNormals();
}
Ejemplo n.º 4
0
void CRenderManager::Render(CTexture const * _pTexture,
							CRect const * _rImgRect,
							D3DXVECTOR2 const & _vPosition,
							D3DXVECTOR2 const & _vScale,
							D3DCOLOR const _ImgColor,
							D3DXVECTOR2 const & _vCenter,
							float const _fLocalRotAmount,
							float const _fGlobalRotAmount,
							D3DXVECTOR2 const & _vRotationVector) const
{
	RECT _rRect;

	if(_rImgRect)
	{
		_rRect.top		= _rImgRect->m_nY;
		_rRect.bottom	= _rImgRect->m_nY + _rImgRect->m_nHeight;
		_rRect.left		= _rImgRect->m_nX;
		_rRect.right	= _rImgRect->m_nX + _rImgRect->m_nWidth;
	}

	/* NOTE */
	// Expensive call, transforming even when values are 0.

	/* NOTE */
	// Don't need to call identity on any of the matrices. Once the DirectX function gets call (Scale, Rotate, Translate),
	// the matrix becomes identity with the applied values from the function.
	D3DXMATRIX mTransform;

	// Order (SRT -> Scale, Rotate, Translate)
	// Scale
	D3DXMATRIX mScale;
 	D3DXMatrixScaling(&mScale, _vScale.x, _vScale.y, 0.0f);

	// Local Rotation
	D3DXMATRIX mLocalRotation;
	D3DXMATRIX mRotationTranslate;
	D3DXMatrixTranslation(&mRotationTranslate, -_vCenter.x, -_vCenter.y, 0.0f);
 	D3DXMatrixRotationAxis(&mLocalRotation, &D3DXVECTOR3(0.0f, 0.0f, 1.0f), _fLocalRotAmount);
	mLocalRotation = mRotationTranslate * mLocalRotation;

	// Translate
	D3DXMATRIX mTranslation;
	D3DXMatrixTranslation(&mTranslation, (_vPosition.x + _vCenter.x), (_vPosition.y + _vCenter.y), 0.0f);

	// Global Rotation
	D3DXMATRIX mGlobalRotation;
	D3DXMatrixTranslation(&mRotationTranslate, _vRotationVector.x, _vRotationVector.y, 0.0f);
	D3DXMatrixRotationAxis(&mGlobalRotation, &D3DXVECTOR3(0.0f, 0.0f, 1.0f), _fGlobalRotAmount);
	mGlobalRotation = mRotationTranslate * mGlobalRotation;

	// Multiply all the matrices together
	mTransform = mScale * mLocalRotation * mGlobalRotation * mTranslation;

	// Set the transform to move the position, draw, then reset back to origin
	m_pSpriteManager->SetTransform(&mTransform);
	m_pSpriteManager->Draw(_pTexture->GetTexture(), _rImgRect ? (&_rRect) : NULL, 0, 0, _ImgColor);

	// Now reset the picture back to top left of window
	D3DXMatrixIdentity(&mTransform);
	m_pSpriteManager->SetTransform(&mTransform);
}
Ejemplo n.º 5
0
void DXApp::RenderFrame()
{
    _p_device->Clear(0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);
    _p_device->BeginScene();

    _p_device->SetRenderState(D3DRS_AMBIENT,RGB(255,255,255));
    _p_device->SetRenderState(D3DRS_LIGHTING,false);
    _p_device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
    _p_device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
    _p_device->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
    D3DXMatrixPerspectiveFovLH(&matProjection,0.30f,(float)width/height,200.0f,2000.0f);
    //D3DXMatrixRotationX(&trans1, CameraAngleX);
    D3DXMatrixRotationYawPitchRoll(&trans1, 0.0f, CameraAngleX, CameraAngleY);
    D3DXMatrixIdentity(&matView);
    D3DXMatrixLookAtLH( &matView, (D3DXVECTOR3*)&Cam.location,
                        (D3DXVECTOR3*)&(Cam.location + Cam.ViewDir),
                        &D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) );
    //D3DXMatrixMultiply(&matView, &trans1, &matView);
    D3DXMATRIX matLocal;
    D3DXMatrixIdentity(&matLocal);
    _p_device->GetRenderTarget(0, & _back_buffer);

    ///////////////////////////////////////////////////
    //Render Shadow Buffer
    IDirect3DSurface9* _shadow_buffer;
    ShadowBuffer->GetSurfaceLevel(0, &_shadow_buffer);
    _p_device->SetRenderTarget(0, _shadow_buffer);
    _p_device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xFFFFFFFF, 1.0f, 0);

    D3DXMATRIX matSBView;
    D3DXMATRIX matSBProjection;
    D3DXMATRIX matSBFull;

    D3DXMatrixLookAtLH( &matSBView, (D3DXVECTOR3*)&DrawLight.location, &D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), &D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) );
    D3DXMatrixPerspectiveFovLH( &matSBProjection, D3DXToRadian(30.0f), 1,200.0f,2000.0f);
    D3DXMatrixMultiply( &matSBFull, &matSBView, &matSBProjection );

    _p_SB_vertex_constant_able->SetMatrix(_p_device, hSBMatProjection, &matSBFull);

    _p_device->SetFVF(particle_fvf);
    _p_device->SetPixelShader(_p_SB_shader);
    _p_device->SetVertexShader(_p_SB_vshader);

    //now render the scene
    for(int i=0; i < _max_particle_count; i++)
    {
        if(_particle_list[i].Particle != NULL)
        {
            NxMat34 Pose = _particle_list[i].Particle->getGlobalPose();

            float MatTransform[16];
            Pose.getColumnMajor44((NxF32*)&MatTransform);
            D3DXMATRIX Transfom(MatTransform);
            D3DXMatrixScaling(&matLocal, CubeMeshDrawScale, CubeMeshDrawScale, CubeMeshDrawScale);
            D3DXMatrixMultiply(&Transfom, &matLocal, &Transfom);
            _p_SB_vertex_constant_able->SetMatrix(_p_device, hSBMatWorld, &Transfom);
            _particle_Mesh->DrawSubset(0);
        }
    }

    _shadow_buffer->Release();








    /////////////////////////////////////////////////
    //Render Scene
    //_p_device->SetTexture(0, _point_texture);
    IDirect3DSurface9* screen_surface;
    _screen_buffer->GetSurfaceLevel(0, &screen_surface);
    _p_device->SetRenderTarget(0, screen_surface);
    _p_device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xFF000000, 1.0f, 0);
    _p_device->SetRenderTarget(0, _back_buffer);
    _p_device->SetTexture(0, ShadowBuffer);

    IDirect3DSurface9* blur_surface;
    if(bMotionBlur)
    {
        _blur_buffer->GetSurfaceLevel(0, &blur_surface);
        _p_device->SetRenderTarget(1, blur_surface);
        _p_device->Clear(0, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0);
    }
    _p_device->SetRenderTarget(0, screen_surface);
    //Setup the Transform Matricies for the VertexShader;
    _p_vertex_constant_able->SetMatrix(_p_device, hMatProjection, &matProjection);
    _p_vertex_constant_able->SetMatrix(_p_device, hMatView, &matView);
    _p_vertex_constant_able->SetFloatArray(_p_device, hLightPosition, (float*)&DrawLight.location, 3);

    float fTexOffs = 0.5f + (0.5f / (float)ShadowMapSize);
    D3DXMATRIX matTexAdj( 0.5f,     0.0f,     0.0f, 0.0f,
                          0.0f,     -0.5f,    0.0f, 0.0f,
                          0.0f,     0.0f,     1.0f, 0.0f,
                          fTexOffs, fTexOffs, 0.0f, 1.0f );

    D3DXMATRIX matTexture;// = matView;

    //D3DXMatrixInverse( &matTexture, NULL, &matTexture );
    D3DXMatrixIdentity(&matTexture);
    D3DXMatrixMultiply( &matTexture, &matTexture, &matSBFull );
    D3DXMatrixMultiply( &matTexture, &matSBFull, &matTexAdj );

    _p_vertex_constant_able->SetMatrix(_p_device, hMatTexture, &matTexture);

    _p_device->SetFVF(particle_fvf);
    _p_device->SetPixelShader(_p_shader);
    _p_device->SetVertexShader(_p_vshader);

    {
        D3DXMATRIX Transform;

        D3DXMatrixTranslation(&Transform, DrawLight.location.x, DrawLight.location.y, DrawLight.location.z);
        _p_vertex_constant_able->SetFloatArray(_p_device, hDeltaPos, (float*)&NxVec3(0,0,0), 3);
        _p_vertex_constant_able->SetMatrix(_p_device, hMatWorld, &Transform);
        _particle_Mesh->DrawSubset(0);

        D3DXMatrixIdentity(&Transform);
        D3DXMatrixScaling(&Transform, 200.0f, 200.0f, 200.0f);
        D3DXMatrixRotationAxis(&matLocal, &D3DXVECTOR3(1.0f,0.0f,0.0f), D3DXToRadian(90));
        D3DXMatrixMultiply(&Transform, &matLocal, &Transform);
        _p_vertex_constant_able->SetMatrix(_p_device, hMatWorld, &Transform);
        _p_vertex_constant_able->SetFloatArray(_p_device, hDeltaPos, (float*)&NxVec3(0,0,0), 3);


        _p_device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, defQuad, sizeof(NxVec3));
    }
    _p_device->SetFVF(particle_fvf);
    //now render the scene
    for(int i=0; i < _max_particle_count; i++)
    {
        if(_particle_list[i].Particle != NULL)
        {
            //NxVec3 Translation = _particle_list[i].Particle->getGlobalPosition();
            NxVec3 Velocity;
            if(bBlurVel)
                Velocity = _particle_list[i].Particle->getLinearVelocity();
            else
                Velocity = NxVec3(0,0,0);
            NxMat34 Pose = _particle_list[i].Particle->getGlobalPose();

            //Velocity *= _time_step;

            float MatTransform[16];
            Pose.getColumnMajor44((NxF32*)&MatTransform);
            D3DXMATRIX Transfom(MatTransform);
            D3DXMatrixScaling(&matLocal, CubeMeshDrawScale, CubeMeshDrawScale, CubeMeshDrawScale);
            D3DXMatrixMultiply(&Transfom, &matLocal, &Transfom);
            _p_vertex_constant_able->SetMatrix(_p_device, hMatWorld, &Transfom);
            _p_vertex_constant_able->SetFloatArray(_p_device, hDeltaPos, (float*)&Velocity, 3);
            _particle_Mesh->DrawSubset(0);
        }
    }
    _p_device->SetTexture(0, NULL);

    D3DXMatrixIdentity(&matLocal);
    //_p_vertex_constant_able->SetMatrix(_p_device, hMatLocal, &matLocal);
    _p_vertex_constant_able->SetMatrix(_p_device, hMatWorld, &matLocal);
    _p_device->SetRenderState(D3DRS_POINTSPRITEENABLE, true);
    _p_device->SetRenderState(D3DRS_POINTSCALEENABLE,true);
    _p_device->SetRenderState(D3DRS_POINTSIZE,*((DWORD*)&_particle_size));
    _p_device->SetRenderState(D3DRS_POINTSCALE_B,*((DWORD*)&_particle_scale));
    _p_device->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
    _p_device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);
    _p_device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);
    _p_device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
    _p_device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);

    _p_device->SetFVF(light_fvf);
    _p_device->SetPixelShader(_p_lightshader);
    _p_device->DrawPrimitiveUP(D3DPT_POINTLIST, 1, &DrawLight, sizeof(DrawParticle));

    _p_device->SetRenderState(D3DRS_POINTSPRITEENABLE, false);
    _p_device->SetRenderState(D3DRS_POINTSCALEENABLE, false);
    _p_device->SetRenderState(D3DRS_POINTSIZE, 0);
    _p_device->SetRenderState(D3DRS_POINTSCALE_B, 0);
    _p_device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
    _p_device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);
    _p_device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ZERO);

    D3DXMatrixIdentity(&matProjection);
    _p_device->SetRenderTarget(0, _back_buffer);
    _p_device->SetRenderTarget(1, NULL);
    if(blur_surface)
    {
        blur_surface->Release();
        IDirect3DTexture9* tmp;
        tmp=_blur_buffer;
        _blur_buffer=_old_blur_buffer;
        _old_blur_buffer=tmp;
    }
    screen_surface->Release();

    _p_device->SetPixelShader(_p_combinershader);
    _p_device->SetVertexShader(_p_alignshader);
    _p_device->SetTexture(0, _screen_buffer);
    _p_device->SetTexture(1, _blur_buffer);
    _p_device->SetTexture(2, _old_blur_buffer);



    _p_device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, defQuad, sizeof(NxVec3));

    _p_device->SetTexture(0, NULL);
    _p_device->SetTexture(1, NULL);

    //Render the FPS Counter
    RECT Rect;
    SetRect(&Rect, 10, 10, width, height);
    CHAR buffer[128];
    sprintf(buffer, "%d Instant FPS", (int)(1/DeltaTime));
    FPSFont->DrawText(NULL, buffer, -1, &Rect, DT_LEFT|DT_NOCLIP, 0xFFFFFFFF);

    _p_device->EndScene();
    _p_device->Present(NULL, NULL, NULL, NULL);
}
Ejemplo n.º 6
0
void CWndChangeSex::OnDraw( C2DRender* p2DRender ) 
{ 
	if( g_pPlayer == NULL  )
		return;

	LPDIRECT3DDEVICE9 pd3dDevice = p2DRender->m_pd3dDevice;

	pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
	pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
	pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
	pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
	pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
	pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );

	pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
	pd3dDevice->SetSamplerState ( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
	pd3dDevice->SetSamplerState ( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );

	pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );

	pd3dDevice->SetRenderState( D3DRS_AMBIENT,  D3DCOLOR_ARGB( 255, 255,255,255) );
	
	CRect rect = GetClientRect();

	// 뷰포트 세팅 
	D3DVIEWPORT9 viewport;

	// 월드 
	D3DXMATRIXA16 matWorld;
	D3DXMATRIXA16 matScale;
	D3DXMATRIXA16 matRot;
	D3DXMATRIXA16 matTrans;

	// 카메라 
	D3DXMATRIX  matView;
	D3DXVECTOR3 vecLookAt( 0.0f, 0.0f, 3.0f );
	D3DXVECTOR3 vecPos(  0.0f, 0.7f, -3.5f );
	
	D3DXMatrixLookAtLH( &matView, &vecPos, &vecLookAt, &D3DXVECTOR3(0.0f,1.0f,0.0f) );
	
	pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
	
	// 왼쪽 원본 모델 랜더링
	{
		LPWNDCTRL lpFace = GetWndCtrl( WIDC_STATIC1 );

		viewport.X      = p2DRender->m_ptOrigin.x + lpFace->rect.left;//2;
		viewport.X     -= 6;
		viewport.Y      = p2DRender->m_ptOrigin.y + lpFace->rect.top;//5;
		viewport.Width  = lpFace->rect.Width();//p2DRender->m_clipRect.Width();
		viewport.Height = lpFace->rect.Height();// - 10;//p2DRender->m_clipRect.Height();

		viewport.MinZ   = 0.0f;
		viewport.MaxZ   = 1.0f;
		pd3dDevice->SetViewport(&viewport);
		pd3dDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER, 0xffa08080, 1.0f, 0 ) ;

		D3DXMATRIX matProj;
		D3DXMatrixIdentity( &matProj );
		FLOAT fAspect = ((FLOAT)viewport.Width) / (FLOAT)viewport.Height;
/*		
		D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4.0f, fAspect, CWorld::m_fNearPlane - 0.01f, CWorld::m_fFarPlane );
		pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
*/		
		FLOAT fov = D3DX_PI/4.0f;//796.0f;
		FLOAT h = cos(fov/2) / sin(fov/2);
		FLOAT w = h * fAspect;
		D3DXMatrixOrthoLH( &matProj, w, h, CWorld::m_fNearPlane - 0.01f, CWorld::m_fFarPlane );
		pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
		
	    D3DXMatrixIdentity(&matScale);
		D3DXMatrixIdentity(&matTrans);
		D3DXMatrixIdentity(&matWorld);
		
		D3DXMatrixScaling(&matScale, 4.5f, 4.5f, 4.5f);
		
		if( g_pPlayer->GetSex() == SEX_MALE )
			D3DXMatrixTranslation(&matTrans,0.0f,-5.6f,0.0f);
		else
			D3DXMatrixTranslation(&matTrans,0.0f,-5.8f,0.0f);

		D3DXMatrixMultiply(&matWorld,&matWorld,&matScale);
		D3DXMatrixMultiply(&matWorld, &matWorld, &matTrans );
		pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

		// 랜더링 
		pd3dDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );
		pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );//m_bViewLight );
		
		::SetLight( FALSE );
		::SetFog( FALSE );
		SetDiffuse( 1.0f, 1.0f, 1.0f );
		SetAmbient( 1.0f, 1.0f, 1.0f );
/*
		m_pModel->GetObject3D(PARTS_HAIR)->m_fAmbient[0] = 0.5f;
		m_pModel->GetObject3D(PARTS_HAIR)->m_fAmbient[1] = 0.5f;
		m_pModel->GetObject3D(PARTS_HAIR)->m_fAmbient[2] = 0.5f;
*/		
		D3DXVECTOR4 vConst( 1.0f, 1.0f, 1.0f, 1.0f );
#ifdef __YENV
		D3DXVECTOR3 vDir( 0.0f, 0.0f, 1.0f );
		SetLightVec( vDir );
		
		g_Neuz.m_pEffect->SetVector( g_Neuz.m_hvFog, &vConst );
#else //__YENV						
		pd3dDevice->SetVertexShaderConstantF( 95, (float*)&vConst, 1 );
#endif //__YENV
		::SetTransformView( matView );
		::SetTransformProj( matProj );
				
		m_pModel->Render( p2DRender->m_pd3dDevice, &matWorld );
	}
} 
/*!
\b Parameters:

\arg \b pX                          Translation in the X coordinate. The (0, 0) position is the
                                    upper-left corner of the Viewport
\arg \b pY                          Translation in the Y coordinate. The (0, 0) position is the
                                    upper-left corner of the Viewport
\arg \b pAngleX                     Rotation in the angle x in degrees
\arg \b pAngleY                     Rotation in the angle y in degrees
\arg \b pAngleZ                     Rotation in the angle z in degrees
\arg \b pScaleX                     Scaling in the x coordinate. 1 for maintaining the original size
\arg \b pScaleY                     Scaling in the y coordinate. 1 for maintaining the original size
\arg \b pAxisCalX, \b pAxisCalY     Parameters that indicates the displacement that the graphical
                                    object undergoes due to the HotSpot. If the HotSpot is not specified,
                                    the value should be 0 for both of them. All the transformation
                                    will be aplied from the upper-left corner of the object.
\arg \b pMirrorX                    Horizontal mirroring. (true / false) = (activated / deactivated).
\arg \b pMirrorY                    Vertical mirroring. (true / false) = (activated / deactivated).
\arg \b pWidth                      Width of the graphical object that we are going to blit just after
                                    applying the transformation. You shoud use the getWidth() method
                                    of the object.
\arg \b pHeight                     Height of the graphical object that we are going to blit just after
                                    applying the transformation. You shoud use the getHeight() method
                                    on the object.
\arg \b pMatrix                     Pointer to a ::IND_Matrix matrix. In this parameter will be
                                    returned by reference the world matrix transformation that
                                    will be aplied to the graphical object. This matrix can be useful
                                    for advanced programmers that need the algebraic description
                                    of the transformation. It is possible to use the value 0
                                    if it not necessary to have this matrix information.
\b Operation:

This function sets the 2d transformation (translation, rotation, scaling, mirroring and hotspot)
of the following 2d graphical objects that will be rendered
by the engine. You should use this method before calling to any of the Bliting methods.

Remember that you can use IND_Entity2d object for applying 2d transformations to the graphical
objects without having to use this advanced method directly. This method is only useful for advanced
users with really concrete purposes.

Using this method is equivalent to using a combination of these methods:
- IND_Entity2d::setAnimation()
- IND_Entity2d::setSurface()
- IND_Entity2d::setPrimitive2d()
- IND_Entity2d::setFont()
- IND_Entity2d::setPosition()
- IND_Entity2d::setAngleXYZ()
- IND_Entity2d::setScale()
- IND_Entity2d::setBackCull()
- IND_Entity2d::setMirrorX()
- IND_Entity2d::setMirrorY()
- IND_Entity2d::setFilter()
- IND_Entity2d::setHotSpot()
- IND_Entity2d::setRegion()
- IND_Entity2d::toggleWrap()
*/
void DirectXRender::setTransform2d(int pX,
                                   int pY,
                                   float pAngleX,
                                   float pAngleY,
                                   float pAngleZ,
                                   float pScaleX,
                                   float pScaleY,
                                   int pAxisCalX,
                                   int pAxisCalY,
                                   bool pMirrorX,
                                   bool pMirrorY,
                                   int pWidth,
                                   int pHeight,
                                   IND_Matrix *pMatrix) {
	// ----- World matrix initialization -----

	D3DXMATRIX mMatWorld, mMatZ, mMatX, mMatY, mMatTraslation, mMatScale;
	//Initializes every object transform with pixel to point scale transform
	_info._device->SetTransform(D3DTS_WORLD, D3DXMatrixIdentity(&mMatWorld));

	// ----- Transformation matrix creation -----

	// Mirroring (180º rotations)
	if (pMirrorX || pMirrorY) {
		//A mirror is a rotation in desired axis (the actual mirror) and a repositioning because rotation
		//also moves 'out of place' the entity translation-wise
		if (pMirrorX) {
			D3DXMatrixTranslation(&mMatTraslation, 
								  static_cast<float>(- pWidth+pAxisCalX),//pWidth is the neeeded amount for normal mirroring, pAxisCalX is a correction for hotspot
								  static_cast<float>(-pAxisCalY), //Corrects the next translation when hotspot is on in Y
								  0);
			D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatTraslation);
			D3DXMatrixRotationY(&mMatY, D3DXToRadian(180));
			D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatY);
		}

		//A mirror is a rotation in desired axis (the actual mirror) and a repositioning because rotation
		//also moves 'out of place' the entity translation-wise
		if (pMirrorY) {
			D3DXMatrixTranslation(&mMatTraslation, 
								  static_cast<float>(-pAxisCalX),  //Corrects the next translation when hotspot is on in X
								  static_cast<float>( - pHeight+pAxisCalY), //pHeight is the neeeded amount for normal mirroring, pAxisCalY is a correction for hotspot
								  0);
			D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatTraslation);
			D3DXMatrixRotationX(&mMatX, D3DXToRadian(180));
			D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatX);
		}
	}

	// Hotspot
	if (pAxisCalX != 0 || pAxisCalY != 0) {
		D3DXMatrixTranslation(&mMatTraslation, static_cast<float>( pAxisCalX), static_cast<float>( pAxisCalY), 0);
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatTraslation);
	}

	// Scaling
	if (pScaleX != 1.0f || pScaleY != 1.0f) {
		D3DXMatrixScaling(&mMatScale, pScaleX, pScaleY, 1.0f);
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatScale);
	}

	// Rotations
	if (pAngleX != 0.0f) {
		D3DXMatrixRotationX(&mMatX, D3DXToRadian(pAngleX));
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatX);
	}
	if (pAngleY != 0.0f) {
		D3DXMatrixRotationY(&mMatY, D3DXToRadian(pAngleY));
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatY);
	}
	if (pAngleZ != 0.0f) {
		D3DXMatrixRotationZ(&mMatZ, D3DXToRadian(pAngleZ));
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatZ);
	}

	// Translations
	if (pX != 0 || pY != 0) {
		D3DXMatrixTranslation(&mMatTraslation, static_cast<float>(pX), static_cast<float>(pY), 0);
		D3DXMatrixMultiply(&mMatWorld, &mMatWorld, &mMatTraslation);
	}

	// ----- Return World Matrix (in IndieLib format) -----
	if (pMatrix) {
		pMatrix->readFromArray(&mMatWorld.m[0][0]);
	}

	// ----- Applies the transformation -----
	_info._device->SetTransform(D3DTS_WORLD, &mMatWorld);
}
Ejemplo n.º 8
0
/**
* Changes GUI squash and updates matrix.
***/
void ViewAdjustment::ChangeGUISquash(float newSquash)
{
	squash = newSquash;

	D3DXMatrixScaling(&matSquash, squash, squash, 1);
}
Ejemplo n.º 9
0
void cPart::Setup(float fWidth, float fHeight, float fDepth, Cube_Part type){
	ST_PT_VERTEX v;
	D3DXMATRIXA16 matScale, matRotate, matTrans, matFinal;
	m_epart = type;

	float left = -0.5f;
	float top = 0.5f;
	float right = 0.5f;
	float bottom = -0.5f;
	float frontdepth = 0.5f;
	float backdepth = -0.5f;

	//front
	std::vector<ST_PT_VERTEX> plane;
	v.p = D3DXVECTOR3(left, top, 0);
	plane.push_back(v);
	v.p = D3DXVECTOR3(right, top, 0);
	plane.push_back(v);
	v.p = D3DXVECTOR3(left, bottom, 0);
	plane.push_back(v);
	v.p = D3DXVECTOR3(left, bottom, 0);
	plane.push_back(v);
	v.p = D3DXVECTOR3(right, top, 0);
	plane.push_back(v);
	v.p = D3DXVECTOR3(right, bottom, 0);
	plane.push_back(v);

	for (UINT j = 0; j < plane.size(); j++){
		v = plane[j];
		D3DXMatrixRotationY(&matRotate, D3DXToRadian(180.0f));
		//D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z);
		//matFinal = matRotate * matTrans;
		D3DXVec3TransformCoord(&v.p, &v.p, &matRotate);
		v.p.z = v.p.z + frontdepth;
		m_vecVertex.push_back(v);
	}

	// right
	for (UINT j = 0; j < plane.size(); j++){
		v = plane[j];
		D3DXMatrixRotationY(&matRotate, D3DXToRadian(270.0f));
		//D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z);
		//matFinal = matRotate * matTrans;
		D3DXVec3TransformCoord(&v.p, &v.p, &matRotate);
		v.p.x = v.p.x + right;
		m_vecVertex.push_back(v);
	}

	//back
	for (UINT j = 0; j < plane.size(); j++){
		v = plane[j];
		//D3DXMatrixRotationY(&matRotate, D3DXToRadian(0.0f));
		//D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z);
		//matFinal = matRotate * matTrans;
		//D3DXVec3TransformCoord(&v.p, &v.p, &matRotate);
		v.p.z = v.p.z + backdepth;
		m_vecVertex.push_back(v);
	}
	//left
	for (UINT j = 0; j < plane.size(); j++){
		v = plane[j];
		D3DXMatrixRotationY(&matRotate, D3DXToRadian(90.0f));
		//D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z);
		//matFinal = matRotate * matTrans;
		D3DXVec3TransformCoord(&v.p, &v.p, &matRotate);
		v.p.x = v.p.x + left;
		m_vecVertex.push_back(v);
	}

	//top
	for (UINT j = 0; j < plane.size(); j++){
		v = plane[j];
		D3DXMatrixRotationX(&matRotate, D3DXToRadian(90.0f));
		//D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z);
		//matFinal = matRotate * matTrans;
		D3DXVec3TransformCoord(&v.p, &v.p, &matRotate);
		v.p.y = v.p.y + top;
		m_vecVertex.push_back(v);
	}

	// bottom
	// lefttop righttop leftbottom leftbottom righttop rightbottom
	for (UINT j = 0; j < plane.size(); j++){
		v = plane[j];
		D3DXMatrixRotationX(&matRotate, D3DXToRadian(270.0f));
		//D3DXMatrixTranslation(&matTrans, m_vec3Origin.x, m_vec3Origin.y, m_vec3Origin.z);
		//matFinal = matRotate * matTrans;
		D3DXVec3TransformCoord(&v.p, &v.p, &matRotate);
		v.p.y = v.p.y + bottom;
		m_vecVertex.push_back(v);
	}

	D3DXMatrixScaling(&matScale, fWidth, fHeight, fDepth);
	for (UINT i = 0; i < m_vecVertex.size(); i++){
		D3DXVec3TransformCoord(&m_vecVertex[i].p, &m_vecVertex[i].p, &matScale);
	}

	if (type == PT_head){
		// right
		m_vecVertex[0].t = D3DXVECTOR2(128.0f / 1024.0f, 128.0f / 512.0f);
		m_vecVertex[1].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, 128.0f / 512.0f);
		m_vecVertex[2].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[3].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[4].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, 128.0f / 512.0f);
		m_vecVertex[5].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[6].t = D3DXVECTOR2(0.0f, 128.0f / 512.0f);
		m_vecVertex[7].t = D3DXVECTOR2(128.0f / 1024.0f, 128.0f / 512.0f);
		m_vecVertex[8].t = D3DXVECTOR2(0.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[9].t = D3DXVECTOR2(0.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[10].t = D3DXVECTOR2(128.0f / 1024.0f, 128.0f / 512.0f);
		m_vecVertex[11].t = D3DXVECTOR2(128.0f / 1024.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[12].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[13].t = D3DXVECTOR2(((128.0f * 4) - 1.0f) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[14].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[15].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[16].t = D3DXVECTOR2(((128.0f * 4) - 1.0f) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[17].t = D3DXVECTOR2(((128.0f * 4) - 1.0f) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[18].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[19].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[20].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[21].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[22].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[23].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[24].t = D3DXVECTOR2((128.0f * 1) / 1024.0f, (128.0f * 0) / 512.0f);
		m_vecVertex[25].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 0) / 512.0f);
		m_vecVertex[26].t = D3DXVECTOR2((128.0f * 1) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[27].t = D3DXVECTOR2((128.0f * 1) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[28].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 0) / 512.0f);
		m_vecVertex[29].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[30].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 0) / 512.0f);
		m_vecVertex[31].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 0) / 512.0f);
		m_vecVertex[32].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[33].t = D3DXVECTOR2((128.0f * 2) / 1024.0f, (128.0f * 1) / 512.0f);
		m_vecVertex[34].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 0) / 512.0f);
		m_vecVertex[35].t = D3DXVECTOR2((128.0f * 3) / 1024.0f, (128.0f * 1) / 512.0f);
	}
	else if (type == PT_body){
		//front
		m_vecVertex[0].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[1].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[2].t = D3DXVECTOR2(320.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[3].t = D3DXVECTOR2(320.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[4].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[5].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[6].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[7].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[8].t = D3DXVECTOR2(256.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[9].t = D3DXVECTOR2(256.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[10].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[11].t = D3DXVECTOR2(320.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[12].t = D3DXVECTOR2(510.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[13].t = D3DXVECTOR2(640.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[14].t = D3DXVECTOR2(510.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[15].t = D3DXVECTOR2(510.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[16].t = D3DXVECTOR2(640.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[17].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[18].t = D3DXVECTOR2(448.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[19].t = D3DXVECTOR2(560.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[20].t = D3DXVECTOR2(448.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[21].t = D3DXVECTOR2(448.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[22].t = D3DXVECTOR2(560.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[23].t = D3DXVECTOR2(560.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[24].t = D3DXVECTOR2(320.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[25].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[26].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[27].t = D3DXVECTOR2(320.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[28].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[29].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[30].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[31].t = D3DXVECTOR2((128.0f * 2 + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[32].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[33].t = D3DXVECTOR2((128.0f + 320.0f) / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[34].t = D3DXVECTOR2((128.0f * 2 + 320.0f) / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[35].t = D3DXVECTOR2((128.0f * 2 + 320.0f) / 1024.0f, 320.0f / 512.0f);
	}
	else if (type == PT_arm_left){
		m_vecVertex[0].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[1].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[2].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[3].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[4].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[5].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);

		m_vecVertex[6].t = D3DXVECTOR2(640.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[7].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[8].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[9].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[10].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[11].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f);

		m_vecVertex[12].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[13].t = D3DXVECTOR2(896.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[14].t = D3DXVECTOR2(832.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[15].t = D3DXVECTOR2(832.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[16].t = D3DXVECTOR2(896.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[17].t = D3DXVECTOR2(896.0f / 1024.0f, 512.0f / 512.0f);

		m_vecVertex[18].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[19].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[20].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[21].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[22].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[23].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);

		m_vecVertex[24].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[25].t = D3DXVECTOR2(704.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[26].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[27].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[28].t = D3DXVECTOR2(704.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[29].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);

		m_vecVertex[30].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[31].t = D3DXVECTOR2(832.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[32].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[33].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[34].t = D3DXVECTOR2(832.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[35].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
	}
	else if (type == PT_arm_right || type == PT_fist){
		m_vecVertex[0].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[1].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[2].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[3].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[4].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[5].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[6].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[7].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[8].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[9].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[10].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[11].t = D3DXVECTOR2(768.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[12].t = D3DXVECTOR2(896.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[13].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[14].t = D3DXVECTOR2(896.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[15].t = D3DXVECTOR2(896.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[16].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[17].t = D3DXVECTOR2(832.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[18].t = D3DXVECTOR2(640.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[19].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[20].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[21].t = D3DXVECTOR2(640.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[22].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[23].t = D3DXVECTOR2(704.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[24].t = D3DXVECTOR2(704.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[25].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[26].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[27].t = D3DXVECTOR2(704.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[28].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[29].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[30].t = D3DXVECTOR2(768.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[31].t = D3DXVECTOR2(832.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[32].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[33].t = D3DXVECTOR2(768.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[34].t = D3DXVECTOR2(832.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[35].t = D3DXVECTOR2(832.0f / 1024.0f, 320.0f / 512.0f);
	}
	else if (type == PT_leg_left){
		m_vecVertex[0].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[1].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[2].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[3].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[4].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[5].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[6].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[7].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[8].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[9].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[10].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[11].t = D3DXVECTOR2(256.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[12].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[13].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[14].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[15].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[16].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[17].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[18].t = D3DXVECTOR2(0 / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[19].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[20].t = D3DXVECTOR2(0 / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[21].t = D3DXVECTOR2(0 / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[22].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[23].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[24].t = D3DXVECTOR2(64.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[25].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[26].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[27].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[28].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[29].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[30].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[31].t = D3DXVECTOR2(192.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[32].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[33].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[34].t = D3DXVECTOR2(192.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[35].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f);
	}
	else if (type == PT_leg_right){
		m_vecVertex[0].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[1].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[2].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[3].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[4].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[5].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[6].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[7].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[8].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[9].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[10].t = D3DXVECTOR2(256.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[11].t = D3DXVECTOR2(256.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[12].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[13].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[14].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[15].t = D3DXVECTOR2(192.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[16].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[17].t = D3DXVECTOR2(128.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[18].t = D3DXVECTOR2(0 / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[19].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[20].t = D3DXVECTOR2(0 / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[21].t = D3DXVECTOR2(0 / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[22].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[23].t = D3DXVECTOR2(64.0f / 1024.0f, 512.0f / 512.0f);
		m_vecVertex[24].t = D3DXVECTOR2(64.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[25].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[26].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[27].t = D3DXVECTOR2(64.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[28].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[29].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[30].t = D3DXVECTOR2(128.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[31].t = D3DXVECTOR2(192.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[32].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[33].t = D3DXVECTOR2(128.0f / 1024.0f, 320.0f / 512.0f);
		m_vecVertex[34].t = D3DXVECTOR2(192.0f / 1024.0f, (128.0f * 2) / 512.0f);
		m_vecVertex[35].t = D3DXVECTOR2(192.0f / 1024.0f, 320.0f / 512.0f);
	}

	g_pD3DDevice->CreateVertexBuffer(
		m_vecVertex.size() * sizeof(ST_PT_VERTEX),
		D3DUSAGE_WRITEONLY,
		ST_PT_VERTEX::FVF,
		D3DPOOL_MANAGED,
		&m_pVertexBuffer,
		0
		);

	ST_PT_VERTEX* buffv;
	m_pVertexBuffer->Lock(0, 0, (void**)&buffv, 0);

	memcpy(buffv, &m_vecVertex[0], m_vecVertex.size() * sizeof(ST_PT_VERTEX));

	//for (size_t i = 0; i < m_vecVertex.size(); i++){
	//	buffv[i] = m_vecVertex[i];
	//}
	
	m_pVertexBuffer->Unlock();
}
VOID Update()
{
	DWORD currentTime = GetTickCount();
	static DWORD preTime;
	g_ElapsedTime = currentTime - preTime;
	preTime = currentTime;

	if ( GetAsyncKeyState( VK_LEFT ) )
	{
		g_Box[0].CenterPos.x -= g_ElapsedTime*0.002f;
	}
	if ( GetAsyncKeyState( VK_RIGHT ) )
	{
		g_Box[0].CenterPos.x += g_ElapsedTime*0.002f;
	}
	if ( GetAsyncKeyState( VK_UP ) )
	{
		g_Box[0].CenterPos.y += g_ElapsedTime*0.002f;
	}
	if ( GetAsyncKeyState( VK_DOWN ) )
	{
		g_Box[0].CenterPos.y -= g_ElapsedTime*0.002f;
	}
	if ( GetAsyncKeyState( VK_LBUTTON ) )
	{
		if (g_ElapsedTime > 20)
		{
			g_Method = !g_Method;
		}
		
	}
	if ( GetAsyncKeyState( VK_HOME ) )
	{
		g_Box[1].BoxRotateZ -= 0.2f;
	}
	if ( GetAsyncKeyState( VK_END ) )
	{
		g_Box[1].BoxRotateZ += 0.2f;
	}

	D3DXVECTOR3 *vertices;

	g_pMesh->LockVertexBuffer( D3DLOCK_READONLY, (void**) &vertices );
	D3DXComputeBoundingBox( vertices, g_pMesh->GetNumVertices(), g_pMesh->GetNumBytesPerVertex(), &g_MinPoint, &g_MaxPoint );
	g_pMesh->UnlockVertexBuffer();

	D3DXMATRIX matScale, matTrans, matRotateZ, matWorld;
	D3DXMatrixTranslation( &matTrans, g_Box[0].CenterPos.x, g_Box[0].CenterPos.y, g_Box[0].CenterPos.z );
	D3DXMatrixScaling( &matScale, g_Box[0].BoxScaling, g_Box[0].BoxScaling, g_Box[0].BoxScaling );
	D3DXMatrixRotationZ( &matRotateZ, g_Box[0].BoxRotateZ );

	matWorld = matRotateZ* matScale * matTrans;
	D3DXVec3TransformCoord( &g_Box[0].MinPoint, &g_MinPoint, &matWorld );
	D3DXVec3TransformCoord( &g_Box[0].MaxPoint, &g_MaxPoint, &matWorld );
	
	if (!g_Method)
	{
		g_CheckFlag = CheckAABBIntersection( &g_Box[0].MinPoint, &g_Box[0].MaxPoint, &g_Box[1].MinPoint, &g_Box[1].MaxPoint );
	}
	else
	{
		g_CheckFlag = CheckOBBIntersection( &g_Box[0], &g_Box[1] );
	}
	
}
Ejemplo n.º 11
0
/**
* Gets the view-projection transform matrices left and right.
* Unprojects, shifts view position left/right (using same matricies as (Left/Right)ViewRollAndShift)
* and reprojects using left/right projection.
* (matrix = projectionInverse * transform * projection)
***/
void ViewAdjustment::ComputeViewTransforms()
{
	// separation settings are overall (HMD and desktop), since they are based on physical IPD
	D3DXMatrixTranslation(&transformLeft, SeparationInWorldUnits() * LEFT_CONSTANT, 0, 0);
	D3DXMatrixTranslation(&transformRight, SeparationInWorldUnits() * RIGHT_CONSTANT, 0, 0);

	// projection transform, no roll
	matViewProjTransformLeftNoRoll = matProjectionInv * transformLeft * projectLeft;
	matViewProjTransformRightNoRoll = matProjectionInv * transformRight * projectRight;

	// head roll
	if (rollEnabled) {
		D3DXMatrixMultiply(&transformLeft, &rollMatrix, &transformLeft);
		D3DXMatrixMultiply(&transformRight, &rollMatrix, &transformRight);

		// projection 
		matViewProjLeft = matProjectionInv * rollMatrix * projectLeft;
		matViewProjRight = matProjectionInv * rollMatrix * projectRight;
	}
	else
	{
		// projection 
		matViewProjLeft = matProjectionInv * projectLeft;
		matViewProjRight = matProjectionInv * projectRight;
	}

	// projection transform
	matViewProjTransformLeft = matProjectionInv * transformLeft * projectLeft;
	matViewProjTransformRight = matProjectionInv * transformRight * projectRight;

	// now, create HUD/GUI helper matrices

	// if not HMD, set HUD/GUI to fullscreen
	if ((stereoType != 26) && // != StereoView::StereoTypes::OCULUS_RIFT
		(stereoType != 27) && // != StereoView::StereoTypes::OCULUS_RIFT_CROPPED
		(stereoType != 25))   // != StereoView::StereoTypes::DIY_RIFT))
	{
		squash = 1.0f;
		gui3DDepth = 0.0f;
		hudDistance = 0.0f;
		hud3DDepth = 0.0f;
	}

	// squash
	D3DXMatrixScaling(&matSquash, squash, squash, 1);

	// hudDistance
	D3DXMatrixTranslation(&matHudDistance, 0, 0, hudDistance);

	// hud3DDepth
	D3DXMatrixTranslation(&matLeftHud3DDepth, hud3DDepth, 0, 0);
	D3DXMatrixTranslation(&matRightHud3DDepth, -hud3DDepth, 0, 0);
	float additionalSeparation = (1.5f-hudDistance)*hmdInfo.lensXCenterOffset;
	D3DXMatrixTranslation(&matLeftHud3DDepthShifted, hud3DDepth+additionalSeparation, 0, 0);
	D3DXMatrixTranslation(&matRightHud3DDepthShifted, -hud3DDepth-additionalSeparation, 0, 0);
	D3DXMatrixTranslation(&matLeftGui3DDepth, gui3DDepth+SeparationIPDAdjustment(), 0, 0);
	D3DXMatrixTranslation(&matRightGui3DDepth, -(gui3DDepth+SeparationIPDAdjustment()), 0, 0);

	// gui/hud matrices
	matHudLeft = matProjectionInv * matLeftHud3DDepth * transformLeft * matHudDistance *  projectLeft;
	matHudRight = matProjectionInv * matRightHud3DDepth * transformRight * matHudDistance * projectRight;
	matGuiLeft =  matProjectionInv * matLeftGui3DDepth * matSquash * projectLeft;
	matGuiRight = matProjectionInv * matRightGui3DDepth * matSquash * projectRight;
}
HRESULT InitGeometry( )
{
	if (FAILED(D3DXCreateBox(g_pD3DDevice, 1.f, 1.f, 1.f, &g_pMesh, NULL)))
	{
		return E_FAIL;
	}

	D3DXVECTOR3 *vertices;
	
	
	g_pMesh->LockVertexBuffer( D3DLOCK_READONLY, (void**) &vertices );
	D3DXComputeBoundingBox( vertices, g_pMesh->GetNumVertices(), g_pMesh->GetNumBytesPerVertex(), &g_MinPoint, &g_MaxPoint );
	g_pMesh->UnlockVertexBuffer();

	
	D3DXMATRIX matScale, matTrans, matRotateZ, matWorld;

	g_Box[0].BoxScaling = 1.5f;
	g_Box[0].CenterPos = D3DXVECTOR3( 0.f, 0.f, 0.f );
	g_Box[0].BoxRotateZ = 0.f;
	g_Box[0].AxisDir[0] = D3DXVECTOR3( 1, 0, 0 );
	g_Box[0].AxisDir[1] = D3DXVECTOR3( 0, 1, 0 );
	g_Box[0].AxisDir[2] = D3DXVECTOR3( 0, 0, 1 );

	for ( int i = 0; i < 3; ++i )
	{
		g_Box[0].AxisLen[i] = 0.5f;

		D3DXVec3TransformNormal( &(g_Box[0].AxisDir[i]), &(g_Box[0].AxisDir[i]), &matRotateZ );
		D3DXVec3Normalize( &( g_Box[0].AxisDir[i] ), &( g_Box[0].AxisDir[i] ) );
		g_Box[0].AxisLen[i] = g_Box[0].AxisLen[i] * g_Box[0].BoxScaling;
	}
	D3DXMatrixTranslation( &matTrans, g_Box[0].CenterPos.x, g_Box[0].CenterPos.y, g_Box[0].CenterPos.z );
	D3DXMatrixScaling( &matScale, g_Box[0].BoxScaling, g_Box[0].BoxScaling, g_Box[0].BoxScaling );
	D3DXMatrixRotationZ( &matRotateZ, g_Box[0].BoxRotateZ );

	matWorld = matRotateZ* matScale * matTrans;
	D3DXVec3TransformCoord( &g_Box[0].MinPoint, &g_MinPoint, &matWorld );
	D3DXVec3TransformCoord( &g_Box[0].MaxPoint, &g_MaxPoint, &matWorld );

	
	g_Box[1].BoxScaling = 2.f;
	g_Box[1].CenterPos = D3DXVECTOR3( 3.f, 3.f, 0.f );
	g_Box[1].BoxRotateZ = 0.f;
	g_Box[1].AxisDir[0] = D3DXVECTOR3( 1, 0, 0 );
	g_Box[1].AxisDir[1] = D3DXVECTOR3( 0, 1, 0 );
	g_Box[1].AxisDir[2] = D3DXVECTOR3( 0, 0, 1 );

	for ( int i = 0; i < 3; ++i )
	{
		g_Box[1].AxisLen[i] = 0.5f;

		D3DXVec3TransformNormal( &( g_Box[0].AxisDir[i] ), &( g_Box[1].AxisDir[i] ), &matRotateZ );
		D3DXVec3Normalize( &( g_Box[1].AxisDir[i] ), &( g_Box[1].AxisDir[i] ) );
		g_Box[1].AxisLen[i] = g_Box[1].AxisLen[i] * g_Box[1].BoxScaling;
	}

	D3DXMatrixTranslation( &matTrans, g_Box[1].CenterPos.x, g_Box[1].CenterPos.y, g_Box[1].CenterPos.z );
	D3DXMatrixScaling( &matScale, g_Box[1].BoxScaling, g_Box[1].BoxScaling, g_Box[1].BoxScaling );
	D3DXMatrixRotationZ( &matRotateZ, g_Box[1].BoxRotateZ );

	matWorld = matRotateZ* matScale * matTrans;
	D3DXVec3TransformCoord( &g_Box[1].MinPoint, &g_MinPoint, &matWorld );
	D3DXVec3TransformCoord( &g_Box[1].MaxPoint, &g_MaxPoint, &matWorld );


	return S_OK;
}
Ejemplo n.º 13
0
//*************************************************************************************************************
void Render(float alpha, float elapsedtime)
{
	static float time = 0;

	D3DXMATRIX	inv;
	D3DXVECTOR3	axis(0, 1, 0);
	D3DXVECTOR4	texelsize(1.0f / (float)screenwidth, 1.0f / (float)screenheight, 0, 1);
	
	LPDIRECT3DSURFACE9 oldtarget = NULL;

	time += elapsedtime;

	D3DXMatrixRotationAxis(&inv, &axis, time);
	D3DXMatrixScaling(&world, 0.3f, 0.3f, 0.3f);
	//D3DXMatrixScaling(&world, 0.6f, 0.6f, 0.6f);
	D3DXMatrixMultiply(&world, &world, &inv);
	D3DXMatrixInverse(&inv, NULL, &world);

	device->SetTexture(0, texture);
	device->SetTexture(1, intensity);

	effect->SetMatrix("matWorld", &world);
	effect->SetMatrix("matWorldInv", &inv);
	effect->SetMatrix("matView", &view);
	effect->SetMatrix("matProj", &proj);

	if( useedgedetect )
	{
		device->GetRenderTarget(0, &oldtarget);
		device->SetRenderTarget(0, colorsurface);
		device->SetRenderTarget(1, normalsurface);
	}

	device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff6694ed, 1.0f, 0);

	if( SUCCEEDED(device->BeginScene()) )
	{
		// draw scene + normals/depth
		effect->SetTechnique("celshading");

		effect->Begin(NULL, 0);
		effect->BeginPass(0);
		{
			mesh->DrawSubset(0);
		}
		effect->EndPass();
		effect->End();

		if( useedgedetect )
		{
			// edge detection
			device->SetVertexDeclaration(vertexdecl);
			device->SetRenderTarget(0, edgesurface);
			device->SetRenderTarget(1, NULL);
			device->SetTexture(0, normaltarget);
			device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xff6694ed, 1.0f, 0);

			effect->SetTechnique("edgedetect");
			effect->SetVector("texelSize", &texelsize);

			effect->Begin(NULL, 0);
			effect->BeginPass(0);
			{
				device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, vertices, sizeof(D3DXVECTOR4) + sizeof(D3DXVECTOR2));
			}
			effect->EndPass();
			effect->End();

			// put together
			device->SetRenderTarget(0, oldtarget);
			device->SetTexture(0, colortarget);
			device->SetTexture(2, edgetarget);
			device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xff6694ed, 1.0f, 0);

			oldtarget->Release();
			effect->SetTechnique("final");

			effect->Begin(NULL, 0);
			effect->BeginPass(0);
			{
				device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, vertices, sizeof(D3DXVECTOR4) + sizeof(D3DXVECTOR2));
			}
			effect->EndPass();
			effect->End();
		}
		else
		{
			D3DXMATRIX offproj;

			// use the stencil buffer
			device->SetRenderState(D3DRS_COLORWRITEENABLE, 0);
			device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
			device->SetRenderState(D3DRS_STENCILENABLE, TRUE);
			device->SetRenderState(D3DRS_ZENABLE, FALSE);

			device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
			device->SetRenderState(D3DRS_STENCILREF, 1);
			device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE);

			device->SetTransform(D3DTS_WORLD, &world);
			device->SetTransform(D3DTS_VIEW, &view);

			float thickness = 3.5f;

			// render object 4 times with offseted frustum
			for( float i = -thickness; i < thickness + 1; i += 2 * thickness )
			{
				for( float j = -thickness; j < thickness + 1; j += 2 * thickness )
				{
					D3DXMatrixTranslation(&offproj, i / (float)screenwidth, j / (float)screenheight, 0);
					D3DXMatrixMultiply(&offproj, &proj, &offproj);

					device->SetTransform(D3DTS_PROJECTION, &offproj);
					mesh->DrawSubset(0);
				}
			}

			// erase area in the center
			device->SetRenderState(D3DRS_STENCILREF, 0);
			device->SetTransform(D3DTS_PROJECTION, &proj);

			mesh->DrawSubset(0);

			// now render outlines
			device->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED|D3DCOLORWRITEENABLE_GREEN|D3DCOLORWRITEENABLE_BLUE|D3DCOLORWRITEENABLE_ALPHA);
			device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_NOTEQUAL);
			device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
			device->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);

			device->SetFVF(D3DFVF_XYZRHW|D3DFVF_TEX1);

			device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
			device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_CONSTANT);
			device->SetTextureStageState(0, D3DTSS_CONSTANT, 0);
			{
				device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, vertices, sizeof(D3DXVECTOR4) + sizeof(D3DXVECTOR2));
			}
			device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
			device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);

			device->SetRenderState(D3DRS_ZENABLE, TRUE);
			device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
			device->SetRenderState(D3DRS_STENCILENABLE, FALSE);
		}

		device->SetTexture(2, NULL);

		// render text
		device->SetFVF(D3DFVF_XYZRHW|D3DFVF_TEX1);
		device->SetRenderState(D3DRS_ZENABLE, FALSE);
		device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
		device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
		device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

		device->SetTexture(0, text);
		device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 2, textvertices, 6 * sizeof(float));

		device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
		device->SetRenderState(D3DRS_ZENABLE, TRUE);

		device->SetTexture(0, NULL);
		device->EndScene();
	}

	device->Present(NULL, NULL, NULL, NULL);
}
Ejemplo n.º 14
0
void CloneMeshOperator::process(int tick)
{
    if (mesh != 0)
        delete mesh;

    unsigned char clones = getByteProperty(0);
    D3DXVECTOR3 scaleVector = getVectorProperty(1);
    D3DXVECTOR3 rotationVector = getVectorProperty(2);
    D3DXVECTOR3 translationVector = getVectorProperty(3);
    D3DXMATRIX scaleMatrix;
    D3DXMatrixScaling(&scaleMatrix,
                      scaleVector.x,
                      scaleVector.y,
                      scaleVector.z);
    D3DXMATRIX rotationXMatrix;
    D3DXMatrixRotationX(&rotationXMatrix, rotationVector.x);
    D3DXMATRIX rotationYMatrix;
    D3DXMatrixRotationY(&rotationYMatrix, rotationVector.y);
    D3DXMATRIX rotationZMatrix;
    D3DXMatrixRotationZ(&rotationZMatrix, rotationVector.z);
    D3DXMATRIX translationMatrix;
    D3DXMatrixTranslation(&translationMatrix,
                          translationVector.x,
                          translationVector.y,
                          translationVector.z);
    D3DXMATRIX cloneMatrix = scaleMatrix * rotationXMatrix * rotationYMatrix * rotationZMatrix * translationMatrix;

    Mesh* srcMesh = getInput(0)->mesh;

    mesh = new Mesh(srcMesh->getNumVertices() * clones,
                    srcMesh->getNumTriangles() * clones,
                    srcMesh->getNumQuads() * clones);

    D3DXMATRIX matrix;
    D3DXMatrixIdentity(&matrix);

    int c = 0;
    int verticeOffset = 0;
    int triangleIndex = 0;
    int quadIndex = 0;
    do
    {
        c++;
        for (int v = 0; v < srcMesh->getNumVertices(); v++)
        {
            Vec3 pos = srcMesh->pos(v);
            Vec3 transformedPos;
            D3DXVec3TransformCoord(&transformedPos, &pos, &matrix);
            mesh->pos(verticeOffset + v) = transformedPos;
            mesh->uv(verticeOffset + v) = srcMesh->uv(v);
        }

        for (int f = 0; f < srcMesh->getNumFaces(); f++)
        {
            int n;
            int* face = srcMesh->face(f, n);

            if (n == 3)
            {
                mesh->setTriangle(triangleIndex,
                                  verticeOffset + face[0],
                                  verticeOffset + face[1],
                                  verticeOffset + face[2]);
                triangleIndex++;
            }
            else
            {
                mesh->setQuad(quadIndex,
                              verticeOffset + face[0],
                              verticeOffset + face[1],
                              verticeOffset + face[2],
                              verticeOffset + face[3]);
                quadIndex++;
            }
        }

        verticeOffset += srcMesh->getNumVertices();
        matrix *= cloneMatrix;
    }
    while (c < clones);
}
Ejemplo n.º 15
0
void Dio::init(ResourceManager* resMan)
{
	for (int i=0;i<256;i++)
	{
		text[i]=0;
	}
	c=0;
	size_of_container=0;
	//timer initializer
	FPS=20;
	now = clock();
	delay = 1000/FPS;
	//speaker position and color
	speaker[0].rec.bottom=0;
	speaker[0].rec.left=0;
	speaker[0].rec.right=100;
	speaker[0].rec.top=400;
	speaker[0].textColor=D3DCOLOR_ARGB(255,255,255,255);
	//text position and color
	speaker[1].rec.bottom=0;
	speaker[1].rec.left=440;
	speaker[1].rec.right=400;
	speaker[1].rec.top=450;
	speaker[1].textColor=D3DCOLOR_ARGB(255,255,255,255);

	D3DXMATRIX matrixlove;
	D3DXMATRIX matrixlove1;
	D3DXMATRIX matrixlove2;
	D3DXMatrixIdentity(&matrixlove);
	D3DXMatrixIdentity(&matrixlove1);
	D3DXMatrixIdentity(&matrixlove2);
	D3DXMatrixScaling(&matrixlove,0.5f,0.5f,0.5f);
	D3DXMatrixTranslation(&matrixlove1,20,150,0);
	D3DXMatrixMultiply(&matrixlove2,&matrixlove1,&matrixlove);
	/*
	for (int i=0;i<=maxpics;i++)
	{
		pics[i].tex=stuff[i+9].objTex;
		pics[i].texinfo=stuff[i+9].texInfo;
		pics[i].matrix= matrixlove2;
	}
	*/

	for (int i=0;i<=maxpics;i++)
	{
		pics[i].matrix= matrixlove2;
	}

	pics[0].tex = resMan->getTexture(L"snake.png")->objTex;
	pics[0].texinfo = resMan->getTexture(L"snake.png")->texInfo;

	pics[1].tex = resMan->getTexture(L"joy.png")->objTex;
	pics[1].texinfo = resMan->getTexture(L"joy.png")->texInfo;

	pics[2].tex = resMan->getTexture(L"solidchu.png")->objTex;
	pics[2].texinfo = resMan->getTexture(L"solidchu.png")->texInfo;

	pics[3].tex = resMan->getTexture(L"evilchu.png")->objTex;
	pics[3].texinfo = resMan->getTexture(L"evilchu.png")->texInfo;

	texholder.tex=0;
	readname=true;
	readtext=true;
	saidtext=true;
	infile.open("Dialogue.txt");
}
Ejemplo n.º 16
0
//////////////////////////////////////////////////////////////////////////
//	setSize
//	(desc) return scale matrix which scales by size_
//	(ref) this shadow object is unit length(1) 2d box
//	+ helper function
//////////////////////////////////////////////////////////////////////////
rmatrix ZShadow::setSize( float size_  )
{
	rmatrix ScaleMatrix;
	D3DXMatrixScaling( &ScaleMatrix, size_, size_, size_ );
	return ScaleMatrix;
}
Ejemplo n.º 17
0
SphereClass::SphereClass(char* objFileName) : ObjModelClass(objFileName)
{
	m_is2D = false;
	D3DXMatrixScaling(&m_worldMatrix, 5.0f, 5.0f, 5.0f);
}
Ejemplo n.º 18
0
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  MSG    msg;
  HRESULT rval;

  rval = InitInstance(hInstance, lpCmdLine, nCmdShow, SCREEN_WIDTH, SCREEN_HEIGHT);
  if (rval != S_OK)
  {
		if( ERR_FILENOTFOUND != rval )	// annunciated by InitInstance
	    DisplayErrorCode(rval);
    exit(rval);
  }

  // create the core engine
  g_pEngine = new (_NORMAL_BLOCK, __FILE__, __LINE__)C3DEngine;
  rval = g_pEngine->Init(g_hWnd, g_hInstance, g_szAppName);
  if (rval)
  {
    DisplayErrorCode(rval);
    exit(rval);
  }  

	// initialize controllers
	rval = InitControllers();
  if (rval)
  {
    DisplayErrorCode(rval);
    exit(rval);
  }

  // create a room object
  g_pRoomObject = new C3DFrameObject;
  rval = g_pRoomObject->Init(g_pEngine, g_szRoomFileName );
  if (rval)
  {
    DisplayErrorCode(rval);
    exit(rval);
  }

	// scale it
	D3DXMATRIX mScale, mIdentity;
	D3DXMatrixIdentity( &mIdentity );
	D3DXMatrixScaling( &mScale, g_fRoomScale, g_fRoomScale, g_fRoomScale );
	g_pRoomObject->SetMatrices( &mIdentity, &mScale );

  // add it to our world
  rval = g_pEngine->AddChild(g_pRoomObject);
  if (rval)
  {
    DisplayErrorCode(rval);
    exit(rval);
  }

	// message pump
  do
  {
    if (PeekMessage(&msg, g_hWnd, 0, 0,PM_REMOVE))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    else
    {

      // idle tasks here...

			// This is where the glove can change values
		  // Read the current values
		  float x = g_pKeyboardControl->GetRawValue("HandX");
		  float y = g_pKeyboardControl->GetRawValue("HandY");
		  float z = g_pKeyboardControl->GetRawValue("HandZ");
		  float yaw = g_pKeyboardControl->GetRawValue("HandYaw");
		  float pitch = g_pKeyboardControl->GetRawValue("HandPitch");
		  float roll = g_pKeyboardControl->GetRawValue("HandRoll");
		  float thumb = g_pKeyboardControl->GetRawValue("ThumbCurl");
		  float index = g_pKeyboardControl->GetRawValue("IndexCurl1");
		  float middle = g_pKeyboardControl->GetRawValue("MiddleCurl1");
		  float ring = g_pKeyboardControl->GetRawValue("RingCurl1");
		  float pinky = g_pKeyboardControl->GetRawValue("PinkyCurl1");
		 
		  // Allow Glove to change values
		  ReadGloveValues(x,y,z,yaw,pitch,roll,thumb,index,middle,ring,pinky);
		 
		  // Write the changes back to the keyboard control
		  g_pKeyboardControl->SetRawValue("HandX",x);
		  g_pKeyboardControl->SetRawValue("HandY",y);
		  g_pKeyboardControl->SetRawValue("HandZ",z);
		  g_pKeyboardControl->SetRawValue("HandYaw",yaw);
		  g_pKeyboardControl->SetRawValue("HandPitch",pitch);
		  g_pKeyboardControl->SetRawValue("HandRoll",roll);
		  g_pKeyboardControl->SetRawValue("ThumbCurl",thumb);
		  g_pKeyboardControl->SetRawValue("ThumbCurl2",thumb);
		  g_pKeyboardControl->SetRawValue("IndexCurl1",index);
		  g_pKeyboardControl->SetRawValue("IndexCurl2",index);
		  g_pKeyboardControl->SetRawValue("IndexCurl3",index);
		  g_pKeyboardControl->SetRawValue("MiddleCurl1",middle);
		  g_pKeyboardControl->SetRawValue("MiddleCurl2",middle);
		  g_pKeyboardControl->SetRawValue("MiddleCurl3",middle);
		  g_pKeyboardControl->SetRawValue("RingCurl1",ring);
		  g_pKeyboardControl->SetRawValue("RingCurl2",ring);
		  g_pKeyboardControl->SetRawValue("RingCurl3",ring);
		  g_pKeyboardControl->SetRawValue("PinkyCurl1",pinky);
		  g_pKeyboardControl->SetRawValue("PinkyCurl2",pinky);
		  g_pKeyboardControl->SetRawValue("PinkyCurl3",pinky);

			// render the scene
			g_pEngine->Render();

      // show the back surface
      g_pEngine->Flip();
    }

  } while (msg.message != WM_QUIT);

	// clean up
	delete g_pKeyboardControl;
	
  // destroy and delete the engine
  g_pEngine->Destroy();
  delete g_pEngine;
  g_pEngine = NULL;

	for(int n=0; n<g_iNumModels; n++)
	{
		delete g_szMenuModelNames[n];
		delete g_szModelFileNames[n];
	}
  return 0;
}
Ejemplo n.º 19
0
void Player::UpdateAndRender()
{
	D3DXVECTOR3 pos = position;
	D3DXVECTOR3 direction;
	D3DXVECTOR3 up = D3DXVECTOR3(0, 1, 0);
	D3DXVECTOR3 forward = D3DXVECTOR3(0, 0, 1);
	D3DXVECTOR3 right;
	
	D3DXMATRIXA16 rotation;

	rotationAngle = GameManager::GetCamera()->GetRotateY();
	
	D3DXMatrixRotationY(&rotation, rotationAngle);
	D3DXVec3TransformCoord(&direction, &forward, &rotation);
	
	skill1Pos = pos + direction*20.0f;
	skill1Sphere.center = skill1Pos;


	D3DXVec3Cross(&right, &direction, &up);
	D3DXMatrixRotationY(&rotation, rotationAngle);
	
	switch (currentState)
	{
		//Idle, Move만 특별한 State. changeState로 바꾸지 않는다.
	case CharacterState::CHARACTER_IDLE:
	case CharacterState::CHARACTER_MOVE:
	{
		if (hm->GetHeight(pos, pos.x, pos.z) != false)
		{
			float tick = (float)GameManager::GetTick();
			bool move = false;
			if ((GetAsyncKeyState('W') & 0x8000) != 0)
			{

				pos -= (-direction * moveSpeed * tick);
				if (currentState == CharacterState::CHARACTER_IDLE)
				{
					ChangeCharacterState(CharacterState::CHARACTER_MOVE);
				}
				move = true;
			}
			else if ((GetAsyncKeyState('S') & 0x8000) != 0)
			{
				pos += (-direction * moveSpeed * tick);
				if (currentState == CharacterState::CHARACTER_IDLE)
				{
					ChangeCharacterState(CharacterState::CHARACTER_MOVE);
				}

				move = true;
			}
			if ((GetAsyncKeyState('A') & 0x8000) != 0)
			{
				pos -= (-right * moveSpeed * tick);
				if (currentState == CharacterState::CHARACTER_IDLE)
				{
					ChangeCharacterState(CharacterState::CHARACTER_MOVE);
				}

				move = true;
			}
			else if ((GetAsyncKeyState('D') & 0x8000) != 0)
			{
				pos += (-right * moveSpeed * tick);
				if (currentState == CharacterState::CHARACTER_IDLE)
				{
					ChangeCharacterState(CharacterState::CHARACTER_MOVE);
				}

				move = true;
			}
			if ((!move) && currentState==CharacterState::CHARACTER_MOVE)
			{
				ChangeCharacterState(CharacterState::CHARACTER_IDLE);
			}
			
			//state transition
			if ((GetAsyncKeyState(VK_SPACE) & 0x8000) != 0)
			{
				ChangeCharacterState(CharacterState::CHARACTER_ATTACK);
			}
			else if (GetAsyncKeyState('1') & 0x8000 != 0)
			{
				ChangeCharacterState(CharacterState::CHARACTER_SKILL1);
			}
		}
	}
	break;
	case CharacterState::CHARACTER_ATTACK:
	{
		double tick = GameManager::GetTick();
		currentAnimationTime += tick;
		if (currentAnimationTime >= selectedAnimationLength)
		{
			ChangeCharacterState(CharacterState::CHARACTER_IDLE);
		}
		break;
	}
	case CharacterState::CHARACTER_SKILL1:
	{
		double tick = GameManager::GetTick();
		currentAnimationTime += tick;
		skill1Sphere.radius = sinf(currentAnimationTime*D3DX_PI)*maxSkill1Radius;
		animController->SetTrackSpeed(0, selectedAnimationLength / skillCastingTime);
		if (currentAnimationTime >= skillCastingTime)
		{
			
			ChangeCharacterState(CharacterState::CHARACTER_IDLE);
		}
	}
		
	default:
		break;
	}
		SetPosition(pos);
	//여기부턴 skinnedmesh와 같음

	if (animController)
	{
		animController->AdvanceTime(GameManager::GetTick(), nullptr);
	}

	if (rootFrame)
	{
		D3DXMATRIXA16 local;
		D3DXMatrixTranslation(&local, position.x, position.y, position.z);
		D3DXMATRIXA16 scale;
		D3DXMatrixScaling(&scale, scaleFactor.x, scaleFactor.y, scaleFactor.z);
		local = scale*rotation*local;
		Update(rootFrame, &local);
		Render(rootFrame);
	}
	Debuging( );
}
Ejemplo n.º 20
0
HRESULT InitControllers()
{
	_ASSERT( !g_pKeyboardControl );
	
	// load model file
	g_pKeyboardControl = new KeyboardControl( g_szHandFileName, "GLOVE" );

	if( !g_pKeyboardControl->GetNumObjects() )
	{
		char msg[256];
		sprintf( msg, "Could not load %s.", g_szHandFileName );
		int ok = MessageBox( g_hWnd, msg, "", MB_OKCANCEL );
//		if( IDOK != ok )
			return ERR_FILENOTFOUND;
	}

	// load model data
	strcpy( g_szHandFileName, g_pKeyboardControl->GetString( "MODEL", "Hand", "media\\newhand.x" ) );
	strcpy( g_szRoomFileName, g_pKeyboardControl->GetString( "MODEL", "Room", "media\\testroom.x" ) );
	g_fHandScale = g_pKeyboardControl->GetFloat( "MODEL", "HandScale", 1.0f );
	g_fRoomScale = g_pKeyboardControl->GetFloat( "MODEL", "RoomScale", 1.0f );


  // create a hand object
  g_pHandObject = new C3DFrameObject();
  HRESULT rval = g_pHandObject->Init(g_pEngine, g_szHandFileName );
  if (rval)
  {
    DisplayErrorCode(rval);
    exit(rval);
  }

	// scale it
	D3DXMATRIX mScale;
	D3DXMatrixScaling( &mScale, g_fHandScale, g_fHandScale, g_fHandScale );
	D3DXMATRIX mIdentity;
	D3DXMatrixIdentity( &mIdentity );
	g_pHandObject->SetMatrices( &mIdentity, &mScale );

  // add it to our world
  rval = g_pEngine->AddChild(g_pHandObject);
  if (rval)
  {
    DisplayErrorCode(rval);
    exit(rval);
  }

	// create text and controllers
	const float fFirstTextLine = UI_FIRST_LINE_Y;
	const float fTextIndent = UI_OFFSET_X;
	const float fTextLineHeight = UI_GROUP_OFFSET_Y;

	float fTextLine = fFirstTextLine;
	C3DFont *pFont = g_pEngine->GetFont();

	int iNumParts = g_pKeyboardControl->GetNumObjects();
	for( int i = 0; i < iNumParts; ++i )
	{
		KeyboardObject *pKBO = g_pKeyboardControl->GetObjectPtr(i);
		ASSERT( pKBO );

		const char *szBoneName = pKBO->GetName();
		ASSERT(szBoneName);

		int iNumValues = pKBO->GetNumValues();
		ASSERT( iNumValues );

		const char *szAnimFileName = pKBO->GetAnimation();

		const char *szControlType = pKBO->GetType();
		if( !strlen( szControlType ) )
		{
			// default to pitch controller if 1 control value
			if( 1 == iNumValues )
				szControlType = g_szPitchControllerType;
			// else default to 6-dof controller if 6 control values
			else if( 6 == iNumValues )
				szControlType = g_sz6DOFControllerType;
			// else default to animation frame controller if anim file name present
//			else if( strlen( szAnimFileName )
//				szControlType = g_szAnimationControllerType;
			else
				return E_FAIL;	// unrecognized controller type
		}

		Controller *pController = NULL;
		C3DText *pText = NULL;

		SIZE size;
		pFont->GetTextExtent("1",&size);

		//
		// create controller of type specified
		//
		// animation frame controller
		if( 0 == stricmp( g_szAnimationControllerType, szControlType ) )
		{
			ASSERT( 1 == iNumValues );
			float *fInput = pKBO->GetValuePtr(0);

			pController = g_pHandObject->AttachAnimController( szBoneName, fInput );
			if( !pController )
				return E_FAIL;

			// attach text display
			if( strlen( pKBO->GetDisplayText() ) )
			{
				pText = new C3DText(2);
				pText->SetOffset( fTextIndent, fTextLine );
				pText->SetLine( 0, pKBO->GetDisplayText() );
				pText->SetColor(UI_HAND_RED,UI_HAND_GREEN,UI_HAND_BLUE,UI_HAND_ALPHA);
				pController->SetText( pText );
				g_pEngine->AddText( pText );
				fTextLine += pText->GetTextBlockHeight(pFont) + fTextLineHeight;
			}
		}

		// 6-dof controller
		else if( 0 == stricmp( g_sz6DOFControllerType, szControlType ) )
		{
			ASSERT( 6 == iNumValues );
			float *fX = pKBO->GetValuePtr(0);
			float *fY = pKBO->GetValuePtr(1);
			float *fZ = pKBO->GetValuePtr(2);
			float *fRoll = pKBO->GetValuePtr(3);
			float *fPitch = pKBO->GetValuePtr(4);
			float *fYaw = pKBO->GetValuePtr(5);

			pController = g_pHandObject->Attach6DOFController( szBoneName, fX, fY, fZ, fRoll, fPitch, fYaw );
			if( !pController )
				return E_FAIL;

			// attach text display
			if( strlen( pKBO->GetDisplayText() ) )
			{
				pText = new C3DText(4);
				pText->SetOffset( fTextIndent, fTextLine );
				pText->SetLine( 0, pKBO->GetDisplayText() );
				pText->SetColor(UI_HAND_RED,UI_HAND_GREEN,UI_HAND_BLUE,UI_HAND_ALPHA);
				pController->SetText( pText );
				g_pEngine->AddText( pText );
				fTextLine += pText->GetTextBlockHeight(pFont) + fTextLineHeight;
			}
		}

		// pitch-only controller
		else if( 0 == stricmp( g_szPitchControllerType, szControlType ) )
		{
			ASSERT( 1 == iNumValues );
			float *fPitch = pKBO->GetValuePtr(0);

			pController = g_pHandObject->Attach6DOFController( szBoneName, NULL, NULL, NULL, NULL, fPitch, NULL );
			if( !pController )
				return E_FAIL;

			// attach text display
			if( strlen( pKBO->GetDisplayText() ) )
			{
				pText = new C3DText(2);
				pText->SetOffset( fTextIndent, fTextLine );
				pText->SetLine( 0, pKBO->GetDisplayText() );
				pText->SetColor(UI_HAND_RED,UI_HAND_GREEN,UI_HAND_BLUE,UI_HAND_ALPHA);
				pController->SetText( pText );
				g_pEngine->AddText( pText );
				fTextLine += pText->GetTextBlockHeight(pFont) + fTextLineHeight;
			}
		}
	}
	return S_OK;
}
Ejemplo n.º 21
0
void ColoredCubeApp::drawScene()
{
	D3DApp::drawScene();

	//Step through animation frame
	animationTimeElapsed += mTimer.getGameTime() - animationTimePrev;
	animationTimePrev = mTimer.getGameTime();
	if(animationTimeElapsed > 0.0666f)
	{
		animationTimeElapsed = 0.0f;
		frameOfAnimation++;
		if(frameOfAnimation > fireFrameCount-1)
		{
			frameOfAnimation = 0;
		}
	}

	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);
    md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	// Set per frame constants
	mfxEyePosVar->SetRawValue(&mCameraPos, 0, sizeof(D3DXVECTOR3));
	mfxLightVar->SetRawValue(&mLights[0], 0, sizeof(Light));
	mfxLightVar2->SetRawValue(&mLights[1], 0, sizeof(Light));

	mfxCubeMapVR->SetResource(mCubeMapRV);
   
	// set constants
	mWVP = mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP); //set gWVP in color.fx to mWVP

	mTree.setEyePos(mCameraPos);
	mTree.setLights(mLights, 2);
	mTree.draw(mView, mProj);
	mObjBox.setEyePos(mCameraPos);
	mObjBox.setLights(mLights, 2);
	mObjBox.draw(mView, mProj);

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        ID3D10EffectPass* pass = mTech->GetPassByIndex( p ); //zero is always used in D3D10
		D3DXMATRIX texMtx;
        
		mWVP = mBoxWorld*mView*mProj;
		mfxWVPVar->SetMatrix((float*)&mWVP);
		mfxWorldVar->SetMatrix((float*)&mBoxWorld);
		mfxDiffuseMapVar->SetResource(mCrateMapRV);
		//mfxDiffuseMapVar->SetResource(mFireAnimationMapRVs[frameOfAnimation]);
		mfxSpecularMapVar->SetResource(mSpecularMapRV);
		mfxNormalMapVR->SetResource(mDefaultNormalMapRV);
		mfxReflectEnabledVar->SetBool(false);
		D3DXMatrixIdentity(&texMtx);
		mfxTexMtxVar->SetMatrix((float*)&texMtx);
		pass->Apply(0);
		mBox.draw();

		mWVP = mPlaneWorld*mView*mProj;
		mfxWVPVar->SetMatrix((float*)&mWVP);
		mfxWorldVar->SetMatrix((float*)&mPlaneWorld);
		mfxDiffuseMapVar->SetResource(mGrassMapRV);
		mfxNormalMapVR->SetResource(mBrickNormalMapRV);
		mfxReflectEnabledVar->SetBool(true);
		D3DXMATRIX s;
		D3DXMatrixScaling(&s, 5.0f, 5.0f, 1.0f);
		texMtx = s;
		D3DXMatrixIdentity(&texMtx);
		mfxTexMtxVar->SetMatrix((float*)&texMtx);
		pass->Apply(0);
		mPlane.draw();
    }

	mSky.draw(mWVP);

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	md3dDevice->RSSetState(0);
	mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);

	mSwapChain->Present(0, 0);
}
Ejemplo n.º 22
0
bool Display(float timeDelta)
{
	if( Device )
	{
		//update audio
		AudioUpdate();

		//keyboard
		if( ::GetAsyncKeyState('W') & 0x8000f)
		{
			TheCamera.walk(40.0f * timeDelta);
			//D3DXMATRIX forwardMovement;
			//D3DXMatrixRotationY(&forwardMovement, avatarYaw);
			//D3DXVECTOR3 v(0,0,forwardSpeed);
			//D3DXVECTOR4 vec4;
			//D3DXVec3Transform(&vec4, &v, &forwardMovement);
			//avatarDirection.x = v.x = vec4.x;
			//avatarDirection.y = v.y = vec4.y;
			//avatarDirection.z = v.z = vec4.z;
			//AvatarPosition.z += v.z;
			//AvatarPosition.x += v.x;
		}
		if( ::GetAsyncKeyState('S') & 0x8000f)
		{
			TheCamera.walk(-40.0f * timeDelta);
			//D3DXMATRIX forwardMovement;
			//D3DXMatrixRotationY(&forwardMovement, avatarYaw);
			//D3DXVECTOR3 v(0,0,-forwardSpeed);
			//D3DXVECTOR4 vec4;
			//D3DXVec3Transform(&vec4, &v, &forwardMovement);
			//avatarDirection.x = v.x = vec4.x;
			//avatarDirection.y = v.y = vec4.y;
			//avatarDirection.z = v.z = vec4.z;
			//AvatarPosition.z += v.z;
			//AvatarPosition.x += v.x;
		}
		if( ::GetAsyncKeyState('A') & 0x8000f)
		{
			TheCamera.yaw(-4.0f * timeDelta);
			//avatarYaw -= rotationSpeed;
		}
		if( ::GetAsyncKeyState('D') & 0x8000f)
		{
			TheCamera.yaw(4.0f * timeDelta);
			//avatarYaw -= rotationSpeed;
		}
		if( ::GetAsyncKeyState('I') & 0x8000f)
		{
			TheCamera.pitch(-4.0f * timeDelta);
		}
		if( ::GetAsyncKeyState('K') & 0x8000f)
		{
			TheCamera.pitch(4.0f * timeDelta);
		}

		D3DXVECTOR3 f = TheCamera.GetPosition();
		if(f.x > 190)
			f.x = 190;
		if(f.x < -190)
			f.x = -190;
		
		if(f.z > 190)
			f.z = 190;
		if(f.z < -190)
			f.z = -190;

		//if(f.y > 390)
		//	f.y = 390;
		//if(f.y < 10)
		//	f.y = 10;
		float height = TheTerrain->getHeight(f.x, f.z);
		f.y = height + 5.0f;


		TheCamera.setPosition(&f);

		//camera stuff
		D3DXMATRIX V, o;
		TheCamera.getViewMatrix(&V);
		Device->SetTransform(D3DTS_VIEW, &V);

		//UpdateCameraThirdPerson();
		//
		// Draw the scene:
		//
		Device->Clear(0, 0, 
			D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL,
			0xff000000, 1.0f, 0L);

		Device->BeginScene();
				
		D3DXMATRIX I;
		D3DXMatrixIdentity(&I);
		if(TheTerrain)
			TheTerrain->draw(&I, false);

		//Device->SetTexture(0, Armor)
D3DXMATRIX i, tripler, grow;

		Collides();

		DisplayTime();
		DisplayRemaining();

		//
		//Barrels1
		//
		if(BoolTrash[0])
		{
		
		D3DXMatrixTranslation(&tripler, TrashPositions[0].x + 0,TrashPositions[0].y, TrashPositions[0].z-10);
		D3DXMatrixScaling(&grow, .05,.05,.05);
		D3DXMatrixMultiply(&tripler, &grow, &tripler);
		Device->SetTransform(D3DTS_WORLD, &tripler);
		Barrels.Draw(NULL);
		}

		//
		//Barrels2
		//
		if(BoolTrash[1])
		{
		D3DXMatrixTranslation(&tripler, TrashPositions[1].x +0,TrashPositions[1].y,TrashPositions[1].z-10);
		D3DXMatrixScaling(&grow, .05,.05,.05);
		D3DXMatrixMultiply(&tripler, &grow, &tripler);
		Device->SetTransform(D3DTS_WORLD, &tripler);
		Barrels.Draw(NULL);
		}
		//
		//Dalek1
		//
		if(BoolTrash[2])
		{
		D3DXMatrixTranslation(&tripler, TrashPositions[2].x +0,TrashPositions[2].y+8,TrashPositions[2].z-10);
		D3DXMatrixScaling(&grow, .05,.05,.05);
		D3DXMatrixMultiply(&tripler, &grow, &tripler);
		Device->SetTransform(D3DTS_WORLD, &tripler);
		Dalek.Draw(NULL);
		}
		//
		//Dalek2
		//
		if(BoolTrash[3])
		{
		D3DXMatrixTranslation(&tripler,TrashPositions[3].x +0,TrashPositions[3].y+8,TrashPositions[3].z-10);
		D3DXMatrixScaling(&grow, .05,.05,.05);
		D3DXMatrixMultiply(&tripler, &grow, &tripler);
		Device->SetTransform(D3DTS_WORLD, &tripler);
		Dalek.Draw(NULL);
		}
		//
		//Tank1
		//		
		if(BoolTrash[4])
		{
		D3DXMatrixTranslation(&tripler, TrashPositions[4].x +40,TrashPositions[4].y+14,TrashPositions[4].z+0);
		D3DXMatrixScaling(&grow, .1,.1,.1);
		D3DXMatrixMultiply(&tripler, &grow, &tripler);
		Device->SetTransform(D3DTS_WORLD, &tripler);
		tank.Draw(NULL);
		}
		//
		//Tank2
		//
		if(BoolTrash[5])
		{
		D3DXMatrixTranslation(&tripler, TrashPositions[5].x +40,TrashPositions[5].y+14,TrashPositions[5].z+0);
		D3DXMatrixScaling(&grow, .1,.1,.1);
		D3DXMatrixMultiply(&tripler, &grow, &tripler);
		Device->SetTransform(D3DTS_WORLD, &tripler);
		tank.Draw(NULL);
		}

		//
		//Table1
		//		
		if(BoolTrash[6])
		{
		D3DXMatrixTranslation(&tripler, TrashPositions[6].x +0,TrashPositions[6].y,TrashPositions[6].z-10);
		D3DXMatrixScaling(&grow, 10,10,10);
		D3DXMatrixMultiply(&tripler, &grow, &tripler);
		Device->SetTransform(D3DTS_WORLD, &tripler);
		Table.Draw(NULL);
		}
		//
		//Table2
		//
		if(BoolTrash[7])
		{
		D3DXMatrixTranslation(&tripler, TrashPositions[7].x +0,TrashPositions[7].y,TrashPositions[7].z-10);
		D3DXMatrixScaling(&grow,10,10,10);
		D3DXMatrixMultiply(&tripler, &grow, &tripler);
		Device->SetTransform(D3DTS_WORLD, &tripler);
		Table.Draw(NULL);
		}
		//
		//Ton1
		//
		if(BoolTrash[8])
		{
		D3DXMatrixTranslation(&tripler, TrashPositions[8].x +0,TrashPositions[8].y,TrashPositions[8].z-10);
		D3DXMatrixScaling(&grow,10,10,10);
		D3DXMatrixMultiply(&tripler, &grow, &tripler);
		Device->SetTransform(D3DTS_WORLD, &tripler);
		Ton.Draw(NULL);
		}
		//
		//Ton2
		//
		if(BoolTrash[9])
		{
		D3DXMatrixTranslation(&tripler, TrashPositions[9].x +0,TrashPositions[8].y,TrashPositions[9].z-10);
		D3DXMatrixScaling(&grow,10,10,10);
		D3DXMatrixMultiply(&tripler, &grow, &tripler);
		Device->SetTransform(D3DTS_WORLD, &tripler);
		Ton.Draw(NULL);
		}

		for(int i = 0; i < numbertrees; i++)
		{
			D3DXMatrixTranslation(&tripler, TreePositions[i].x +0,TreePositions[i].y,TreePositions[i].z-10);
			D3DXMatrixScaling(&grow,5,5,5);
			D3DXMatrixMultiply(&tripler, &grow, &tripler);
			Device->SetTransform(D3DTS_WORLD, &tripler);
			Tree.Draw(NULL);
		}

		if(messageDone)
		{
		if(allfound)
		{
			sprintf(buffers, "Seconds taken to find all objects: %i", seconds);
			::MessageBoxA(0, buffers, "Congratulations", 0);
			//::PostQuitMessage(0);
			messageDone = false;
		}
		}

		renderSkybox(Device, TheCamera);
		DrawMinimap();

		Device->EndScene();
		Device->Present(0, 0, 0, 0);
	}

	if(GetTickCount() - dwFinalTick > 1000)
	{
		seconds = seconds + 1;
		dwInitialTick = dwFinalTick;
		dwFinalTick = GetTickCount();

		countDown = countDown+ 1;
	}
	return true;
}
Ejemplo n.º 23
0
void Direct3DRender(HWND hwnd)
{
	RECT formatRect;
	GetClientRect(hwnd, &formatRect);

	gPD3DDevice->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0, 30), 1.0f, 0.0f);
	gPD3DDevice->BeginScene();

	MatrixSet();

	WCHAR str[50];
	int strCount = swprintf_s(str, _T("Mat, Mesh & Light!"));
	gPFont->DrawTextW(nullptr, str, strCount, &formatRect, DT_TOP| DT_RIGHT, D3DCOLOR_XRGB(25, 134, 111));

	D3DXMATRIX Ry;
	D3DXMatrixRotationY(&Ry, timeGetTime() / 1000.0f);
	D3DXMATRIX teaPotWorldTrans;
	D3DXMatrixTranslation(&teaPotWorldTrans, 2.5f, 2.5f, 2.5f);
	D3DXMATRIX Sa;
	D3DXMatrixScaling(&Sa, 2.0f, 2.0f, 2.0f);
	teaPotWorldTrans = teaPotWorldTrans * Ry * Sa;
	gPD3DDevice->SetTransform(D3DTS_WORLD, &teaPotWorldTrans);

	D3DMATERIAL9 material;
	ZeroMemory(&material, sizeof(material));
	material.Ambient = D3DXCOLOR(0.5f, 0.5f, 0.7f, 1.0f);
	material.Diffuse = D3DXCOLOR(0.4f, 0.6f, 0.6f, 1.0f);
	material.Specular = D3DXCOLOR(0.3f, 0.3f, 0.3f, 0.3f);
	material.Emissive = D3DXCOLOR(0.3f, 0.0f, 0.1f, 1.0f);
	gPD3DDevice->SetMaterial(&material);

	gPTeapot->DrawSubset(0);


	D3DXMATRIX boxWorldTrans;
	D3DXMatrixTranslation(&boxWorldTrans, -5.0f, 5.0f, 5.0f);
	boxWorldTrans *= Ry;
	gPD3DDevice->SetTransform(D3DTS_WORLD, &boxWorldTrans);

	ZeroMemory(&material, sizeof(material));
	material.Ambient = D3DXCOLOR(0.3f, 0.1f, 0.5f, 1.0f);
	material.Diffuse = D3DXCOLOR(0.4f, 0.6f, 0.6f, 1.0f);
	material.Specular = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.3f);
	material.Emissive = D3DXCOLOR(0.3f, 0.0f, 0.1f, 1.0f);
	gPD3DDevice->SetMaterial(&material);
	gPBox->DrawSubset(0);

	D3DXMATRIX torusWorldTrans;
	D3DXMatrixTranslation(&torusWorldTrans, 5.0f, -5.0f, 5.0f);
	torusWorldTrans *= Ry;
	gPD3DDevice->SetTransform(D3DTS_WORLD, &torusWorldTrans);

	ZeroMemory(&material, sizeof(material));
	material.Ambient = D3DXCOLOR(0.5f, 0.2f, 0.3f, 1.0f);
	material.Diffuse = D3DXCOLOR(0.6f, 0.2f, 0.4f, 1.0f);
	material.Specular = D3DXCOLOR(0.3f, 0.3f, 0.3f, 0.3f);
	material.Emissive = D3DXCOLOR(0.3f, 0.0f, 0.1f, 1.0f);
	gPD3DDevice->SetMaterial(&material);
	gPTorus->DrawSubset(0);

	D3DXMATRIX sphereWorldTrans;
	D3DXMatrixTranslation(&sphereWorldTrans, -5.0f, -5.0f, 5.0f);
	sphereWorldTrans *= Ry;
	gPD3DDevice->SetTransform(D3DTS_WORLD, &sphereWorldTrans);

	ZeroMemory(&material, sizeof(material));
	material.Ambient = D3DXCOLOR(0.9f, 0.1f, 0.9f, 1.0f);
	material.Diffuse = D3DXCOLOR(0.3f, 0.6f, 0.8f, 1.0f);
	material.Specular = D3DXCOLOR(0.3f, 0.3f, 0.3f, 0.3f);
	material.Emissive = D3DXCOLOR(0.9f, 0.4f, 0.7f, 1.0f);
	gPD3DDevice->SetMaterial(&material);
	gPSphere->DrawSubset(0);

	LightSet(gPD3DDevice, 1);

	gPD3DDevice->EndScene();
	gPD3DDevice->Present(nullptr, nullptr, nullptr, nullptr);
}
Ejemplo n.º 24
0
/*
 * scale
 */
void Transformable::Scale(float x, float y, float z) {
	D3DXMatrixScaling(&scale, x, y, z);
}
Ejemplo n.º 25
0
void GameSkybox::SetScal(float size)
{
	m_dwScal = size;
	D3DXMatrixScaling(&m_matscal,size,size,size);
}
Ejemplo n.º 26
0
Matrix Matrix::createScale(const Vector3& v)
{
	return *D3DXMatrixScaling(&tmp, v.x, v.y, v.z);
}
Ejemplo n.º 27
0
bool graphics::Render()
{
    bool result;

    D3DXMATRIX worldMatrix, viewMatrix, projectionMatrix,tempA,tempB,tempC,temphold;
    D3DXMATRIX lightViewMatrix, lightProjectionMatrix;
    D3DXMATRIX lightViewMatrix2, lightProjectionMatrix2;
    D3DXMATRIX lightViewMatrix3, lightProjectionMatrix3;





    result = RenderSceneToTexTure();
    if(!result)
    {
        return false;

    }

    result = RenderSceneToTexTure2();
    if(!result)
    {
        return false;
    }

    result = RenderSceneToTexTure3();
    if(!result)
    {
        return false;
    }
    // Clear the buffers to begin the scene.
    _D3D->SetupScene(0.0f, 0.0f, 0.0f, 1.0f);


    _camera->Render();

    _light->GenerateViewMatrix();
    _light2->GenerateViewMatrix();
    _light3->GenerateViewMatrix();
    // Get the world, view, and projection matrices from the camera and d3d objects.
    _camera->GetViewMatrix(viewMatrix);
    _D3D->GetWorldMatrix(worldMatrix);
    _D3D->GetProjectionMatrix(projectionMatrix);

    _light->GetViewMatrix(lightViewMatrix);
    _light->GetProjectionMatrix(lightProjectionMatrix);


    _light2->GetViewMatrix(lightViewMatrix2);
    _light2->GetProjectionMatrix(lightProjectionMatrix2);

    _light3->GetViewMatrix(lightViewMatrix3);
    _light3->GetProjectionMatrix(lightProjectionMatrix3);

    //D3DXMatrixRotationX(&worldMatrix, 90.0f);

    D3DXMatrixRotationY(&worldMatrix,_rotation1);

    _model2->RenderToGraphics(_D3D->GetDevice());


    _shader->Render(_D3D->GetDevice(), _model2->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, lightViewMatrix,
                    lightProjectionMatrix,_model2->GetTexture(),_renderTexture->GetShaderResourceView(),
                    _light->GetPosition(), _light->GetDiffuseColor(),_light->GetAmbient(),_camera->GetPosition(),_light->GetSpecularColor(),_light->GetSpecularPower(),_light2->GetPosition(),_light2->GetDiffuseColor()
                    ,_light2->GetSpecularColor(),_light2->GetSpecularPower(),lightViewMatrix2, lightProjectionMatrix2,_renderTexture2->GetShaderResourceView(),
                    _light3->GetPosition(),_light3->GetDiffuseColor(),_light3->GetSpecularColor(),_light3->GetSpecularPower(),lightViewMatrix3, lightProjectionMatrix3,_renderTexture3->GetShaderResourceView());
    // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
    _model->RenderToGraphics(_D3D->GetDevice());

    _D3D->GetWorldMatrix(worldMatrix);
    D3DXMatrixTranslation(&tempA,0.0f,1.0f,1.0f);
    D3DXMatrixRotationX(&tempB, 90.0f);

    D3DXMatrixMultiply(&worldMatrix,&tempA,&tempB);
    D3DXMatrixScaling(&tempC,2.0f,2.0f,2.0f);

    D3DXMatrixMultiply(&worldMatrix,&worldMatrix,&tempC);



    // Render the model using the color shader.
    _shader->Render(_D3D->GetDevice(), _model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,lightViewMatrix,
                    lightProjectionMatrix,_model->GetTexture(),_renderTexture->GetShaderResourceView(),_light->GetPosition(), _light->GetDiffuseColor(),_light->GetAmbient(),_camera->GetPosition(),_light->GetSpecularColor(),_light->GetSpecularPower(),_light2->GetPosition(),_light2->GetDiffuseColor()
                    ,_light2->GetSpecularColor(),_light2->GetSpecularPower(),lightViewMatrix2, lightProjectionMatrix2,_renderTexture2->GetShaderResourceView(),
                    _light3->GetPosition(),_light3->GetDiffuseColor(),_light3->GetSpecularColor(),_light3->GetSpecularPower(),lightViewMatrix3, lightProjectionMatrix3,_renderTexture3->GetShaderResourceView());




    _D3D->DrawScene();


    return true;
}
Ejemplo n.º 28
0
void DrawMap(void)
{

  char buff[512];
	
  /*------------------------------------------------------------------------------
  //Begin Input Ctrl & View Matrix Setup
  ------------------------------------------------------------------------------*/
  static float angle = 0.0f;
  static float view = -240.0f;
  //view = -view;
  D3DXMATRIX matWorld;
  D3DXMATRIX matWorld2;
  D3DXMatrixTranslation(&matWorld2,0.0f,0.0f,angle/1500.0f);
  //D3DXMatrixRotationX(&matWorld, DEGtoRAD(angle/1.0069));
  //DXMatrixRotationY(&matWorld, DEGtoRAD(angle));
  D3DXMatrixRotationYawPitchRoll(&matWorld,DEGtoRAD(angle/20.0f),DEGtoRAD(angle/15.0f),DEGtoRAD(angle/10.0f));
  matWorld*=matWorld2;
  angle += 1.0f;
  //g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);

  D3DXMATRIX matView;
  static float mawari = 0.0f;
  float delta;
  delta = 0.02f;
  if( GetKeyState(VK_CONTROL)&0x8000 ){ delta = 0.1f; };
  if( GetKeyState(VK_RIGHT) & 0x8000 ) mawari-=delta;
  if( GetKeyState(VK_LEFT)  & 0x8000 ) mawari+=delta;
  static D3DXVECTOR3 pos(0.0f, 0.0f, 0.0f);
  delta = 2.0f;
  if( GetKeyState(VK_CONTROL)&0x8000 ){ delta = 5.0f; };
  if( GetKeyState(VK_UP)    & 0x8000 ){ pos.x+=cos(mawari)*delta; pos.z+=sin(mawari)*delta; }
  if( GetKeyState(VK_DOWN)  & 0x8000 ){ pos.x+=cos(mawari+3.1415926f)*delta; pos.z+=sin(mawari+3.1415926f)*delta; }
  if( GetKeyState(VK_PRIOR) & 0x8000 ){ pos.y+=delta; }
  if( GetKeyState(VK_NEXT)  & 0x8000 ){ pos.y-=delta; }
  if( GetKeyState(VK_HOME)  & 0x8000 ){ mawari=pos.x=pos.y=pos.z=0.0f; }
  D3DXVECTOR3 pnt(pos.x+cos(mawari), pos.y+0.0f, pos.z+sin(mawari));
  D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
  D3DXMatrixLookAtRH(&matView, &pos, &pnt, &up);
  g_pD3DDevice->SetTransform(D3DTS_VIEW, &matView); 

  D3DXMATRIX matProj;
  D3DXMatrixPerspectiveFovRH(&matProj, DEGtoRAD(45.0f), 4.0f / 3.0f, 1.0f, 500.0f);
  g_pD3DDevice->SetTransform(D3DTS_PROJECTION, &matProj);


   if( GetAsyncKeyState(VK_RETURN)  & 0x1 ){ AutoMakeMMB=TRUE;}


  /*------------------------------------------------------------------------------
  //End Input Ctrl & View Matrix Setup
  ------------------------------------------------------------------------------*/

  /*------------------------------------------------------------------------------
  //Begin RenderState
  ------------------------------------------------------------------------------*/
  //g_pD3DDevice->SetRenderState( D3DRS_CULLMODE,   D3DCULL_CW/*/D3DCULL_NONE*/  );
  g_pD3DDevice->SetRenderState( D3DRS_CULLMODE,   D3DCULL_CCW/*/D3DCULL_NONE*/  );
  g_pD3DDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
  //g_pD3DDevice->SetLight(0,&light);
  //g_pD3DDevice->LightEnable(0,TRUE);
  g_pD3DDevice->SetRenderState(D3DRS_LIGHTING,FALSE);
  //g_pD3DDevice->SetRenderState(D3DRS_AMBIENT, 0xF0F0F0F0);
  g_pD3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD );

  g_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
  g_pD3DDevice->SetRenderState( D3DRS_STENCILENABLE, TRUE );
  g_pD3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE , TRUE );
  g_pD3DDevice->SetRenderState( D3DRS_ALPHAREF , 0x80 );
  g_pD3DDevice->SetRenderState( D3DRS_ALPHAFUNC  , D3DCMP_GREATER );
  //g_pD3DDevice->SetRenderState(D3DRS_EDGEANTIALIAS,TRUE);
  /*------------------------------------------------------------------------------
  //End RenderState
  ------------------------------------------------------------------------------*/

  //地图是在TheDesertWorld.cpp里画的
  //g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,128), 1.0f, 0L );



  if( flgFirst ) logprintf("MZB:%d",noj);
  pory = 0;
  for( int i=0; i< noj; i++ )
  {
    //if(i>=50) break;
    D3DXMATRIX matWorld;
    D3DXMATRIX matWorld2;
    D3DXMATRIX matWorld3;
    D3DXMATRIX matWorld4;
    D3DXMATRIX matWorldR4;
    D3DXMATRIX matWorldR5;
    D3DXMATRIX matWorldR6;
    ZeroMemory(&matWorld,sizeof(D3DXMATRIX));
    D3DXMatrixScaling(&matWorld3,oj[i].fScaleX,oj[i].fScaleY,oj[i].fScaleZ); 
    D3DXMatrixTranslation(&matWorld,oj[i].fTransX,oj[i].fTransY,oj[i].fTransZ);
    D3DXMatrixRotationX(&matWorldR4,oj[i].fRotX);
    D3DXMatrixRotationY(&matWorldR5,oj[i].fRotY);
    D3DXMatrixRotationZ(&matWorldR6,oj[i].fRotZ);
    matWorld2 = matWorldR4 * matWorldR5 * matWorldR6;
    matWorld=((matWorld3*matWorld2)/**matWorld4*/)*matWorld;
    g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);
    if( oj[i].fScaleX*oj[i].fScaleY*oj[i].fScaleZ < 0.0f )
	{ 
      g_pD3DDevice->SetRenderState( D3DRS_CULLMODE,   D3DCULL_CW );
    }
	else
	{
      g_pD3DDevice->SetRenderState( D3DRS_CULLMODE,   D3DCULL_CCW );
    }
    if(0)
	{
       float pp[]={-20,0,0,20,0,0, 0,-20,0,0,20,0, 0,0,-20,0,0,20};
       //float pp[]={-10,0,0,10,0,0, 0,-10,0,0,10,0, 0,0,-10,0,0,10};
       g_pD3DDevice->SetFVF(D3DFVF_XYZ);
       g_pD3DDevice->DrawPrimitiveUP(D3DPT_LINELIST,3,pp,12);
    }



	//Draw MzbLists Hint
	{
    RECT rc={5,91,600,128};

	  //自动输出
	  i = haha; //这个会打乱文件名和文件内容的正确配对吗?
	  if (AutoMakeMMB == TRUE) {haha+=1;};
      if (haha == (noj -1)) {haha = 0;AutoMakeMMB == false;};

    sprintf(buff,"-----MZBList:%d/%d",i,noj);
    pDxFont->DrawTextA(NULL,buff,lstrlen(buff),&rc, DT_LEFT,  D3DCOLOR_XRGB(0,0,255)); 
	}


    for( int j=0; j< NumMMB; j++ )
	{
      if( memcmp(MMBlist[j]+16,oj[i].id,16) ) continue;

	//Draw Mmb Hint
	{
    RECT rc={5,134,600,160};
    sprintf(buff,"------- Draw MMB:%s",sstr(oj[i].id,16));
    pDxFont->DrawTextA(NULL,buff,lstrlen(buff),&rc, DT_LEFT,  D3DCOLOR_XRGB(0,0,255)); 
	}

    /*------------------------------------------------------------------------------
    //Begin MapObj Files Output
    ------------------------------------------------------------------------------*/
    char opname[16];  //要输出的文件名
    CopyMemory(opname,MMBlist[j]+16,16);
    ChangeSpaceToNull(opname);
	lstrcat(opname,".MapObj");


    if (DoesFileExist(opname)) { logprintf("发现有文件重复将自动复盖,这些文件是%s",opname);}
    HANDLE hFile = CreateFile(opname,GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL );
    //ReadFile(hFile,pdat,dwSize,&dmy,NULL);	  

    if( hFile!=INVALID_HANDLE_VALUE && hFile!=NULL )
	{
    DWORD dmy;
    //SetFilePointer(hFile,0,NULL,FILE_END);

	LPSTR ReadLocate = MMBlist[j+1]-16;

	int size = (int)(((*(DWORD*)&ReadLocate[4])>>3)&0x007ffff0);

    WriteFile(hFile,&ReadLocate[0],size,&dmy,NULL);
    CloseHandle(hFile);
	}
   /*------------------------------------------------------------------------------
   //End MapObj Files Output
   ------------------------------------------------------------------------------*/

    DrawMMB(MMBlist[j]);

    //信息输出1
	{
    RECT rc={5,5,600,64};
    sprintf(buff,"正在绘制Index数=%d\nLookAt:X=%02.2f Y=%02.2f Z=%02.2f",pory,pos.x,pos.y,pos.z);
    pDxFont->DrawTextA(NULL,buff,lstrlen(buff),&rc, DT_LEFT,  D3DCOLOR_XRGB(196,196,0)); 
	}
    //信息输出2
	{
    RECT rc={5,48,600,96};
    sprintf(buff,"%sMZB=%d MMB=%d\n当前第%d个MMB",oj?"总共":"第",noj,NumMMB,j);
    pDxFont->DrawTextA(NULL,buff,lstrlen(buff),&rc, DT_LEFT,  D3DCOLOR_XRGB(196,196,0)); 
	}

	break;
	}//End For MumMMB

  break;
  }//End For Noj
Ejemplo n.º 29
0
DWORD KG3DRotationCoordinateOld::GetSelCoord(const D3DXVECTOR3& vSrc, const D3DXVECTOR3& vDir)
{
    D3DXVECTOR3 vCoordX = D3DXVECTOR3(m_matCoord._11, m_matCoord._12, m_matCoord._13);
    D3DXVECTOR3 vCoordY = D3DXVECTOR3(m_matCoord._21, m_matCoord._22, m_matCoord._23);
    D3DXVECTOR3 vCoordZ = D3DXVECTOR3(m_matCoord._31, m_matCoord._32, m_matCoord._33);
    D3DXVECTOR3 vCenter = D3DXVECTOR3(m_matCoord._41, m_matCoord._42, m_matCoord._43);
    D3DXVECTOR3 vNormal = D3DXVECTOR3(0.f, 1.f, 0.f);

    D3DXVECTOR3 src;
    D3DXVECTOR3 dir;

    BOOL  bHit   = FALSE;
    DWORD dwFace = 0;

    FLOAT fScal = m_fZoom * GetScalingFactor();

    D3DXMATRIX  matCoord;
    D3DXMATRIX  matMove;
    D3DXMATRIX  matRota;
    D3DXMATRIX  matScal;
    D3DXMATRIX  matCoordInv;

    D3DXVECTOR3 vRotaAxis;

    D3DXMatrixTranslation(&matMove, vCenter.x, vCenter.y, vCenter.z);
    D3DXMatrixScaling(&matScal, fScal, fScal, fScal);

    // y

    D3DXVec3Cross(&vRotaAxis, &vNormal, &vCoordY);
    D3DXMatrixRotationAxis(&matRota, &vRotaAxis, acosf(D3DXVec3Dot(&vNormal, &vCoordY)));
    matCoord = matScal * matRota * matMove;
    D3DXMatrixInverse(&matCoordInv, NULL, &matCoord);
    D3DXVec3TransformCoord(&src, &vSrc, &matCoordInv);
    D3DXVec3TransformNormal(&dir, &vDir, &matCoordInv);

    for (DWORD i = 0; i < m_dwNumMatrials; i++)
    {
        D3DXIntersectSubset(
            m_pCoordMesh,
            i,
            &src,
            &dir,
            &bHit,
            &dwFace,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL
            );
        if (bHit)
            return 0;
    }


    // x

    D3DXVec3Cross(&vRotaAxis, &vNormal, &vCoordX);
    D3DXMatrixRotationAxis(&matRota, &vRotaAxis, acosf(D3DXVec3Dot(&vNormal, &vCoordX)));
    matCoord = matScal * matRota * matMove;
    D3DXMatrixInverse(&matCoordInv, NULL, &matCoord);
    D3DXVec3TransformCoord(&src, &vSrc, &matCoordInv);
    D3DXVec3TransformNormal(&dir, &vDir, &matCoordInv);

    for (DWORD i = 0; i < m_dwNumMatrials; i++)
    {
        D3DXIntersectSubset(
            m_pCoordMesh,
            i,
            &src,
            &dir,
            &bHit,
            &dwFace,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL
            );
        if (bHit)
            return 1;
    }


    // z

    D3DXVec3Cross(&vRotaAxis, &vNormal, &vCoordZ);
    D3DXMatrixRotationAxis(&matRota, &vRotaAxis, acosf(D3DXVec3Dot(&vNormal, &vCoordZ)));
    matCoord = matScal * matRota * matMove;
    D3DXMatrixInverse(&matCoordInv, NULL, &matCoord);
    D3DXVec3TransformCoord(&src, &vSrc, &matCoordInv);
    D3DXVec3TransformNormal(&dir, &vDir, &matCoordInv);

    for (DWORD i = 0; i < m_dwNumMatrials; i++)
    {
        D3DXIntersectSubset(
            m_pCoordMesh,
            i,
            &src,
            &dir,
            &bHit,
            &dwFace,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL
            );
        if (bHit)
            return 2;
    }

   return 0xffffffff;
}
Ejemplo n.º 30
0
//-------------------------------------
// Draw()
//-------------------------------------
void Shadow::Draw()
{
//	DWORD zfunc;
	LPDIRECT3DDEVICE9 device = DirectX9Holder::device_;

	D3DXMATRIX world, scaling;
	D3DXMatrixIdentity(&world);
	D3DXMatrixScaling(&scaling, parameter_.scaling_.x_, 1.0f, parameter_.scaling_.z_);
	world *= scaling;
	world._41 += parameter_.position_.x_;
	world._42 += parameter_.position_.y_;
	world._43 += parameter_.position_.z_;

	D3DXMATRIX view, projection, wvp;
	device->GetTransform(D3DTS_VIEW, &view);
	device->GetTransform(D3DTS_PROJECTION, &projection);
	wvp = world * view * projection;

	shader_->vertex_table()->SetMatrix(
		device, "matrix_wvp", &wvp);
	device->SetTexture(
		shader_->pixel_table()->GetSamplerIndex("texture_0"), texture_);

	device->SetVertexShader(shader_->vertex_shader());
	device->SetPixelShader(shader_->pixel_shader());

	device->SetVertexDeclaration(
		DirectX9Holder::vertex_declaration_shadow_);

	device->SetStreamSource(
		0,
		vertex_buffer_,
		0,
		sizeof(Vertex3DShadow));

	// レンダーステート保存
	DWORD blendop, srcblend, destblend;//, zfunc;
	device->GetRenderState(D3DRS_BLENDOP, &blendop);
	device->GetRenderState(D3DRS_SRCBLEND, &srcblend);
	device->GetRenderState(D3DRS_DESTBLEND, &destblend);
//	device->GetRenderState(D3DRS_ZFUNC, &zfunc);

	//影用にレンダーステートを減算合成に変更する
	device->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_REVSUBTRACT);
	device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

	//Zバッファの設定を完全描画にする。
//	device->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);

	// 描画
	device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

	// 変更したレンダースレート修正
//	device->SetRenderState(D3DRS_ZFUNC, zfunc);
	device->SetRenderState(D3DRS_BLENDOP, blendop);
	device->SetRenderState(D3DRS_SRCBLEND, srcblend);
	device->SetRenderState(D3DRS_DESTBLEND, destblend);

	device->SetVertexShader(NULL);
	device->SetPixelShader(NULL);
}