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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      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