Posted: 11th Jan 2014 22:54
I needed an easy way to make a conduit/cylinder skewed so as to be able to make simple inclined/declined hallways for connecting rooms.



It turned out to be simpler than I thought.
This example skews the object along the X axis according to the vertex height.

+ Code Snippet
backdrop on:color backdrop rgb(128,0,255)
make object cylinder 1,10:set object wireframe 1,1:set object cull 1,0
t#=timer()+3000
while t#>timer():set cursor 0,0:print "Unskewed...":yrotate object 1,object angle Y(1)+.1:ENDWHILE

lock vertexdata for limb 1,0
for v=0 to get vertexdata vertex count()
Xpos#=get vertexdata position x(v)
Ypos#=get vertexdata position y(v)
set vertexdata position v,Xpos#+(Ypos#*.5),get vertexdata position y(v),get vertexdata position z(v)
NEXT
unlock vertexdata:color backdrop rgb(190,20,100)

do
set cursor 0,0:print "Skewed."
yrotate object 1,object angle Y(1)+.1
LOOP
Posted: 12th Jan 2014 0:56
It turned out to be simpler than I thought


Yeah , we can make an elbow with several skew cylinder.

Now try to figure out, how to apply animation in real time

Cheers.
Posted: 13th Jan 2014 19:45
Yeah , we can make an elbow with several skew cylinder.

Now try to figure out, how to apply animation in real time


I wish!
My ability is limited because of my lack of math concepts.

(I'm too lazy to learn trigonometry, etc.)
Posted: 13th Jan 2014 22:14
(I'm too lazy to learn trigonometry, etc.)


When we set vertexdata position, we can check if vertex y are higher than 0 and if YES, we skew vertex. So knowing that, imagine that we decide to get only vertex higher than zero, and not all of them but every three vertex. Could be something like this:

+ Code Snippet
autocam off
sync on
make object cylinder 100,10
set object cull 100,0

lock vertexdata for limb 100,0
    vertices = get vertexdata vertex count()
    for i = 0 to vertices
        inc a
        if a>3 then a=0
        x# = get vertexdata position x(i)
        y# = get vertexdata position y(i)
        z# = get vertexdata position z(i)
        if y#>0 then set vertexdata position i,x#*1.2,y#,z#*1.2
        if y#>3 and a=1 then set vertexdata position i,x#*1.2,y#-6,z#*1.2
     next i
unlock vertexdata

position camera -10,20,-30
point camera 0,0,0
do
g#=g#+0.04
yrotate object 100,g#
set cursor 5,5:print vertices
sync
loop


And for animate vertex, could be like this:

+ Code Snippet
ink rgb(100,90,0),0:box 0,0,40,80:ink rgb(70,40,0),0:box 0,39,40,41
box 0,0,2,40:box 19,40,21,80:box 0,0,40,2
get image 1,0,0,40,80,1

for i= 1 to 5700
   col=rnd(50)
   dot rnd(20),rnd(20),rgb(150+col,100+col,100+col)
next i
blur bitmap 0,1
get image 2,0,0,20,20,1

autocam off
sync on

rem cone
make object cylinder 1,10
texture object 1,1
set light mapping on 1,2
scale object texture 1,5,5
make mesh from object 1,1
set object cull 1,0

rem rings
make object cylinder 50,6:scale object 50,300,10,300
color object 50,rgb(255,0,255)
set object emissive 50,rgb(255,0,255)
set object cull 50,0
clone object 51,50:set object emissive 51,rgb(0,255,0)

position camera -0,10,-30
point camera 0,0,0
sc#=0.5
do
ink rgb(255,255,255),0
set cursor 0,0
print "Press a or s key "
print "use arrowkeys to free move"

position object 50,0,3,0
move object 50,-4
position object 51,0,1,0
move object 51,3
zrotate object 50,-object position x(51)*5
zrotate object 51,-object position x(51)*3

g#=g#+0.8+(0.8-sc#)
yrotate object 50,g#
yrotate object 51,g#

if inkey$()="a" then sc#=sc#+0.001
if inkey$()="s" then sc#=sc#-0.001
rem top to the size
if sc#>1 then sc#=1
if sc#<0 then sc#=0

 change mesh 1,0,1    rem change mesh to avoid vertex collapsing.

lock vertexdata for limb 1,0
    vertex = get vertexdata vertex count()
    for i =0  to vertex
        x# = get vertexdata position x(i)
        y# = get vertexdata position y(i)
        z# = get vertexdata position z(i)
        if y#>0 then set vertexdata position i,x#*sc#+object position x(50)/3,y#,z#*sc#+object position z(50)/3
    next i
unlock vertexdata

control camera using arrowkeys 0,0.1,0.1
a#=wrapvalue(a#+mousemovex()/2)
cam#=wrapvalue(cam#+mousemovey()/2)
rotate camera cam#,a#,0
if leftkey() then move camera left 0.1
if rightkey() then move camera right 0.1

sync
loop
Posted: 15th Jan 2014 22:31
Nice!
I never thought about rotating the object while changing the vertex positions. And no trig required, so it's way easier for me.