Help

Blitz3D Forums/Blitz3D Programming/Help

Yue(Posted 2010) [#1]
hi, please someone kindly help me with this:

I need to put three cubes on the screen and mouse by lifting these boxes and put them elsewhere in the ground, something like when you play chess.

Please code as simple as possible.

A greeting.


Axel Wheeler(Posted 2010) [#2]
Well, CreateCube() is the simplest way to make a cube. Use the EntityColor() command to color it and ScaleEntity() to make it the size you need. Then PositionEntity() to put it where you want.

Keep in mind that CreateCube() creates a cube that is 2x2x2, so when using ScaleEntity() use half the size you really want it. Also remember that the lower half of the cube will be below the location you put it, so adjust the Y value accordingly.

Clicking and dragging in 3D is considerably more tricky than the above.

The "Pick" commands can help to identify the cube being clicked. They are: EntityPick(), LinePick(), CameraPick()

(I don't use these much myself so I can't tell you much more about them)

Then you will have to read the MouseX() and MouseY() values and somehow convert the 2D screen information they represent to a best guess at the 3D location. Again, a Pick command can help because after every Pick command is run you can get PickedX(), PickedY() and PickedZ(). The X and Z values would tell you where on the chessboard the mouse pointer was when the user clicked (or released).

These will also help:

MouseDown(1) detects a mouse button (left, I think) is currently being held down.
MouseHit(1) detects that it was hit since the last check.
MoveMouse() moves the mouse to a specified x and y position. You may need this at some point.

Check the Blitz3D documentation for these commands and good luck Yue!


Fintan(Posted 2010) [#3]
I don't know how exactly to lift something and put it down elsewhere, but I think I can point you in the right direction. Here's a simple bit of code that will show you how to lift an object by clicking on it and drop it back to the ground when the mouse is released:



The variables "e", "entitypicked", and "type_cube" are obviously declared previously in the code as well as the type, "cube".
The "entitypicked" variable is not actually the entity handle, but a set of seemingly random numbers unless it is changed using "NameEntity", but I won't get into that.

You might be able to move the cube by using some sort of mathematical process to detemine where the mouse is in the game, provided you are using an overhead view of a stationary grid similar to chess. You may also need to set the entitypickmode of everything in the scene to avoid an "enity does not exist" error. The above code will make sure that it is a cube with the "getentitytype" command before lifting it.

I hope this at least helps you get started.


Drak(Posted 2010) [#4]
I've come up with a relatively simple result I'm pleased with.

Because a mouse only moves in x and y axis, and we want to move the picked object in x, y, and z, I used the mousewheel to control the z axis.

Holding the RMB down while hanging on to an object will rotate it.

One thing you may notice is that as the object gets closer to the camera it moves noticably faster in the x and y axis, and vise versa. Oh, and there is also collisions between cubes so they won't pass through each other, and will stack, etc. They also won't fall through the ground, as gravity effects the cubes not held.

Here is the code:




Axel Wheeler(Posted 2010) [#5]
Great work Drak! I've modded it a bit for a different flavor. Yue, normally I don't think people would actually write code for you like Drak did, so don't get too used to it! :-)

Note: I'm trying to hide the mouse pointer while an object is picked, but it isn't working. Oh well.




Yue(Posted 2010) [#6]
hello friends, thanks for your help, because my English is very bad, well the thing is I'm learning and the best way is to examine small codes that experienced users like you can write on the subject.


A greeting.


Drak(Posted 2010) [#7]
Well I love a challenge and I don't mind helping out. The way I learned b3d was by reading code. To me it's the fastest way to learn, so long as the recipient learns why what happens, happens.


Fintan(Posted 2010) [#8]
Wow, Drak!

Okay, Yue. Disregard my code that I posted earlier. It was just the code that I used when I was first learning about picks. Drak's code really is the way to go and it's very easy to understand, too.


Drak(Posted 2010) [#9]
Changing this:

For s.shape=Each shape
		PositionEntity(s\shadow,EntityX(s\mesh),0,EntityZ(s\mesh))
Next


To this:
For s.shape=Each shape
		PositionEntity(s\shadow,EntityX(s\mesh),0,EntityZ(s\mesh))
		RotateEntity s\shadow,0,EntityYaw(s\mesh),0
Next

allows the shadow to rotate with the object.


Axel Wheeler(Posted 2010) [#10]

allows the shadow to rotate with the object.


Oops ... it's the little things that get ya! :-)