|U| |V|
I wonder what is that mean.
?
maybe the vector length?
e.g. |U| is the length of vector U.
absolute value:
it means - if it's negative, multiply it by -1
so - yah, vector length :P
The formula Y= |U| |V| as it stands means
If U < 0 then
U = -U
Else
U = U (if this makes sense :green2)
endif
So Y = Abs(U) * Abs(V) >= 0
In correct Vector maths notation |U| should have a '-' on top of the 'U' (I don't know how to do it on the keyboard) and..
Length of vector
|U| = Sqr(X^2 + Y^2 +.....+ n^2)
Which is positive anyway (unless you're going complex) so...
|U| * |V| >= 0
Hi, THanks All, its right, it was for vector length.
THey said to find an angles between 2 vectors I need to calculate it this way Cos^-1(Ux.Vx+Uy.Vy+Uz.Vz)/|U| |V|. I dont get what is the logic behind it, but I hope it will just worked.
Are you trying to work out the luminance or reflection off a surface in Dx... This is known as the Vector Dot Product
Quote from: vanjast on February 24, 2012, 05:59:28 PM
Are you trying to work out the luminance or reflection off a surface in Dx... This is known as the Vector Dot Product
No, Im just wanted to know how to obtain an angle between 2 Vectors. I tried this but it did not worked
FPGetAngles proc uses esi edi lpPos:dword,lpRotation:dword
LOCAL signX,signY:dword
LOCAL rslt:VERTEX
LOCAL q:dword
LOCAL t:qword
;++ = 0-90
;+- = 91-180
;-- = 181=270
;-+ = 271-360
mov esi,lpPos
mov edi,lpRotation
; X = Y,Z
; Y = X,Z
; Z = X,Y
invoke Vec_Normalize,addr rslt,lpPos
; invoke Vec_Copy,addr rslt,lpPos
fld rslt.y
invoke FpuArcsin,0,0,129
fstp [edi].VERTEX.x
fld rslt.x
fld rslt.z
fpatan
fstp q
invoke Vec_RadToDeg,q
fstp [edi].VERTEX.y
; fld rslt.x
; fld rslt.y
; fpatan
; fstp q
; invoke Vec_RadToDeg,q
; fldz
; fstp [edi].VERTEX.z
ret
FPGetAngles endp
On a few test it worked, like when you input X=10 but Y=Z=0, it will yield a right results. But problem occurs when you move the cameras. I dont know where went wrong, is it because the physic engine messed up the rotation order or what. But if that test was worked, it should be worked everywhere, but nevermind it, I given up. My brain almost exploded. :toothy
VERTEX struct
x REAL8 ?
y REAL8 ?
z REAL8 ?
VERTEX ends
Angle proc uses esi edi pAngle: ptr REAL4,pU:ptr VERTEX,pV:ptr VERTEX
LOCAL abs1:REAL8
LOCAL abs2:REAL8
mov esi,pU
mov edi,pV
;|U|
fld [esi].VERTEX.x
fmul st,st
fld [esi].VERTEX.y
fmul st,st
faddp st(1),st
fld [esi].VERTEX.z
fmul st,st
faddp st(1),st
fsqrt
fstp abs1
.if !DWORD ptr abs1[0] && !DWORD ptr abs1[4]
; error: null vector
xor eax,eax
ret
.endif
;|V|
fld [edi].VERTEX.x
fmul st,st
fld [edi].VERTEX.y
fmul st,st
faddp st(1),st
fld [edi].VERTEX.z
fmul st,st
faddp st(1),st
fsqrt
fst abs2
.if !DWORD ptr abs2[0] && !DWORD ptr abs2[4]
; error: null vector
xor eax,eax
ret
.endif
; |U|*|V|
fmul abs1
; U*V
fld [esi].VERTEX.x
fmul [edi].VERTEX.x
fld [esi].VERTEX.y
fmul [edi].VERTEX.y
faddp st(1),st
fld [esi].VERTEX.z
fmul [edi].VERTEX.z
faddp st(1),st
; U*V / |U|*|V|
fdivrp st(1),st
; acos(U*V / |U|*|V|)
fst abs1
test DWORD ptr abs1+4,80000000h
fmul st,st
fld st
fld1
fsubrp st(1),st
fdivp st(1),st
fabs
fsqrt
fld1
fpatan
fld FP4(1.5707963267949) ; pi/2
.if ZERO?
fsubrp st(1),st
.else
faddp st(1),st
.endif
; rad -> deg
fmul FP4(57.2957795131) ; 180/pi
mov edi,pAngle
fstp REAL4 ptr [edi]
mov eax,1
ret
Angle endp
Quote from: qWord on February 25, 2012, 02:35:09 AM
VERTEX struct
x REAL8 ?
y REAL8 ?
z REAL8 ?
VERTEX ends
Angle proc uses esi edi pAngle: ptr REAL4,pU:ptr VERTEX,pV:ptr VERTEX
LOCAL abs1:REAL8
LOCAL abs2:REAL8
mov esi,pU
mov edi,pV
;|U|
fld [esi].VERTEX.x
fmul st,st
fld [esi].VERTEX.y
fmul st,st
faddp st(1),st
fld [esi].VERTEX.z
fmul st,st
faddp st(1),st
fsqrt
fstp abs1
.if !DWORD ptr abs1[0] && !DWORD ptr abs1[4]
; error: null vector
xor eax,eax
ret
.endif
;|V|
fld [edi].VERTEX.x
fmul st,st
fld [edi].VERTEX.y
fmul st,st
faddp st(1),st
fld [edi].VERTEX.z
fmul st,st
faddp st(1),st
fsqrt
fst abs2
.if !DWORD ptr abs2[0] && !DWORD ptr abs2[4]
; error: null vector
xor eax,eax
ret
.endif
; |U|*|V|
fmul abs1
; U*V
fld [esi].VERTEX.x
fmul [edi].VERTEX.x
fld [esi].VERTEX.y
fmul [edi].VERTEX.y
faddp st(1),st
fld [esi].VERTEX.z
fmul [edi].VERTEX.z
faddp st(1),st
; U*V / |U|*|V|
fdivrp st(1),st
; acos(U*V / |U|*|V|)
fst abs1
test DWORD ptr abs1+4,80000000h
fmul st,st
fld st
fld1
fsubrp st(1),st
fdivp st(1),st
fabs
fsqrt
fld1
fpatan
fld FP4(1.5707963267949) ; pi/2
.if ZERO?
fsubrp st(1),st
.else
faddp st(1),st
.endif
; rad -> deg
fmul FP4(57.2957795131) ; 180/pi
mov edi,pAngle
fstp REAL4 ptr [edi]
mov eax,1
ret
Angle endp
Look cool. If I know how to use this and it worked, it mean youre a genius. I've bee looking for the logic behind this.
; acos(U*V / |U|*|V|)
although, it might be simplified...
http://steve.hollasch.net/cgindex/math/anglevec.html