Posted: 20th Jul 2003 15:55
This snippet uses the new U5 Pick Object and Pick Screen commands, to make an easier to understand matrix height editor.

Basically a cube is created and positioned at each point on the matrix. You then click and drag to move each point around.

This method works OK for matrixes of up to 20x20 tiles. Above that, it gets slow because of the sheer number of objects created. Therefore you could implement a simple function to only show the objects nearest the mouse.

Note that PICK OBJECT still picks hidden objects.

For users of the first U5 beta, because of the SET MATRIX HEIGHT inversion bug, you'll need to comment out the line which sets the matrix height and uncomment out the other line above it (which is a workaround)
Posted: 20th Jul 2003 18:11
Nice code, I have posted a little alteration to it. Instead of testing lots of objects all at once, i test a single object that is being positioned all over the matrix. It appears to work quicker for large matrices.
Posted: 20th Jul 2003 18:54
Thanks - I was considering possible improvements but you've done it for me

Your version is better, but to get good accuracy, you need to make the object smaller (eg size 1)

A very slightly tweaked version attached.

+ Code Snippet
sync on: sync rate 0

type MatrixTile
  xtile
  ztile
endtype

tilecountx=25
tilecountz=25
mxwidth=100
mxheight=100
totalcubes =  (tilecountx+1)*(tilecountz+1)

MxPoint as MatrixTile
make matrix 1,mxwidth,mxheight,tilecountx,tilecountz
position matrix 1,0,0,0

`Create a cube for each point on the matrix
make object cube 1,1
hide object 1
space#=mxwidth/tilecountx

xrotate camera 0

do
   if mouseclick()=0 or pickobj=0
      `find out which matrix tile it is picking if at all
      for z=0 to tilecountz
         for x=0 to tilecountx
            position object 1, (x*space#), get matrix height(1,x,z) ,(z*space#)
            pickobj = Pick Object(MouseX(),MouseY(),1,1)
            if pickobj=1
               MxPoint.xtile=x
               MxPoint.ztile=z
            endif
            if pickobj=1 then exit
         next x
         if pickobj=1 then exit
      next z
   endif

   if mouseclick()=1 and pickobj=1
      `Get the distance between camera and object in x and z axis
      CamDist# = Distance3D(Camera Position X(),0,Camera Position Z(),Object Position X(1),0,Object Position Z(1))

      `Convert the mousex / mousey position into a new Y co-ord in World3D
         Pick Screen MouseX(),MouseY(),CamDist#
      `Add the world Y to the camera Y given by Get Pick Vector()
         newy# = Get Pick Vector Y()+Camera Position Y()
         Position Object 1,Object Position X(1),newy#,Object Position Z(1)
         `Adjust the matrix tile height

         `There is a bug in the U5 beta where matrix height is inversed
        Set Matrix Height 1,MxPoint.xtile, MxPoint.ztile,-Object Position Y(1)

         `Use this line below instead when the bug is fixed
         `Set Matrix Height 1,MxPoint(pickobj).xtile,MxPoint(pickobj).ztile,Object Position Y(pickobj)

         Update Matrix 1
   endif


   Control Camera Using Arrowkeys 0,0.1,0.1
   if inkey$()="a" then Position Camera Camera Position X(),Camera Position Y()+0.1,Camera Position Z()
   if inkey$()="z" then Position Camera Camera Position X(),Camera Position Y()-0.1,Camera Position Z()
   text 20,40,str$(pickobj)
   text 20,20,str$(screen fps())
   sync
loop

function Distance3D(x1#,y1#,z1#,x2#,y2#,z2#)
   distx#=x2#-x1#
   disty#=y2#-y1#
   distz#=z2#-z1#
   result#=Sqrt(abs(distx#*distx#)+abs(disty#*disty#)+abs(distz#*distz#))
endfunction result#
Posted: 20th Jul 2003 19:06
There is also a problem when working out space#, since its doing interger division it causes problems when you increase the tilecount variables. Though it is an easy fix:-

+ Code Snippet
space#=(mxwidth*1.0)/(tilecountx*1.0)


The new pick commands are great.
Posted: 25th Jul 2003 0:35
"could not determine parameter of Pick Object(MouseX(),MouseY(),1,1) at line 30"

...?
Posted: 25th Jul 2003 0:52
HZence - obviously these commands will not work until Update 5 comes out!!!!

Some people like Rob K and haggisman get beta versions to play with and are the guinea pigs for testing purposes.
Posted: 25th Jul 2003 1:02
cool code rob
Posted: 25th Jul 2003 7:28
oh i didn't know that.
Posted: 25th Jul 2003 15:07
@HZence

I did put "U5" in the title
Posted: 25th Jul 2003 17:06
But you know some people cant read...
Posted: 26th Jul 2003 0:33
Like me I can't read ... Or write
I did the same thing :p
Any ideas when the final version will be out? Hopefully won't be long seeing as the Beta's out now.