# vertex sine-waving

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?

yuri

``````
import Rasterizer as R
import GameLogic as GL
import math

scene = GL.getCurrentScene()

obj = scene.objects['OBMyObj']

vert = obj.meshes.getVertex(0,5)

vertCoords = vert.getXYZ()

vert.setXYZ([(1*math.sin(2*math.pi*vertCoords/1.9)),vertCoords,vertCoords])

``````

Couldn’t you just assign that vertex to a vertex group then use the wave modifier on that vertex group?

but… modifiers available in bge? argh i didn’t notice it!

but i still don’t know how to use them 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…

Some calculation of the above may look like:

``````
scale_factor = 100
co = vert.getXYZ()  # vertCoords
co.y = (math.sin(math.pi()*(co.x/180)))*scale_factor
vert.setXYZ(co)

``````

The scale_factor gives you the height of the sinosoidal wave so above it is = 100.

The code above may need some further adjustments to the specific needs you may have.

Regards,

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, co and co 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.

modifiers available in bge? argh i didn’t noticed it!

sorry, grammar error, you’re right by the way, in the meantime i did it with a shape action actuator. i’m still struggling to do it with python.

btw, the wave modifier doesn’t produce a real sinus.

yeah, i got it!  many thanx to all of you 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
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…

Regards,

What would it take to make this work on a plane, instead of a single vert? I’m not much of a python guy… at all.
trying fore this: