Re: Smoothly rotating to another angle on pano nodes
Status: Alpha
Brought to you by:
cwalther
|
From: James C. W. <jfc...@ya...> - 2009-12-20 02:17:17
|
Yesterday I realized most of those problems, and fixed them. The new code runs very well, but oddly enough, doesn't return to exactly the defined target location, missing by about 1.5 degrees x, and 0.2 degrees y.
Here's the new code, commented. Sorry about not commenting the older code-it was quite late.
--included in node.lua
hotspot {
onmousedown = function()
autoPan_tarAZ, autoPan_tarEL = 270, 4
autoPan_time = 1
autoPan()
end
}
--autoPan.lua: an add-on file included in main.lua.
autoPan_funcCount = 0 --the number of times the function has been run.
autoPan_time = 1 --the duration, in seconds, the rotation should take to complete, set
--by onenternode in node.lua
autoPan_rate = 0.025 --the framrate of the rotation, e.g. how many times it runs per
--second.
autoPan_iterCount = 0 --the number of times the function should run, in order to get to the --target angle.
autoPan_tarAZ, autoPan_tarEL = 0, 0 --The target angle.
autoPan_viewAZ, autoPan_viewEL = pipmak.getviewdirection() --the current angle.
autoPan_speedAZ, autoPan_speedEL = 0 --the degree value which gets added to the
--current view angle each time the function runs.
function autoPan() --defining the function
pipmak.schedule(
autoPan_rate, --borrowing the framerate from the global autopan_rate.
function()
autoPan_viewAZ, autoPan_viewEL = pipmak.getviewdirection() --each time the function --is called, set the global to match the current viewing angle.
if autoPan_funcCount == 0 then --if the function has been run 0 times,
autoPan_iterCount = (autoPan_time) / autoPan_rate --then divide the duration of the
--event by the framrate, getting the number of times the function should be run, and dumping it into autoPan_iterCount,
autoPan_speedAZ = (autoPan_tarAZ - autoPan_viewAZ) / autoPan_iterCount
-- Subtract the AZ viewing angle from the
--target, and divide by autopan_iterCount, to get the the degree value which gets added to
--the current view angle each time the function runs.
autoPan_speedEL = (autoPan_tarEL - autoPan_viewEL) / autoPan_iterCount
-- Subtract the EL viewing angle from the
--target, and divide by autopan_iterCount, to get the the degree value which gets added to
--the current view angle each time the function runs.
end
if autoPan_funcCount == autoPan_iterCount then --if the # of times the function
--has been run equals the target number of times, then...
autoPan_funcCount = 0 --reset to 0,
return --stop the function.
else --if NOT, then...
autoPan_funcCount = autoPan_funcCount + 1 --increase the # of times the function
--has been run by 1.
pipmak.setviewdirection(autoPan_viewAZ + autoPan_speedAZ, autoPan_viewEL + autoPan_speedEL ) --add the neccessary change to each
--degree axis, as determined by the previous calcualtions.
end
return autoPan_rate --borrowing the framerate from the global autopan_rate.
end
)
end
CODE END.
Thanks,
James
--- On Sat, 12/19/09, Christian Walther <cwa...@gm...> wrote:
From: Christian Walther <cwa...@gm...>
Subject: Re: Smoothly rotating to another angle on pano nodes
To: pip...@li...
Date: Saturday, December 19, 2009, 4:41 PM
James C. Wilson wrote:
> When I run this code, Pipmak will smoothly rotate to either 90, 90, or
> 90, -90(disregarding panorama limits), and slowly spins.
> I can tell there's something wrong with this code, but I don't know what
> it is exactly, or how to fix it. Can anyone suggest a possible solution?
I probably can, if you can explain what exactly you want to achieve, or
what you expect this code to do. I can see that it approximately does
what you describe, but I can't tell in how far that is not what you expect.
A few comments on details that seem strange to me:
> local tarAZ, tarEL = 45, 45
> local viewAZ, viewEL = pipmak.getviewdirection()
> local speedAZ, speedEL
>
> if viewAZ > tarAZ then
> speedAZ = viewAZ / tarAZ
> elseif viewAZ < tarAZ then
> speedAZ = tarAZ / viewAZ
Are you aware that you may be dividing by zero here?
> end
You don't handle the case viewAZ == tarAZ here and leave speedAZ = nil
in that case, is that what you want?
> if viewEL > tarEL then
> speedEL = viewEL / tarEL
> elseif viewEL < tarEL then
> speedEL = tarEL / viewEL
> end
> hotspotmap "hotspotmap.png"
> hotspot {
> onmousedown = function()
> pipmak.schedule(
> 0.02,
> function()
> viewAZ, viewEL = pipmak.getviewdirection()
> if viewAZ == tarAZ and viewEL == tarEL then
> viewAZ, viewEL = tarAZ, tarEL
What's the point of this assignment? It has no effect since in the "if"
statement you just checked that its outcome is already true before.
> pipmak.setviewdirection( viewAZ + 0.8, viewEL * speedEL + 0.8 )
> end
> return 0.02
If you always return a number, the timer will repeat indefinitely, is
that what you want?
> end
> )
> end
> }
-Christian
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
Pipmak-Users mailing list
Pip...@li...
news://news.gmane.org/gmane.games.devel.pipmak.user
https://lists.sourceforge.net/lists/listinfo/pipmak-users
|