System Quaternions

jackall

You can change this now in User CP.
Reaction score
37
Hello! I made this post (i don't know the real reason) to help others that want to become modelers/animators that make the animations themselves.
You can get Pascal and JASS scrips from this link.
If for some unknown reason the link doesn't work here they are:
in JASS:
JASS:
function Quaternion takes real angx, real angy, real angz returns nothing
  local string result
  local real x
  local real y
  local real z
  local real total = x + y + z
  local real a
  local real qx
  local real qy
  local real qz
  local real qw
  local integer axisNo
  set x = 1
  set y = 1
  set z = 1
  if angx == 0 then
    set x = 0
  elseif angy == 0 then
    set y = 0
  elseif angz == 0 then
    set z = 0
  endif
  if x == 1 then
    set axisNo = axisNo + 1
  elseif y == 1 then
    set axisNo = axisNo + 1
  elseif z == 1 then
    set axisNo = axisNo + 1
  endif
  if axisNo == 1 then
    set a = 1
  elseif axisNo == 2 then
    set a = 0.707
  elseif axisNo == 3 then
    set a = 0.577
  endif
  set qx = a * x * SinBJ(angx/2)
  set qy = a * y * SinBJ(angy/2)
  set qz = a * z * SinBJ(angz/2)
  set qw = CosBJ(total/2)
  set result = R2S(qx) + ", " + R2S(qy) + ", " + R2S(qz) + ", " + R2S(qw)
    call BJDebugMsg(result)
endfunction


in Pascal
NOTE: you need a program called Scar (from here or here) to use this version of the script


Scar Version:
Code:
program New;
var
  frmDesign : TForm;
  Button1 : TButton;
  Edit1 : TEdit;
  Edit2 : TEdit;
  Edit3 : TEdit;
  xAng,yAng,zAng,x,y,z,qx,qy,qz,qw,total,a,axisNo : extended;
  return: string;
function DegToRad(angle: extended): extended;
begin
  Result:= angle * 0.017453292519943295769236907684886
end;
procedure buttonclick(sender: TObject);
begin
  xAng:= StrToFloat(Edit1.Text)
  yAng:= StrToFloat(Edit2.Text)
  zAng:= StrToFloat(Edit3.Text)
  total:= xAng + yAng + zAng
  x:= 1
  y:= 1
  z:= 1
  if xAng = 0 then
    x:= 0
  if yAng = 0 then
    y:= 0
  if zAng = 0 then
    z:= 0
  if x = 1 then
    axisNo:= axisNo + 1
  if y = 1 then
    axisNo:= axisNo + 1
  if z = 1 then
    axisNo:= axisNo + 1
  if axisNo = 1 then
    a:= 1
  if axisNo = 2 then
    a:= 0.707
  if axisNo = 3 then
    a:= 0.577
  qx:= a * x * Sin(DegToRad(xAng/2))
  qy:= a * y * Sin(DegToRad(yAng/2))
  qz:= a * z * Sin(DegToRad(zAng/2))
  qw:= Cos(DegToRad(total/2))
  return:= (FloatToStr(qx) + ', ' + FloatToStr(qy) + ', ' + FloatToStr(qz) + ', ' + FloatToStr(qw))
  WriteLn(return)
end;
procedure InitForm;
begin
  frmDesign := CreateForm;
  frmDesign.Left := 250;
  frmDesign.Top := 114;
  frmDesign.Width := 225;
  frmDesign.Height := 176;
  frmDesign.Caption := 'frmDesign';
  frmDesign.Color := clBtnFace;
  frmDesign.Font.Color := clWindowText;
  frmDesign.Font.Height := -11;
  frmDesign.Font.Name := 'MS Sans Serif';
  frmDesign.Font.Style := [];
  frmDesign.Visible := False;
  frmDesign.PixelsPerInch := 96;
  Button1 := TButton.Create(frmDesign);
  Button1.OnClick := @buttonclick;
  Button1.Parent := frmDesign;
  Button1.Left := 23;
  Button1.Top := 110;
  Button1.Width := 75;
  Button1.Height := 25;
  Button1.Caption := 'Calculate';
  Button1.TabOrder := 8;
  Edit1 := TEdit.Create(frmDesign);
  Edit1.Parent := frmDesign;
  Edit1.Left := 25;
  Edit1.Top := 15;
  Edit1.Width := 125;
  Edit1.Height := 20;
  Edit1.TabOrder := 9;
  Edit1.Text := 'X Angle';
  Edit2 := TEdit.Create(frmDesign);
  Edit2.Parent := frmDesign;
  Edit2.Left := 25;
  Edit2.Top := 46;
  Edit2.Width := 125;
  Edit2.Height := 20;
  Edit2.TabOrder := 10;
  Edit2.Text := 'Y Angle';
  Edit3 := TEdit.Create(frmDesign);
  Edit3.Parent := frmDesign;
  Edit3.Left := 25;
  Edit3.Top := 75;
  Edit3.Width := 125;
  Edit3.Height := 21;
  Edit3.TabOrder := 11;
  Edit3.Text := 'Z Angle';
end;
procedure SafeInitForm;
var
  v: TVariantArray;
begin
  setarraylength(V, 0);
  ThreadSafeCall('InitForm', v);
end;
procedure ShowFormModal;
begin
  frmDesign.ShowModal;
end;

procedure SafeShowFormModal;
var
  v: TVariantArray;
begin
  setarraylength(V, 0);
  ThreadSafeCall('ShowFormModal', v);
end;
begin
  SafeInitForm;
  SafeShowFormModal;
end.

Normal Pascal Version
Code:
program Quaternion;
var
  xAng,yAng,zAng,x,y,z,qx,qy,qz,qw,total,a,axisNo : extended;
  return: string;
function DegToRad(angle: extended): extended;
begin
  Result:= angle * 0.017453292519943295769236907684886
end;
begin
//Write here V the X angle
  xAng:= 
//Write here V the Y angle
  yAng:= 
//Write here V the Z angle
  zAng:= 
  total:= xAng + yAng + zAng
  x:= 1
  y:= 1
  z:= 1
  if xAng = 0 then
    x:= 0
  if yAng = 0 then
    y:= 0
  if zAng = 0 then
    z:= 0
  if x = 1 then
    axisNo:= axisNo + 1
  if y = 1 then
    axisNo:= axisNo + 1
  if z = 1 then
    axisNo:= axisNo + 1
  if axisNo = 1 then
    a:= 1
  if axisNo = 2 then
    a:= 0.707
  if axisNo = 3 then
    a:= 0.577
  qx:= a * x * Sin(DegToRad(xAng/2))
  qy:= a * y * Sin(DegToRad(yAng/2))
  qz:= a * z * Sin(DegToRad(zAng/2))
  qw:= Cos(DegToRad(total/2))
  return:= (FloatToStr(qx) + ', ' + FloatToStr(qy) + ', ' + FloatToStr(qz) + ', ' + FloatToStr(qw))
  WriteLn(return)
end.

This is my first ever tutorial/"system" so any suggestions on improvements i should make :(. (i'm stupid...i know)
The JASS version can be upgraded (i guess) and i -will- try to.
 

Tom_Kazansky

--- wraith it ! ---
Reaction score
157
can you use Code tag instead ? there is no indent with Quote tag :(
it's hard to read :banghead:
 

jackall

You can change this now in User CP.
Reaction score
37
@Trollvottel: you can use quaternions to make animations for models
 

Jesus4Lyf

Good Idea™
Reaction score
397
@Trollvottel: you can use quaternions to make animations for models
Your JASS function certainly does not achieve this.
Unless you can explain in an easy-to-understand manner how this is used to make animations, I don't think our audience has any use for this.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top