0

I'm doing a function in responce to WM_MOUSEMOVE to move my camera in opengl application.

The function is to take the STARTING POINT (old lParam from the wm_lbuttondown command)and subtract CURRENT POINT from STARTING POINT, and multiply the result by some floating point coefficient.

class cam
{
 int sp; //staring point saved here
 float x_coeff;//the addresses of sp and x_coeff are aligned , I can load them both as a quad-word later
}

case WM_LBUTTONDOWN:
    cam.sp=lParam;
    return 0;
case WM_MOUSEMOVE:
    cam.drag_camera(lParam);
    return 0;

cam::drag_camera(LPARAM lParam)
{
  float step=0.001;
  short old_x=sp&0xFFFF;
  short old_y=sp>>16;
  short current_x=lParam&0xFFFF;
  short curretn_y=lParam>>16;
  x_move=(old_x-current_x)*step;
  .... do something with the step
}

Ok, it works, but I'm trying to practice in using asm and all those nice registers. So here is my code for the same thing but using mmx registers

cam::drag_camera(LPARAM lParam)
{
  _asm
  { 
    movd mm0,lParam       //MOVE current mouse LPARAM point to mm0    - mm0 = 00:00:cy:cx
    movq mm1,[ebx+40h]    //MOVE starting mouse point LPARAM to low dword of mm1 and x_coeff in  high dword of mm1   - mm1 = x_coeff:sy:sx
    psubw mm1,mm0         //SUB current - starting mm1 = x_coeff:(sy-cy):(sx-cx)
    punpcklwd mm2,mm1     //PUT packed word result to mm2 double words   m2=00:(sy-cy):00:(sx-cx)
    psrad mm2,16          //Sign extend both double words of the result  m2=(sy-cy):(sx-cx)
    cvtpi2ps xmm7,mm2     //MOVE X Y result to XMM7  xmm7 = 0000:0000:sy-cy:sx-cx
    psrlq mm1,32          //SHIFT the x_coeff from the high dword to the left m1=00:00:x_coeff 
    movq2dq  xmm6,mm1     //SEND coeff to xmm6 low dword    xmm6=0000:0000:0000:x_coeff
    shufps xmm6,xmm6,00h  //SHUFFLE x_coeff everywhere      xmm6=x_coeff:x_coeff:x_coeff:x_coeff
    mulps xmm7,xmm6       //MULTIPLY 0:0:Y:X by x_coeff     xmm7=0000:0000:(sy-cy)*x_coeff:(sx-cx)*x_coeff

  }
}

The question is - is this a quick method of doing such a simple athirmetic or I could choose some other way of doing those things? Thanks

Antiusninja
  • 157
  • 1
  • 17

0 Answers0