예제 #1
0
bool KG3DScenePvsEditor::GetPlaceObjectPos(D3DXVECTOR3& vPos, KG3DSceneOutputWnd* pWnd)
{
    ASSERT(pWnd);

    if (!pWnd || !m_pPvs)
        return false;

    RECT rectWnd;
    POINT ptCursor;

    GetWindowRect(pWnd->m_hWnd, &rectWnd);
    GetCursorPos(&ptCursor);

    if (!PtInRect(&rectWnd, ptCursor))
        return false;

    D3DXVECTOR3 v1;
    D3DXVECTOR3 v2;
    D3DXVECTOR3 dir;
    const D3DXPLANE plane = D3DXPLANE(0.0f, 1.0f, 0.0f, 0.f);

    pWnd->GetPickRay(&v1, &dir, NULL); 
    v2 = v1 + (dir * 100000.0f);
    D3DXPlaneIntersectLine(&vPos, &plane, &v1, &v2);

    D3DXVECTOR3 vSrc[1] = { v1 };
    D3DXVECTOR3 vDst[1] = { v2 };
    float fDis = 0.f;

    if (m_pPvs->GetCameraNearRayIntersect(vDst, vSrc, 1, &fDis))
        vPos = vDst[0] - dir * fDis;

    return true;
}
예제 #2
0
bool KG3DScenePvsEditor::GetPlacePortalPos(D3DXVECTOR3& vPos, KG3DSceneOutputWnd* pWnd, KG3DPvsPortal* ptl)
{
    ASSERT(pWnd);

    if (!pWnd || !m_pPvs || !ptl)
        return false;

    RECT rectWnd;
    POINT ptCursor;

    GetWindowRect(pWnd->m_hWnd, &rectWnd);
    GetCursorPos(&ptCursor);

    if (!PtInRect(&rectWnd, ptCursor))
        return false;

    D3DXVECTOR3 v1;
    D3DXVECTOR3 v2;
    D3DXVECTOR3 dir;
    const D3DXPLANE plane = D3DXPLANE(0.0f, 1.0f, 0.0f, 0.f);

    pWnd->GetPickRay(&v1, &dir, NULL); 
    v2 = v1 + (dir * 100000.0f);
    D3DXPlaneIntersectLine(&vPos, &plane, &v1, &v2);

    D3DXVECTOR3 vScal;
    ptl->GetScaling(&vScal);
    vScal *= 0.5f;

    D3DXVECTOR3 vSrc[5] = 
    {
        v1,
        v1 - pWnd->GetCamera().GetCameraRight() * vScal.x + pWnd->GetCamera().GetCameraUp() * vScal.y,
        v1 + pWnd->GetCamera().GetCameraRight() * vScal.x + pWnd->GetCamera().GetCameraUp() * vScal.y,
        v1 + pWnd->GetCamera().GetCameraRight() * vScal.x - pWnd->GetCamera().GetCameraUp() * vScal.y,
        v1 - pWnd->GetCamera().GetCameraRight() * vScal.x - pWnd->GetCamera().GetCameraUp() * vScal.y
    };

    D3DXVECTOR3 vDst[5] = 
    {
        v2,
        v2 - pWnd->GetCamera().GetCameraRight() * vScal.x + pWnd->GetCamera().GetCameraUp() * vScal.y,
        v2 + pWnd->GetCamera().GetCameraRight() * vScal.x + pWnd->GetCamera().GetCameraUp() * vScal.y,
        v2 + pWnd->GetCamera().GetCameraRight() * vScal.x - pWnd->GetCamera().GetCameraUp() * vScal.y,
        v2 - pWnd->GetCamera().GetCameraRight() * vScal.x - pWnd->GetCamera().GetCameraUp() * vScal.y
    };

    float fDis = 0.f;

    if (m_pPvs->GetCameraNearRayIntersect(vDst, vSrc, 5, &fDis))
        vPos = v2 - dir * fDis;

    return true;
}
예제 #3
0
파일: OBB.cpp 프로젝트: 7zhang/studies
Ray OBB::GetContactPoint(Ray &ray) {
    D3DXMATRIX p, r, world, invWorld;
    D3DXMatrixTranslation(&p, m_pos.x, m_pos.y, m_pos.z);
    D3DXMatrixRotationQuaternion(&r, &m_rot);

    D3DXMatrixMultiply(&world, &r, &p);
    D3DXMatrixInverse(&invWorld, NULL, &world);

    D3DXVECTOR3 org, dir;
    D3DXVec3TransformCoord(&org, &ray.m_org, &invWorld);
    D3DXVec3TransformNormal(&dir, &ray.m_dir, &invWorld);

    D3DXPLANE planes[] = {D3DXPLANE(0.0f, 0.0f, -1.0f, -m_size.z),
                          D3DXPLANE(0.0f, 0.0f, 1.0f,  -m_size.z),
                          D3DXPLANE(0.0f, -1.0f, 0.0f, -m_size.y),
                          D3DXPLANE(0.0f, 1.0f, 0.0f,  -m_size.y),
                          D3DXPLANE(-1.0f, 0.0f, 0.0f, -m_size.x),
                          D3DXPLANE(1.0f, 0.0f, 0.0f,  -m_size.x)
                         };

    D3DXVECTOR3 result, normal;
    int numPlanes = 0;
    int numIntersections = 0;

    for (int i=0; i<6; i++) {
        float d = org.x * planes[i].a +
                  org.y * planes[i].b +
                  org.z * planes[i].c;

        if (d > -planes[i].d) {
            D3DXVECTOR3 r;
            if (D3DXPlaneIntersectLine(&r, &planes[i], &org, &(org + dir * 1000.0f)) != NULL) {
                numPlanes++;

                if (abs(r.x) <= m_size.x &&
                        abs(r.y) <= m_size.y &&
                        abs(r.z) <= m_size.z) {
                    D3DXVec3TransformCoord(&r, &r, &world);
                    result = r;
                    normal = D3DXVECTOR3(planes[i].a, planes[i].b, planes[i].c);
                    numIntersections++;
                }
            }
        }
    }

    if (numIntersections == 0) {
        //Warning! OBB No Intersections!
        return Ray(ray.m_org, -ray.m_dir);
    }

    D3DXVec3Normalize(&normal, &normal);
    D3DXVec3TransformNormal(&normal, &normal, &world);

    return Ray(result, normal);
}
예제 #4
0
void GameState::MouseButtonJustPressed(int button)
{
	// User hit button 1 and mouse is at the bottom of the screen we are allowed to cast a summon demon spell
	if (button==1 && currentState==GAME_IN_PROGRESS && /*inputSystem->MouseY() > manager->GetScreenHeight()-100 &&*/ players[user->GetTeam()-1].CanCastSpell(SUMMON_DEMON_SPELL_INDEX))
	{
		// Get an origin and ray as if they clicked on the bottom of the screen
		D3DXVECTOR3 rayDir, rayOrg, pointOnGround;
		POINT ptCursor;
		ptCursor.x=inputSystem->MouseX(); ptCursor.y=manager->GetScreenHeight(); 
		GetClickPos (rayDir, rayOrg, ptCursor);

		// Normalize rayDir
		D3DXVec3Normalize(&rayDir, &rayDir);

		// For now the terrain is a plane, so find where on the plane you clicked
		if (RayPlaneIntersection(&D3DXPLANE(0,1,0,0), &pointOnGround, &rayOrg, &rayDir))
		{
			/*
			// If they clicked too far out into the battlefield, move the point to the maximum allowable
			// If they clicked inside the castle move the point to the base of the castle
			if (user->GetTeam()==1)
			{
				if (pointOnGround.x < TEAM_1_CASTLE_POSITION - MAX_SUMMON_RANGE)
					pointOnGround.x = TEAM_1_CASTLE_POSITION - MAX_SUMMON_RANGE;
				else if (pointOnGround.x > TEAM_1_CASTLE_POSITION)
					pointOnGround.x = TEAM_1_CASTLE_POSITION;
			}
			else if (user->GetTeam()==2)
			{
				if (pointOnGround.x > TEAM_2_CASTLE_POSITION + MAX_SUMMON_RANGE)
					pointOnGround.x = TEAM_2_CASTLE_POSITION + MAX_SUMMON_RANGE;
				else if (pointOnGround.x < TEAM_2_CASTLE_POSITION)
					pointOnGround.x = TEAM_2_CASTLE_POSITION;
			}
			*/

			CreateDemon(pointOnGround, user->GetTeam(), false);
		}
	}
	
	if (button==2 && CanLevelUp())
	{
		HandleLevelUp();
	}
}
예제 #5
0
ReflRender::ReflRender()
{
	SetReflPlane(D3DXPLANE(0.0f, 0.0f, 1.0f, 0.0f));
}