not sure about this. i have older programs where this calc works fine, then it doesn't work in my newer programs.
the 'z' value in the code should be the same???
rz1 & rz2 should give the same result...
[pbcode]
x# = 2 : z# = 3
angle# = 10
; goal = rotate around y axis so camera looks down zero angle (calc must be reversed angle)
; x# = x# * cos(-angle#) + z# * sin(-angle#)
; z# = x# * -sin(-angle#) + z# * cos(-angle#)
rx# = x# * cos(-angle#) + z# * sin(-angle#)
rz1# = x# * -sin(-angle#) + z# * cos(-angle#) ; *** wrong value here ??? ***
rz2# = x# * sin(angle#) + z# * cos(-angle#) ; *** alter equation here _ remove minus sign before sin() and use same angle ***
; NOTE: both z values should be the same answer
print "rx = "+str$(rx#)
print ""
print "rz1 -sin(-a) = "+str$(rz1#)+" ?"
print "rz2 sin(a) = "+str$(rz2#)
sync : flushkeys : waitkey
[/pbcode]
I don't know.... but will have a loook :)
So for future reference 1,64P4 returns
rx = 1.448671
rz1 -sin(-a) = 6.256143 ?
rz2 sin(a) = 3.30172
Pb 1.65 returns
rx = 1.448671
rz1 -sin(-a) = 6.256143 ?
rz2 sin(a) = 3.30172
You could swap the unary negation for a mult by *-1 as I've a feeling that'd be the issue.
[pbcode]
rz1# = x# * (sin(angle#*-1)*-1) + z# * cos(-angle#) ; *** wrong value here Huh ***
rz2# = x# * sin(angle#) + z# * cos(-angle#) ; *** alter equation here _ remove minus sign before sin() and use same angle ***
[/pbcode]
This seems to work, so my best guess would be the order of operations between the Mult and the negation of the SIN in the original expression.
ie. x# * -sin(-angle#)
It's a result of some precedence in the compiler. If you bracket the -sin(-angle#) it produces the same result.. Internally I think the wrapper inserts a mult by -1, but it's been a LONG time since i looked at that code.
[pbcode]
x# = 2
z# = 3
angle# = 10
; goal = rotate ar
; x# = x# * cos(-angle#) + z# * sin(-angle#)
; z# = x# * -sin(-angle#) + z# * cos(-angle#)
Print angle#
rx# = x# * Cos(-angle#) + z# * Sin(-angle#)
rz1# = x# * (-Sin(-angle#)) + z# * Cos(-angle#) ; *** wrong value here Huh ***
rz2# = x# * Sin(angle#) + z# * Cos(-angle#) ; *** alter equation here _ remove minus sign before sin() and use same angle ***
; NOTE: both z values should be the same answer
Print "rx = "+Str$(rx#)
Print ""
Print "rz1 -sin(-a) = "+Str$(rz1#)+" ?"
Print "rz2 sin(a) = "+Str$(rz2#)
sync
waitkey
[/pbcode]