hi all, i’m trying to move a single vertex along an axis through a sinusoidal path, but this lines i wrote seem not to work properly. any ideas?
thanx in advance.
yuri
import Rasterizer as R
import GameLogic as GL
import math
scene = GL.getCurrentScene()
obj = scene.objects['OBMyObj']
vert = obj.meshes[0].getVertex(0,5)
vertCoords = vert.getXYZ()
vert.setXYZ([(1*math.sin(2*math.pi*vertCoords[0]/1.9)),vertCoords[1],vertCoords[2]])
I dont see this as a sinosoidal curve… Since y and z ot the vertex do NOT change, it will result in ONLY oscilation on x of that vertex. Lets accept that your z will remain unchanged. Then, to reaching a sinosoidal curve along axis OX, you need to calculate the y coordinate on the basis of x. In that case, your sinosoidal curve will lye in a plane P parallel to XOY and displaced at z units off XOY…
hi abidos, thanx for your reply; in fact the movement i imagine is something like the “loading bar” in various software… imagine a vertex sliding from A to B along its X axis (not over a plane, in fact) and “smoothing” its movement near the two limits.
(beg my pardon for my ridiculous english)
apart from this, i tried your code and it didn’t work: it seems to that math.pi() isn’t correct and i used co[0], co[1] and co[2] to refer to vertex coords (i don’t know if it is correct!).
moreover, i have another problem: i don’t know how to execute the code ONLY at game start. i assume it’s something like activating false triggering with always actuator, but i cannot do it yet.
and last but not least i’d like to know something more about wave modifier in bge. atom, i’ll be glad if you can route me in the right direction.
i’ll take a peek into this forum, maybe tomorrow. thanx in advance for the help.
Well, really the math.pi shall be without the brackets… with the brackets is pi() in VBA… Sorry for that mistake…
Other than that, I think the code is working… you just need to convert the argument to something which is a float. As getXYZ() is not my proc, I re-worked the code like this:
from Blender import *
import bpy
import math
def Sine_Test():
sce = bpy.data.scenes.active
ob = sce.objects.active
me = ob.getData(mesh=1)
vert = me.verts[0]
scale_factor = 100
for x in range(180):
co = vert.co # vertCoords
co.y = (math.sin(math.pi*(1.0*x/180)))*scale_factor
vert.co = co
Redraw()
return
Sine_Test()
With the default cube selected, you can actually see how it moves on sinosoidal pattern. Here is the testing blend file… To confirm the pattern is a part of a sine curve, I have taken out the results and put them in EXCEL to produce a simple graph… Here it is:
And I think, it is a half of a sine curve with amplitude = 100, right??
BTW, is the ping-pong running on a sine curve? I thought it follows a ballistic curve which is far more difficult to calculate though…