//#warning FALSE


#define MouseMaxXCoord 64
#define MouseMaxYCoord 64

int XMouseCoord,YMouseCoord;
byte MouseBut;


MouseInit()
{
 AX=0;$int 33h
 AX=7;CX=0;DX=MouseMaxXCoord;$int 33h
 AX=8;CX=0;DX=MouseMaxYCoord;$int 33h
 AX=26;BX=40;CX=40;DX=1000;$int 33h
 CX=MouseMaxXCoord/2;DX=MouseMaxYCoord/2;
 AX=4;$int 33h
}


MouseRotateObject(dword objnum)
float angle;
//word KeyboardStatus;
{
 AX=3;$int 33h
 XMouseCoord=CX;
 YMouseCoord=DX;
 MouseBut=BL;

 XMouseCoord-=MouseMaxXCoord/2;
 YMouseCoord-=MouseMaxYCoord/2;

 AH=2;$int 16h
// KeyboardStatus=AX;
 if ($test AX,3){ // Если нажата shift
    IF (MouseBut&1) Object[objnum].rz+=0.017453292519943296;
    IF (MouseBut&2) Object[objnum].rz-=0.017453292519943296;

    angle=0.017453292519943296*XMouseCoord;
    Object[objnum].ry+=angle;
    angle=0.017453292519943296*YMouseCoord;
    Object[objnum].rx+=angle;
 }else if ($test AX,4){ // Если нажата ctrl
    IF (MouseBut&1) Camera.sz1=2;
    ELSE IF (MouseBut&2) Camera.sz1=-2;
    ELSE Camera.sz1=0;
    $fild XMouseCoord $fstp Camera.sx1
    $fild YMouseCoord $fstp Camera.sy1
    //Перемещаем координаты камеры на полученный вектор
    //Делае поворот вектора перемещения по OX и OY
    ClearMatrix(dword #Matrix);
    $fld Camera.RotateOX
    $fsincos
    $fst Matrix[5*4]
    $fstp Matrix[10*4]
    $fst Matrix[9*4]
    $fchs
    $fstp Matrix[6*4]
    _MulMatrixAVectorA_4x4(dword #Matrix, dword #Camera.sx1, dword #Camera.sx1);
    ClearMatrix(dword #Matrix);
    $fld Camera.RotateOY
    $fsincos
    $fst Matrix[0]
    $fstp Matrix[10*4]
    $fst Matrix[2*4]
    $fchs
    $fstp Matrix[8*4]
    _MulMatrixAVectorA_4x4(dword #Matrix, dword #Camera.sx1, dword #Camera.sx1);
    $fld Camera.sx $fadd Camera.sx1 $fstp Camera.sx
    $fld Camera.sy $fadd Camera.sy1 $fstp Camera.sy
    $fld Camera.sz $fadd Camera.sz1 $fstp Camera.sz
//    Camera.sx+=Camera.sx1;
//    Camera.sy+=Camera.sy1;
//    Camera.sz+=Camera.sz1;
 }else IF ($test AX,8){ // Если нажата alt
    IF (MouseBut&1) Camera.RotateOZ+=0.017453292519943296;
    IF (MouseBut&2) Camera.RotateOZ-=0.017453292519943296;

    angle=0.017453292519943296*XMouseCoord;
    Camera.RotateOY+=angle;
    angle=0.017453292519943296*YMouseCoord;
    Camera.RotateOX+=angle;
 }ELSE{
  IF (MouseBut&1) Object[objnum].z-=2;
  IF (MouseBut&2) Object[objnum].z+=2;
  Object[objnum].x+=XMouseCoord;
  Object[objnum].y-=YMouseCoord;
 }

 CX=MouseMaxXCoord/2;DX=MouseMaxYCoord/2;
 AX=4;$int 33h
}