Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Ayumi), 1,170 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Snapping to a grid #238084
11/24/08 19:10
11/24/08 19:10
Joined: Mar 2004
Posts: 71
Scotland
westray Offline OP
Junior Member
westray  Offline OP
Junior Member

Joined: Mar 2004
Posts: 71
Scotland
How would you snap to a grid using code.I am making a Rubicks cube game and after rotating and moving you can see positional anomallys with individual cubes.How would you make them snap to a 3d grid 21x21x21

Re: Snapping to a grid [Re: westray] #238090
11/24/08 19:47
11/24/08 19:47
Joined: May 2008
Posts: 301
Oxy Offline
Senior Member
Oxy  Offline
Senior Member

Joined: May 2008
Posts: 301
just calculate a "hidden" position value (your current position value),
and then put the entity every frame to
an absolute value ( something like pos_x = int(pos_x_curr/21)*21

Re: Snapping to a grid [Re: Oxy] #238095
11/24/08 20:23
11/24/08 20:23
Joined: Mar 2003
Posts: 3,010
analysis paralysis
NITRO777 Offline
Expert
NITRO777  Offline
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
Where TileSize is the size of each square (say 64 quants * 64 quants)

Code:
function SnapIt()

{

        if (my.x < 0)

        {

                my.x = TileSize * (int(my.x / TileSize)) - (TileSize / 2);

        }

        if (my.x >= 0)

        {

                my.x = TileSize * (int(my.x / TileSize)) + (TileSize / 2);

        }

        if (my.y < 0)

        {

                my.y = TileSize * (int(my.y / TileSize)) - (TileSize / 2);

        }

        if (my.y >= 0)

        {

                my.y = TileSize * (int(my.y / TileSize)) + (TileSize / 2);

        }

}


As you can see it is pretty simple, what I would suggest is go to the acknex resources pages (to the tutorials section) and download a tutorial called "3d tile-based game programming", this will help you set up you mouse and constrain the grid to whatever sides of the cube you want.

Re: Snapping to a grid [Re: NITRO777] #238152
11/25/08 08:39
11/25/08 08:39
Joined: May 2008
Posts: 301
Oxy Offline
Senior Member
Oxy  Offline
Senior Member

Joined: May 2008
Posts: 301
Beware!
This code works, but what I guessis, that he wants is just the
entities be displayed as aligned on a grid.
You basically force the whole entity to the grid,
erasing inbetweensteps wich might be needed still for
"internal" calculations.

the actual position should be saved to a "hidden" position value,
and just be snapped to the grid for displaying it.

Re: Snapping to a grid [Re: Oxy] #238180
11/25/08 12:27
11/25/08 12:27
Joined: Mar 2003
Posts: 3,010
analysis paralysis
NITRO777 Offline
Expert
NITRO777  Offline
Expert

Joined: Mar 2003
Posts: 3,010
analysis paralysis
Quote:
erasing inbetweensteps wich might be needed still for
"internal" calculations.
No. This function would be called from within a mouse while loop with a wait instruction for calculating other processes. You need to see the rest of the code, (which I referenced in my previous post) in order to understand how it all works.

The SnapIt() function is called inside a while loop for an action which is placed upon the square sprite used to frame the movement of the mouse on the grid.

Code:
action Square

{

        my.oriented = on;

        my.facing = off;

        my.decal = off;

        

        my.pan = 0;

        my.roll = 0;

        my.tilt = 90;

        

        while(1)

        {

                Mouse3D();

                vec_set(my.x, target);

                my.z = 0.5;
                
                SnapIt();

                wait(1);

        }

}


This action also references a Mouse3d() function:

Code:
function Mouse3D()

{

        var vector1;

        var vector2;

        

        vector1.x = mouse_pos.x;

        vector1.y = mouse_pos.y;

        vector1.z = 5;

        

        vector2.x = mouse_pos.x;

        vector2.y = mouse_pos.y;

        vector2.z = 5000;

        

        vec_for_screen(vector1, camera);

        vec_for_screen(vector2, camera);

        

        trace(vector1, vector2);

}


The exact orientation of the frame will be different because you have a rubiks cube which you can rotate in space.

Other than that Im not sure what "internal calculations" you are talking about and/or why this code makes it impossible for them? grin

Last edited by TriNitroToluene; 11/25/08 12:47.
Re: Snapping to a grid [Re: NITRO777] #238213
11/25/08 17:39
11/25/08 17:39
Joined: Jul 2007
Posts: 959
nl
F
flits Offline
User
flits  Offline
User
F

Joined: Jul 2007
Posts: 959
nl
why you dont use sign

Code:
function SnapIt()
{
	my.x = TileSize * (int(my.x / TileSize)) + (TileSize / 2)*sign(my.x);
	my.y = TileSize * (int(my.y / TileSize)) + (TileSize / 2)*sign(my.y);
}




"empty"
Re: Snapping to a grid [Re: flits] #238389
11/27/08 00:15
11/27/08 00:15
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
what exactly do you want, it's probably been answered, but are you just displaying a 2d view of one side of a cube, or selecting a column or row of one cube? or selecting the above but in a 3d view, and if it is similarly displaying a 3d view, how do you want to display which axis will be rotated?


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1