+ Reply to Thread
Results 1 to 5 of 5

Thread: Quaternions?

  1. #1
    Expressionism 2.0 Syranide's Avatar
    Join Date
    Mar 2007
    Location
    Sweden
    Posts
    4,573

    Default

    So as I'm not all familiar with Quaternions myself I was hoping someone here would be.
    Basically, what functionality/operators/methods would be necessary for Quaternions being useful in-game with-in the expression gate?
    I've implemented Q+Q, Q-Q, Q*Q, Q*S, S*Q (also soon Q*V) as they should be, but I'm not sure what functions should go with that to make them useful.
    Vectors are available, but not matrices.

  2. #2
    That furred thing Black Phoenix's Avatar
    Join Date
    Feb 2007
    Location
    Kyiv, Ukraine
    Posts
    3,565

    Default

    Implement matrices (add, sub, mul, inversion, vector mul, rotation matrixes, translate, scale, perspective, ortho)

    Some code you might want to use (from GPU ):
    Code:
    ****self.OpcodeTable[250] = function ()****//MADD
    
    ********local mx1 = self:ReadMatrix(self.Params[1])
    
    ********local mx2 = self:ReadMatrix(self.Params[2])
    
    ********local rmx = {}
    
    
    
    ********for i=0,15 do
    
    ************rmx[i] = mx1[i] + mx2[i]
    
    ********end
    
    
    
    ********self:WriteMatrix(self.Params[1],rmx)********
    
    ********self.WriteBack = false
    
    ****end
    
    ****self.OpcodeTable[251] = function () ****//MSUB
    
    ********local mx1 = self:ReadMatrix(self.Params[1])
    
    ********local mx2 = self:ReadMatrix(self.Params[2])
    
    ********local rmx = {}
    
    
    
    ********for i=0,15 do
    
    ************rmx[i] = mx1[i] - mx2[i]
    
    ********end
    
    
    
    ********self:WriteMatrix(self.Params[1],rmx)********
    
    ********self.WriteBack = false
    
    ****end
    
    ****self.OpcodeTable[252] = function () ****//MMUL
    
    ********local mx1 = self:ReadMatrix(self.Params[1])
    
    ********local mx2 = self:ReadMatrix(self.Params[2])
    
    ********local rmx = {}
    
    
    
    ********for i=0,3 do
    
    ************for j=0,3 do
    
    ****************rmx[i*4+j] = mx1[i*4+0] * mx2[0*4+j] +
    
    ************************ mx1[i*4+1] * mx2[1*4+j] +
    
    ************************ mx1[i*4+2] * mx2[2*4+j] +
    
    ************************ mx1[i*4+3] * mx2[3*4+j]
    
    ************end
    
    ********end
    
    
    
    ********self:WriteMatrix(self.Params[1],rmx)********
    
    ********self.WriteBack = false
    
    ****end
    
    ****self.OpcodeTable[253] = function () ****//MROT
    
    ********local vec = self:Read4f(self.Params[2])
    
    ********local rm = {}
    
    
    
    ********local axis = {}
    
    ********axis[0] = vec.x
    
    ********axis[1] = vec.y
    
    ********axis[2] = vec.z
    
    ********
    
    ********local angle = vec.w * 3.1415926 / 180;
    
    
    
    ********local mag = math.sqrt(axis[0]*axis[0] + axis[1]*axis[1] + axis[2]*axis[2])
    
    ********if (mag > 0) then
    
    ************axis[0] = axis[0] / mag
    
    ************axis[1] = axis[1] / mag
    
    ************axis[2] = axis[2] / mag
    
    ********end
    
    
    
    ********local sine = math.sin(angle)
    
    ********local cosine = math.cos(angle)
    
    
    
    ********local ab = axis[0] * axis[1] * (1 - cosine)
    
    ********local bc = axis[1] * axis[2] * (1 - cosine)
    
    ********local ca = axis[2] * axis[0] * (1 - cosine)
    
    ********local tx = axis[0] * axis[0]
    
    ********local ty = axis[1] * axis[1]
    
    ********local tz = axis[2] * axis[2]
    
    
    
    ********rm[0]**= tx + cosine * (1 - tx)
    
    ********rm[1]**= ab + axis[2] * sine
    
    ********rm[2]**= ca - axis[1] * sine
    
    ********rm[3]**= 0
    
    ********rm[4]**= ab - axis[2] * sine
    
    ********rm[5]**= ty + cosine * (1 - ty)
    
    ********rm[6]**= bc + axis[0] * sine
    
    ********rm[7]**= 0
    
    ********rm[8]**= ca + axis[1] * sine
    
    ********rm[9]**= bc - axis[0] * sine
    
    ********rm[10] = tz + cosine * (1 - tz)
    
    ********rm[11] = 0
    
    ********rm[12] = 0
    
    ********rm[13] = 0
    
    ********rm[14] = 0
    
    ********rm[15] = 1
    
    
    
    ********self:WriteMatrix(self.Params[1],rm)********
    
    ********self.WriteBack = false
    
    ****end
    
    ****self.OpcodeTable[254] = function () ****//MSCALE
    
    ********local vec = self:Read3f(self.Params[2])
    
    ********local rm = {}
    
    
    
    
    
    ********rm[0]**= vec.x
    
    ********rm[1]**= 0
    
    ********rm[2]**= 0
    
    ********rm[3]**= 0
    
    
    
    ********rm[4]**= 0
    
    ********rm[5]**= vec.y
    
    ********rm[6]**= 0
    
    ********rm[7]**= 0
    
    
    
    ********rm[8]**= 0
    
    ********rm[9]**= 0
    
    ********rm[10] = vec.z
    
    ********rm[11] = 0
    
    
    
    ********rm[12] = 0
    
    ********rm[13] = 0
    
    ********rm[14] = 0
    
    ********rm[15] = 1
    
    
    
    ********self:WriteMatrix(self.Params[1],rm)********
    
    ********self.WriteBack = false
    
    ****end
    
    ****self.OpcodeTable[256] = function () ****//MTRANS
    
    ********local vec = self:Read3f(self.Params[2])
    
    ********local rm = {}
    
    
    
    
    
    ********rm[0]**= 1
    
    ********rm[1]**= 0
    
    ********rm[2]**= 0
    
    ********rm[3]**= vec.x
    
    
    
    ********rm[4]**= 0
    
    ********rm[5]**= 1
    
    ********rm[6]**= 0
    
    ********rm[7]**= vec.y
    
    
    
    ********rm[8]**= 0
    
    ********rm[9]**= 0
    
    ********rm[10] = 1
    
    ********rm[11] = vec.z
    
    
    
    ********rm[12] = 0
    
    ********rm[13] = 0
    
    ********rm[14] = 0
    
    ********rm[15] = 1
    
    
    
    ********self:WriteMatrix(self.Params[1],rm)********
    
    ********self.WriteBack = false
    
    ****end
    
    ****//------------------------------------------------------------
    
    ****self.OpcodeTable[260] = function () ****//MIDENT
    
    ********local rm = {}
    
    
    
    ********rm[0]**= 1
    
    ********rm[1]**= 0
    
    ********rm[2]**= 0
    
    ********rm[3]**= 0
    
    
    
    ********rm[4]**= 0
    
    ********rm[5]**= 1
    
    ********rm[6]**= 0
    
    ********rm[7]**= 0
    
    
    
    ********rm[8]**= 0
    
    ********rm[9]**= 0
    
    ********rm[10] = 1
    
    ********rm[11] = 0
    
    
    
    ********rm[12] = 0
    
    ********rm[13] = 0
    
    ********rm[14] = 0
    
    ********rm[15] = 1
    
    
    
    ********self:WriteMatrix(self.Params[1],rm)********
    
    ********self.WriteBack = false
    
    ****end
    I'm a wire-crazy person with a tail.

    Take a daily journey into my brain

    D2K5

  3. #3
    Expressionism 2.0 Syranide's Avatar
    Join Date
    Mar 2007
    Location
    Sweden
    Posts
    4,573

    Default

    Well, the reason I don't want to add matrices is not "just because", but because they require a whole lot of instructions to compute, even a simple addition requires 16 additions. And that is really bad considering that the expression gate might be updated 40+ per second and that people often write rather unoptimized code. Which might of course work with the CPU because it isn't realtime in the same sense and bad code just contributes to a slower execution of the code. But it kind of depends as well, if Wire2 turns out good it might be still be feasible as of the improved "propagation".

    But we'll see, I might implement them in the end, altough I'm not sure what people would use matrices for when you have quaternions and vectors.

    Btw, you might want to look into my interpreter instructions when I'm done, they contain insanely optimized versions of everything you can think of :lol:. I've even made my own floor/ceil/round/int/frac/etc... functions that are more than 100% faster. Also did my own implementation of vectors... just because it turned out to be more than 200% faster from time to time.

  4. #4
    That furred thing Black Phoenix's Avatar
    Join Date
    Feb 2007
    Location
    Kyiv, Ukraine
    Posts
    3,565

    Default

    CPU (GPU in this case) is realtime, but it updates at 10 to 30 times per second (FPS from 40 to 120) :P
    I'm a wire-crazy person with a tail.

    Take a daily journey into my brain

    D2K5

  5. #5
    Wire Amateur Kirk's Avatar
    Join Date
    Feb 2008
    Location
    The Netherlands
    Posts
    60

    Default

    Quaternions are most useful for angular interpolation. Although matrices are resource intensive, it might still be worth considering since people generally are more familiar with matrices than with quaternions (cause ya know, complex numbers are often considered evil ).
    Quote Originally Posted by LuaPineapple
    WTF does it mean "unable to read int expected int but got int"?

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots