January 26, 2021, 12:25:08 PM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
3D Graphics - Maths
»
[bb] Snap to grid movement by Zethrax [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Snap to grid movement by Zethrax [ 1+ years ago ] (Read 676 times)
BlitzBot
Jr. Member
Posts: 1
[bb] Snap to grid movement by Zethrax [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:39 AM »
Title :
Snap to grid movement
Author :
Zethrax
Posted :
1+ years ago
Description :
Demonstrates camerapicking a point on a grid and moving an object so that movement is snapped to the size of the grid cell
Code :
Code: BlitzBasic
Global
G_grid_cell_size# =
1.0
Graphics3D
800
,
600
,
0
,
2
Global
G_camera =
CreateCamera
(
)
CameraZoom
G_camera,
1.6
TurnEntity
G_camera,
90.0
,
0.0
,
0.0
MoveEntity
G_camera,
0.0
,
0.0
, -
20.0
Global
G_light =
CreateLight
(
)
Global
G_cube =
CreateCube
(
)
ScaleMesh
G_cube,
0.5
,
0.5
,
0.5
PositionMesh
G_cube,
0.5
,
0.5
,
0.5
UpdateNormals
G_cube
Global
G_grid = CreateGrid
(
)
EntityPickMode
G_grid,
2
Global
G_picked_entity
SetBuffer
BackBuffer
(
)
Repeat
G_picked_entity =
CameraPick
(
G_camera,
MouseX
(
)
,
MouseY
(
)
)
If
G_picked_entity
x# =
Floor
(
PickedX
(
)
/ G_grid_cell_size#
)
* G_grid_cell_size#
z# =
Floor
(
PickedZ
(
)
/ G_grid_cell_size#
)
* G_grid_cell_size#
PositionEntity
G_cube, x#,
PickedY
(
)
, z#
EndIf
UpdateWorld
RenderWorld
Flip
Delay
(
1
)
Until
KeyHit
(
1
)
End
Function
CreateGrid
(
)
; -- Create grid texture.
Local
i, x, y
Local
grid_2d_tex =
CreateTexture
(
256
,
256
,
11
)
SetBuffer
TextureBuffer
(
grid_2d_tex
)
For
i =
0
To
4
Rect
i, i,
256
- i - i,
256
- i - i,
False
Next
For
y =
5
To
250
For
x =
5
To
250
WritePixel
x, y,
0
Next
Next
;^^^^^^
; -- Create 2D grid.
Local
grid_2D =
CreatePlane
(
)
EntityTexture
grid_2D, grid_2d_tex
EntityFX
grid_2D,
9
;^^^^^^
Return
grid_2D
End Function
Comments :
none...
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
3D Graphics - Maths
»
[bb] Snap to grid movement by Zethrax [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal