Jump to content

  • Log In with Google      Sign In   
  • Create Account


anders211

Member Since 14 Feb 2012
Offline Last Active Jun 07 2014 02:37 AM
-----

Topics I've Started

adding angle to existed quaternion

04 May 2014 - 01:45 PM

Hi

I have a quaternion and I would like to add angle to it.

I have some code for calculating it, however I don't know if it is OK and I don't remember from which sources I took it.

D3DXQUATERNION mQuatOrientation;  //it has some value
D3DXVECTOR3 fi; //in radians


// Apply angle to orientation
        mQuatOrientation.w -= 0.5f * (mQuatOrientation.x * fi.x + mQuatOrientation.y * fi.y + mQuatOrientation.z * fi.z);
        mQuatOrientation.x += 0.5f * (mQuatOrientation.w * fi.x - mQuatOrientation.z * fi.y + mQuatOrientation.y * fi.z);
        mQuatOrientation.y += 0.5f * (mQuatOrientation.z * fi.x + mQuatOrientation.w * fi.y - mQuatOrientation.x * fi.z);
        mQuatOrientation.z += 0.5f * (mQuatOrientation.x * fi.y - mQuatOrientation.y * fi.x + mQuatOrientation.w * fi.z);
 
Could anybody confirm that it is OK algorithm?

algorithm for calulating angle between two points

27 April 2014 - 12:11 PM

In 3d space where

(1,0,0) - right

(0,1,0) - up

(0,0,1) - forward

0 degree means that vector from two points is (0,0,1)

90 degree means that vector from two points is (-1,0,0)

180 degree means that vector from two points is (0,0,-1)

270 degree means that vector from two points is (1,0,0)

 

My algorithm for calculation angle between two points is as below (in fact I calculate angle between camera location position and camera look-at position:

float angle = calculateAngle(cam->GetCamPos(), cam->GetCamLook()) - d3d::DEGREE_90;

float calculateAngle(D3DXVECTOR3* baseVec, D3DXVECTOR3* targetVec)
{
D3DXVECTOR2 vDiff;

D3DXVECTOR2 baseVec2(baseVec->x,baseVec->z);
D3DXVECTOR2 targetVec2(targetVec->x,targetVec->z);

D3DXVec2Subtract(&vDiff, &targetVec2, &baseVec2);
D3DXVec2Normalize(&vDiff, &vDiff);
//the angle is calculated from +X axis where the center of coordinate system XZ is baseVec
if(!vDiff.y)
{
    if(vDiff.x>0)
       return 0;
    else
       return D3DX_PI;
}
else if( vDiff.y > 0.f )
    return acosf(vDiff.x);
else
     return (acosf(-vDiff.x) + D3DX_PI);
}

The results is as in the attached image:

Attached File  issue0.JPG   69.53KB   2 downloads

Attached File  issue1.JPG   91.54KB   3 downloads

Instead of angle 45-60 I have angle 4 degree, so something is wrong.

My input data GetCamPos and GetCamLook are from View Matrix. Their coordinates are also seen at the attached pictures (camera pos, camera target).

The aim is that when I press "D" ball is kicked straigt forward according to the view.

I suppose that algorithm is OK, however instead GetCamLook I should take another input data, however I don't know which one. Maybe GetCamPos + GetCamLook or something like that.


share pasting HBITMAP and IDirect3DDevice9::Present method

16 March 2014 - 12:23 PM

Hi

I have a problem that Present method overwrite HBITMAP paste method. Here is my code:

 

if(mRefreshWindow)
{
       //mRefreshWindow = false;
            static bool once = false; 
            if(!once) //(-)
{
                pDev->Clear(0, 0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff000000, 1, 0); //(=)
   once = true;
   hDCWin=GetDC(NULL);


                i32 width = GetDeviceCaps(hDCWin, HORZRES);
                i32 height = GetDeviceCaps(hDCWin, VERTRES);


                HDC helpDc;
                helpDc=CreateCompatibleDC(NULL); //gui->hDCWin
                SelectObject(helpDc,hBMP);
                BOOL status = BitBlt(hDCWin,0,0,width,height,helpDc,0,0,SRCCOPY);
                ReleaseDC(hWnd,hDCWin); //do not release hdc, keep it for future purposes
                DeleteDC(helpDc);
}
}


pDev->BeginScene();


if(!mRefreshWindow)
   dialMgr->onRender(timeDelta);


pDev->EndScene();
if(!mRefreshWindow) //(*)
   pDev->Present(0, 0, 0, 0); //present back buffer

With the above code I have pasted my image on the screen.

If I uncomment (*) then my window is the whole black.

If I in addition to (*) delete (-) and (=) my window is black and image is pasted and this is very quickly changed like there is some fighting between "black screen and my image".

Does anybody know how to paste the image on the screen and then use Present method so that there is on the screen my image and also objects drawn between Begin and EndScene.


saving back buffer on another buffer and present

03 March 2014 - 08:01 AM

Hi

I have a problem. When I press "P" i my keyboard I want my scene pause (view freeze) - this works

and I want to present dialog box with menu content - this works

The above works however when I do some activity like for example showing content of combobox then as I don't clear back buffer, my view of the scene where the combobox control is placed, is ugly (there is some black rectangular). So my current solution is wrong. I have:

 

void GUI::Display(float timeDelta)
{ 
   if(!e3D->pause)
        (e3D->*(e3D->Display))(timeDelta);
   else
   {
           //pDev->Clear(0, 0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff000000, 1, 0); //do not clear when pause
           pDev->BeginScene();


          dialMgr->onRender(timeDelta);


          pDev->EndScene();
          pDev->Present(0, 0, 0, 0); //present back buffer
   }
}
 
and it should be sthm like this:
 
1.) in WndProc during handling "P" I should save back buffer


2.)
void GUI::Display(float timeDelta)
{ 
   if(!e3D->pause)
        (e3D->*(e3D->Display))(timeDelta);
   else
   {
           



           pDev->Clear(0, 0, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff000000, 1, 0); //clear back buffer


           present saved buffer somehow


           pDev->BeginScene();


          dialMgr->onRender(timeDelta);


          pDev->EndScene();
          pDev->Present(0, 0, 0, 0); //present back buffer
   }
}

Does anybody know how to save back buffer to another buffer and then present it?


What float unit should I choose for 1 [m]?

19 January 2014 - 01:35 PM

Hi

What unit should I choose for 1 [m], what value is the best? For example I have a football mesh. In reality the radius of the ball is about 11 cm (0,11m). Here on the screen:

http://imagizer.imageshack.us/v2/800x600q90/855/m2z1.jpg

the radius is 0,70 (I have float variable in which I store 0.70f). So this makes that in my game 0,70 [unit] means 0.11 [m], so 1 [m] is in fact 6,3636 units in my game.

I would like to scale my mesh and choose the scale of the world that 1 [m] = 1 [unit]. Without this there are some issues with physic. So from physic engine and generally logical point of view it would be the best to choose 1[m] as 1[unit], so radius float 0.11f means 0.11 [m]. However You know floats numbers have inacurracies, so is it good to choose 1[m] as 1[unit] or maybe better choice would be 1[m] as 100[unit]??? What is the best scale of the game environment?


PARTNERS