Jump to content


Photo

d3d_transform_add_rotation_y and custom position


  • Please log in to reply
1 reply to this topic

#1 ck2k

ck2k

    GMC Member

  • New Member
  • 68 posts

Posted 13 October 2010 - 11:37 AM

Well, I've written a script that draws a little a tree:

/*
scr_tree()
argument0 = x
argument1 = y
argument2 = z

*/

OX = argument0
OY = argument1
OZ = argument2

d3d_draw_cylinder(OX-15,OY-15,OZ,OX+15,OY+15,OZ+80,background_get_texture(tex_palme),1,5,true,8)
d3d_transform_add_rotation_y(330)
d3d_draw_cylinder(OX-15-75,OY-15,OZ+220,OX+15-75,OY+15,OZ+275,background_get_texture(tex_palme),1,5,true,8)
d3d_transform_add_rotation_y(-330)
d3d_draw_ellipsoid(OX-90+30,OY-80,OZ+100,OX+90+30,OY+80,OZ+175,background_get_texture(tex_blatt),2,2,8)
d3d_transform_add_rotation_y(270)
d3d_draw_cylinder(OX-5-400,OY-5,OZ+325,OX+5-400,OY+5,OZ+375,background_get_texture(tex_palme),1,5,true,8)
d3d_transform_add_rotation_y(-25)
d3d_draw_cylinder(OX-5-550,OY-5,OZ+300,OX+5-550,OY+5,OZ+330,background_get_texture(tex_palme),1,5,true,8)
d3d_transform_add_rotation_y(-245)
d3d_draw_ellipsoid(OX-45+80,OY-40,OZ+35,OX+45+80,OY+40,OZ+75,background_get_texture(tex_blatt),2,2,8)

As you ceen see i used d3d_transform_add_rotation to draw some branches but, and as long z = 0 it works finde, but as soon z is different form 0 the tree breaks.. (because the axes rotate too and i have to use a different z that is relativ to the rotation, but i've no idea how to achieve this)

I hope you can understand what i mean in spite of my crappy english :o

Can anyone tell me how to calculate that new relativ z?
or a function that can help me?
Thank you :)

Edited by ck2k, 13 October 2010 - 11:44 AM.

  • 0

#2 slayer 64

slayer 64

    GMC Member

  • GMC Member
  • 3300 posts
  • Version:GM8.1

Posted 15 October 2010 - 11:43 PM

when you use transformations; everything drawn after is rotated, scaled, or translated depending on what you defined. the transformation stack is nothing to begin with. you should always set the transformation to nothing using d3d_transform_set_identity() when you're done so everything else in your game isn't drawn crazy.

d3d_transform_set_identity() will set he transformation stack to nothing.
d3d_transform_set_something() will clear the transformation stack and set the transformation to something.
d3d_transform_add_something() will add transformations onto the stack.

when something is drawn, it will be transformed using the information on the stack.

the easiest way to know where cylinders will be transformed is by visualizing them without any transformations and executing each transformation on it. example: a cylinder, rotate x 90, rotate z 45, then translate to a position x y z.

your tree limbs need to be translated after they're rotated.

this should draw your tree, it might not look the same because the cylinders are drawn in the wrong place before the transformations are applied.
/*
scr_tree()
argument0 = x
argument1 = y
argument2 = z

*/

var ox,oy,oz,t;

ox = argument0
oy = argument1
oz = argument2
t=background_get_texture(tex_palme)
j=background_get_texture(tex_blatt)

d3d_draw_cylinder(ox-15,oy-15,oz,ox+15,oy+15,oz+80,t,1,5,true,8)

d3d_transform_add_rotation_y(330)
d3d_transform_add_translation(ox,oy,oz)
d3d_draw_cylinder(-15-75,-15,+220,+15-75,+15,+275,t,1,5,true,8)

d3d_transform_set_rotation_y(-330)
d3d_transform_add_translation(ox,oy,oz)
d3d_draw_ellipsoid(-90+30,-80,+100,+90+30,+80,+175,j,2,2,8)

d3d_transform_set_rotation_y(270)
d3d_transform_add_translation(ox,oy,oz)
d3d_draw_cylinder(-5-400,-5,+325,+5-400,+5,+375,t,1,5,true,8)

d3d_transform_set_rotation_y(-25)
d3d_transform_add_translation(ox,oy,oz)
d3d_draw_cylinder(-5-550,-5,+300,+5-550,+5,+330,t,1,5,true,8)

d3d_transform_set_rotation_y(-245)
d3d_transform_add_translation(ox,oy,oz)
d3d_draw_ellipsoid(-45+80,-40,+35,+45+80,+40,+75,j,2,2,8)

d3d_transform_set_identity()

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users