# Rotate object in superengine for ruby

**URL:** <https://www.ruby-forum.com/t/rotate-object-in-superengine-for-ruby/164649>\
**Category:** Ruby\
**Created:** [April 3, 2009, 5:14pm UTC](https://www.ruby-forum.com/t/rotate-object-in-superengine-for-ruby/164649 "2009-04-03T17:14:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![geasy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/45deac/32.png) [@geasy](https://www.ruby-forum.com/u/geasy)\
**Post date:** [April 3, 2009, 5:14pm UTC](https://www.ruby-forum.com/t/rotate-object-in-superengine-for-ruby/164649/1 "2009-04-03T17:14:38Z")

</div>

Hi

I need help. I use a ruby superengine software to virtualize 3D object.  
This software use a ruby scripts. In this virtualizer I need rotate  
object. And aj dont know how to do it. For example i give to this page  
example of moveobject and part of my definition of rotateobject. For  
answers thx.

examples :

def MoveObject(object,x,y,z,speed=1)

pdx = (object.px - x).abs;  
pdy = (object.py - y).abs;  
pdz = (object.pz - z).abs;  
if(pdx\<=0.001 && pdy\<=0.001 && pdz\<=0.001) then return true end

dirx = 1.0;  
diry = 1.0;  
dirz = 1.0;

dx = x - object.px;  
dy = y - object.py;  
dz = z - object.pz;

if(dx\<0.0) then dirx = -1.0 end  
if(dy\<0.0) then diry = -1.0 end  
if(dz\<0.0) then dirz = -1.0 end

deltax = speed \* dirx \* $FRAMETIME;  
deltay = speed \* diry \* $FRAMETIME;  
deltaz = speed \* dirz \* $FRAMETIME;

max = dx.abs;  
if(dy.abs \> max) then max = dy.abs end  
if(dz.abs \> max) then max = dz.abs end

if(max == dx.abs) then  
deltay = deltay \* (dy.abs/dx.abs);  
deltaz = deltaz \* (dz.abs/dx.abs);  
elsif(max == dy.abs) then  
deltax = deltax \* (dx.abs/dy.abs);  
deltaz = deltaz \* (dz.abs/dy.abs);  
elsif(max == dz.abs) then  
deltax = deltax \* (dx.abs/dz.abs);  
deltay = deltay \* (dy.abs/dz.abs);  
end

object.px = object.px + deltax;  
object.py = object.py + deltay;  
object.pz = object.pz + deltaz;

if(dirx\<0.0) then  
if(object.px \<= x) then object.px = x end  
else  
if(object.px \>= x) then object.px = x end  
end

if(diry\<0.0) then  
if(object.py \<= y) then object.py = y end  
else  
if(object.py \>= y) then object.py = y end  
end

if(dirz\<0.0) then  
if(object.pz \<= z) then object.pz = z end  
else  
if(object.pz \>= z) then object.pz = z end  
end

finished = false;  
pdx = (object.px - x).abs;  
pdy = (object.py - y).abs;  
pdz = (object.pz - z).abs;  
if(pdx\<=0.001 && pdy\<=0.001 && pdz\<=0.001) then return true  
else return false end  
end

This script is OK and its fully function

now rotate object

def RotateObject(object,dx,dy,dz,rotation\_time=1,speed=1)

```
    dirx = 1.0;

```

diry = 1.0;  
dirz = 1.0;

if(dx\<0.0) then dirx = -1.0 end  
if(dy\<0.0) then diry = -1.0 end  
if(dz\<0.0) then dirz = -1.0 end

a=dx/(rotation\_time);

deltax = speed \* dirx \* $FRAMETIME;  
deltay = speed \* diry \* $FRAMETIME;  
deltaz = speed \* dirz \* $FRAMETIME;

## Rotation angle

$angle = $angle + ($FRAMETIME/16.0)\*360.0;

## Are we about to change model?

if($angle \> $max\_rotation) then  
$angle = 0;  
$modelID = $modelID + 1;  
end

## Looping

if($modelID \> 5) then  
$modelID = 0;  
end

## Now we set rotation to each model

$gallon\_small\_finished.oz = $angle;  
end  
And this script has no errors but do nothing ☹
