Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (754) Games in Android Showcase (229) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Real 4D World Rendering  (Read 13441 times) 0 Members and 2 Guests are viewing this topic.
DQQAYME

Junior Devvie

Medals: 1
Projects: 1

 « Posted 2013-05-16 03:41:57 »

# What is 4 Dimension and how program it =)

Let's start simple.

## 1st dimension:

Imagine a corridor.
It's simply a line, you can look into 2 directions: forwards or backwards.
In a program this would be a 1-dimensional array, i.e.
 1 int[x]

## 2nd dimension:

Imagine a corridor that has doors to rooms.
The line we had before can now have many more lines (or corridors / rooms) along the walls of the corridor.
You see can now look into 4 directions: forwards, backwards, left, right.
In a program this would be a 2-dimensional array (an array of arrays):
 1 int[x][z]

For rotating we use one defining angle and sin and cos:

• Sin = first and second direction (forwards, backwards)
• Cos = third and fourth direction (left, right)

In different angles we move into different directions:

• angle 90°: x+
• angle 270°: x-
• angle 0°: z+
• angle 180°: z-

## 3rd dimension:

Imagine a building, which has floors, which have corridors with rooms and doors to them.
You can look into 6 directions: forwards, backwards, left, right, top and down.
In a program this would be a 3-dimensional array:
 1 int[x][z][y]

For rotating we use 2 defining angles:
Sinus for up and down and
Cos for the XZ plane.

## Dimension Plane

Every new dimension adds a new Plane, which has 2 sides.
We only see a particular direction, if we look into it's angle.
To show the effect, we give those directions (sides) different colors.
If you look diagonal in 3D by 2 angles, we can see 3 sides:
Green Y, Blue Z, Red X:

If we look diagonal with only 1 angle, we can only see 2 sides:
Y Angle = 0;

This is how it looks like, when we see 2 X sides, 1 Z side and 2 Y sides:

Every new dimension adds 2 planar sides on one positive dimension and on one negative dimension (+/-).
They may have any color or texture.
Every new plane after 2 planes adds a new rotation axis, which is able to render it's own 2 sides and the 2 previous planars.
In 3D the angle 0 and 180 look along the Y-axis, and 90 and 270 along the XZ plane.

## 4th dimension

Imagine a group of buildings.
You can look into 8 directions: forwards, backwards, left, right, top, down, D+ and D-.
We call the new dimension D.
In a program that is a 4-dimensional array:
 1 int[x][z][y][d]

So we now have 2 new planes on which we can travel or look along.
If it's possible to cast a ray in 1d, 2d and 3d, it should be able to move in 4d!
And it is!
If we have a 4x4 matrix we can easy calculate Ray position with it,
but how to render it?
Let's use raycasting.
Every pixel casts a ray, which sets the color for a pixel to the color of the obstacle it collides with.

The maths:
To cast a ray, we have to properly normalize it:

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20 //2D normalizelength = sqrt(x * x + y * y)invlen = 1 / lengthx *= lengthy *= length//3Dlength = sqrt(x * x + y * y + z * z)invlen = 1 / lengthx *= lengthy *= lengthz *= length//4Dlength = sqrt(x * x + y * y + z * z + d * d)invlen = 1 / lengthx *= lengthy *= lengthz *= lengthd *= length

Moves In 3D it looks like here we have same XZ Position but We moves Top or bottom on Y plane
And Words Changed.

4D matrix where
In one picture we don't have a floor and in the second we have it.
We now moved in the D plane, but the XYZ position is still the same.
And Words Changed.

It's even more interesting to see how the image will be if we make the D angle diagonal and see all 4 planes:

Purpl Side is 4D plane color
It can be explain like
Rays that colis First World Out Of Draw Range Have Black color (1 world don’t have floor)
Rays that colis second World Have Grean color(2 world  have floor)
Rays that colis Plane Side have purple color.
(purple D plane can have same Hole like Any other Plane)
I Have img this =)
Ray Progression 2D

Cube in 4D have 4 Planes every Plane with own color.

## Ray Progression 4D

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16 y=0, z=2, x=2, d=1y=0, z=3, x=2, d=1y=0, z=3, x=3, d=1y=-1, z=3, x=3, d=1// blacky=1, z=2, x=3, d=1y=1, z=3, x=3, d=1y=0, z=3, x=3, d=1y=0, z=3, x=4, d=1y=0, z=3, x=4, d=2// Purply=1, z=2, x=3, d=1y=1, z=3, x=3, d=1y=1, z=3, x=4, d=1y=1, z=3, x=4, d=2y=0, z=3, x=4, d=2// Grean

Every new plane add Sin self and Cos prev Planes
Camera ray Projection 3D
 1  2  3  4 ray.y += Dist * sin_Y;            ray.x += Dist * sin_X * cos_Y;      ray.z += -Dist * cos_X * cos_Y;

Camera ray Projection 4D
 1  2  3  4  5 pos.d += Dist * sin_D;      pos.y += Dist * sin_Y * cos_D;            pos.x += Dist * sin_X * cos_Y * cos_D;      pos.z += -Dist * cos_X * cos_Y * cos_D;

## 4D matrix Img

We have int[2][2][2][2]
So We have two 3D Matrix
4th Dimension give ability to Ray travel between this two 3D matrix =)

If we in int[X][Y][Z][0] we in first 3D matrix
If we in int[X][Y][Z][1] we in second 3D matrix
All simple )

If we have matrix array like in minecraft in 4D it will be 4D cube

Every Cube In First 3D matrix have Side To second 3D matrix,
So we have 2 * 2 * 2 = 8 sides(Tunnels) between two 3D matrix =)

Same as with 3D we can travel only on Free place block (Air)
So Even in 4D you only can move through the Air {Air == 0, Block  == 1}
[1][2][3]    D[2] = 0
[1][2][3]    D[1] = 0
[1][2][3]    D[0] = 1

We in [1][2][3]    D[1]

Ray can move to [1][2][3] D[2] ,
but can't move to [1][2][3] D[0]  we will see wall, it can be One Color Or Texture like side in Cube

Try it yourself and make a raycasting renderer and add a 4th vector component to the ray.
Is the 4 the maximum number of possible dimensions?
No, it could be any number of dimensions. 5D, 6D or even 111D =)

More img

HeroesGraveDev

JGO Kernel

Medals: 382
Projects: 11
Exp: 4 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

 « Reply #1 - Posted 2013-05-16 04:05:01 »

The fourth dimension is usually represented by w.

Also, this isn't a real rendering of a 4D world. It is simply a projection of 4D space into 3D space (which in turn is projected into 2D space), when actually it should be projected straight into 2D space. Of course, we can't see 4D, so it is impossible to have 'Real' 4D rendering. You can't solve that, and it's just me nit-picking, but the title is slightly incorrect.

Thirdly, your transformation of the w*-axis is slightly incorrect. The fourth dimension should travel along the direction you look in xyz space, ie: a 4D plane is perpendicular to the ray cast from the camera. Your transformation looks a bit warped, but maybe it's just the screenshot.

It would also be nice if you could fix the typos. Sometimes it can get a bit confusing and may have lead me to misunderstand some of your points.

* titled D in the article, see my first point.

DQQAYME

Junior Devvie

Medals: 1
Projects: 1

 « Reply #2 - Posted 2013-05-16 10:01:11 »

Quote from:  HeroesGraveDev
The fourth dimension is usually represented by w

Quote from:  HeroesGraveDev
Also, this isn't a real rendering of a 4D world. It is simply a projection of 4D space into 3D space (which in turn is projected into 2D space), when actually it should be projected straight into 2D space. Of course, we can't see 4D, so it is impossible to have 'Real' 4D rendering. You can't solve that, and it's just me nit-picking, but the title is slightly incorrect.

Okay same as you can't see 3D dimension on 2D screen its impossible XD

4D Projection with FOV
22 On D
45 On XZ
45 On Y

Quote from:  HeroesGraveDev
Thirdly, your transformation of the w*-axis is slightly incorrect. The fourth dimension should travel along the direction you look in xyz space, ie: a 4D plane is perpendicular to the ray cast from the camera. Your transformation looks a bit warped, but maybe it's just the screenshot.

Yes you right XYZ perpendicular D that’s why we use Cos angel D for XYZ and Sin angel D For D. =)

matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #3 - Posted 2013-05-16 14:37:42 »

I tried to correct your typos and grammar errors in your article, it's such a high level in terms of math and understanding, but such a low level in English...
I'm not native English speaker myself, so it's not 100% right

I don't know if it's even possible to modify Article posts, but here it is:

# What is the 4th dimension and how to program it =)

Let's start simple.

## 1st dimension:

Imagine a corridor.
It's simply a line, you can look into 2 directions: forwards or backwards.
In a program this would be a 1-dimensional array, i.e.
 int[x]

## 2nd dimension:

Imagine a corridor that has doors to rooms.
The line we had before can now have many more lines (or corridors / rooms) along the walls of the corridor.
You see can now look into 4 directions: forwards, backwards, left, right.
In a program this would be a 2-dimensional array (an array of arrays):
 int[x][z]

For rotating we use one defining angle and sin and cos:
• Sin = first and second direction (forwards, backwards)
• Cos = third and fourth direction (left, right)

In different angles we move into different directions:
• angle 90°: x+
• angle 180°: x-
• angle 0°: z+ (<- Both this and the one below were "-" before)
• angle 90°: z-

## 3rd dimension:

Imagine a building, which has floors, which have corridors with rooms and doors to them.
You can look into 6 directions: forwards, backwards, left, right, top and down.
In a program this would be a 3-dimensional array:
 int[x][z][y]

For rotating we use 2 defining angles:
Sinus for up and down and
Cos for the XZ plane.

## More dimensions

Every new dimension adds a new Plane, which has 2 sides.
We only see a particular direction, if we look into it's angle.
To show the effect, we give those directions (sides) different colors.
If you look diagonal in 3D by 2 angles, we can see 3 sides:
Green Y, Blue Z, Red X:

If we look diagonal with only 1 angle, we can only see 2 sides:

This is how it looks like, when we see 2 X sides, 1 Z side and 2 Y sides:

Every new dimension adds 2 planar sides on one positive dimension and on one negative dimension (+/-).
They may have any color or texture.
Every new plane after 2 planes adds a new rotation axis, which is able to render it's own 2 sides and the 2 previous planars.
In 3D the angle 0 and 180 look along the Y-axis, and 90 and 270 along the XZ plane.

## 4th dimension

Imagine a group of buildings.
You can look into 8 directions: forwards, backwards, left, right, top, down, D+ and D-.
We call the new dimension D.
In a program that is a 4-dimensional array:
 int[x][z][y][d]

So we now have 2 new planes on which we can travel or look along.
If it's possible to cast a ray in 1d, 2d and 3d, it should be able to move in 4d!
And it is!
If we have a 4x4 matrix we can easy calculate Ray position with it,
but how to render it?
Let's use raycasting.
Every pixel casts a ray, which sets the color for a pixel to the color of the obstacle it collides with.

The maths:
To cast a ray, we have to properly normalize it:

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20 // 2D normalizelength = sqrt(x * x + y * y)invlen = 1 / lengthx *= lengthy *= length// 3Dlength = sqrt(x * x + y * y + z * z)invlen = 1 / lengthx *= lengthy *= lengthz *= length// 4Dlength = sqrt(x * x + y * y + z * z + d * d)invlen = 1 / lengthx *= lengthy *= lengthz *= lengthd *= length

'Moving in 3d looks like having the same XZ position, but we move up or down on the y axis.
And the other way around' (quotes for a reason here )

'4D matrix:
In one picture we don't have a floor and in the second we have it.
We now moved in the D plane, but the XYZ position is still the same.
And the other way around.'

It's even more interesting to see how the image will be if we make the D angle diagonal and see all 4 planes:

The purple plane is the 4th plane.
This can be explained like that:
Rays that collide in the first picture (3rd last picture) are out of draw range and have a black color (it doesn't have a floor).
Rays that collide in the second last picture have a green color (second world has a floor).
Rays that collide with the Plane side have a purple color.
(the purple D plane can have the same holes like any other plane)

So I have this Image:

### Ray progression

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31 float y=0, z=2, x=2, d=1float y=0, z=3, x=2, d=1float y=0, z=3, x=3, d=1float y=-1, z=3, x=3, d=1// blackfloat y=1, z=2, x=3, d=1float y=1, z=3, x=3, d=1float y=0, z=3, x=3, d=1float y=0, z=3, x=4, d=1float y=0, z=3, x=4, d=2// Purplefloat y=1, z=2, x=3, d=1float y=1, z=3, x=3, d=1float y=1, z=3, x=4, d=1float y=1, z=3, x=4, d=2float y=0, z=3, x=4, d=2// GreenEvery new plane adds a sin for itself and a cos for previous planesCamera ray Projection in 3D      ray.y += 1 * sin_Y;            ray.x += 1 * sin_X * cos_Y;      ray.z += -1 * cos_X * cos_Y;Camera ray Projection in 4D      pos.d += Dist * sin_D;      pos.y += Dist * sin_Y * cos_D;            pos.x += Dist * sin_X * cos_Y * cos_D;      pos.z += -Dist * cos_X * cos_Y * cos_D;

Try it yourself and make a raycasting renderer and add a 4th vector component to the ray.
Is the 4 the maximum number of possible dimensions?
No, it could be any number of dimensions. 5D, 6D or even 111D =)

(couldn't put this into quotes...)

Hope this helps some people.
I've put some sentences into quotes ('), because I really couldn't understand what you wanted to say. Other than that, a cool article.

Also, your strange image host seems to make a lot of money with... stuff... (click on images )

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
DQQAYME

Junior Devvie

Medals: 1
Projects: 1

 « Reply #4 - Posted 2013-05-16 15:51:57 »

Quote from:  matheus23
I tried to correct your typos and grammar errors in your article
Big Ty I Try fix all Now;)

Quote from:  matheus23
Also, your strange image host seems to make a lot of money with... stuff... (click on images Wink )
Don’t make money for me at all, I take first hosting that find in Google.
If some one want I can change img hosting.

theagentd
 « Reply #5 - Posted 2013-05-16 19:26:48 »

Myomyomyo.
DQQAYME

Junior Devvie

Medals: 1
Projects: 1

 « Reply #6 - Posted 2013-05-16 20:35:11 »

Quote from:  theagentd
4D? Just throw in some smell emitters and spray some water in the players' face.
I am not kickstarter I don’t ask ppl pay me or do something for me =)
I have knowledge that I tested (in my opinion on this moment I this they right)
I share them.

Take them or throw them away, In any case I accept your choice.
Cheers. XD

DQQAYME

Junior Devvie

Medals: 1
Projects: 1

 « Reply #7 - Posted 2013-05-16 20:40:14 »

sorry wrong browser have double post

theagentd
 « Reply #8 - Posted 2013-05-16 23:56:39 »

I was joking how the "4D" label has been corrupted by stupid people who think smell is the same as adding an extra dimension. >___>

Myomyomyo.
HeroesGraveDev

JGO Kernel

Medals: 382
Projects: 11
Exp: 4 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

 « Reply #9 - Posted 2013-05-17 04:54:42 »

@theagentd: I would have appreciated that if this weren't an article.

Have an imaginary virtual medal!

matheus23

JGO Kernel

Medals: 138
Projects: 3

You think about my Avatar right now!

 « Reply #10 - Posted 2013-05-17 14:46:53 »

@DQQAYME:
If you wonder how to make those awesome-looking headers (the blue font), use headers:

The result is:

See my:
My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
DQQAYME

Junior Devvie

Medals: 1
Projects: 1

 « Reply #11 - Posted 2013-05-17 18:16:55 »

Quote from:  matheus23
If you wonder how to make those awesome-looking headers (the blue font), use headers:
=)
Add New 4D Img (Cube) Matrix

int[2][2][2][2] = Two matrix int[2][2][2] - All simple, Any programmer know about that =)

DQQAYME

Junior Devvie

Medals: 1
Projects: 1

 « Reply #12 - Posted 2013-05-18 12:06:37 »

p.s Camera Movement in 4D really hard understand Visual , even for me who know and understand all his maths
Technical its simple if vision Ray collis wall - you see wall,
you see wall - you know you can’t go there.

But its really hard predict next position where you will be,
its something like camera strafe in 3d(3 Vectors, base strafe in 3d game is 2d - you move on ZX Plane)

HeroesGraveDev

JGO Kernel

Medals: 382
Projects: 11
Exp: 4 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

 « Reply #13 - Posted 2013-05-18 19:24:54 »

Just make the player a 4D object, then add controls for movement in the fourth dimension.

Collision can be done with just a 4D AABB

DQQAYME

Junior Devvie

Medals: 1
Projects: 1

 « Reply #14 - Posted 2013-05-19 12:40:02 »

Yes, now you see that 4D is easy.
AABB do later, Have old AABB collis from World of Change project, but hi slow,
I want do new AABB ray cast collision
Don’t want write crap code XD

Roquen

JGO Kernel

Medals: 517

 « Reply #15 - Posted 2013-05-20 12:30:17 »

Complete unrelated, but Java doesn't have concrete nor flattened multidimensional arrays, so type[][][] with fixed lengths should be avoided (except in cases where your using the fact to quickly swap rows...for instance).
Pages: [1]
 ignore  |  Print

 DesertCoockie (36 views) 2018-05-13 18:23:11 nelsongames (80 views) 2018-04-24 18:15:36 nelsongames (73 views) 2018-04-24 18:14:32 ivj94 (755 views) 2018-03-24 14:47:39 ivj94 (85 views) 2018-03-24 14:46:31 ivj94 (626 views) 2018-03-24 14:43:53 Solater (101 views) 2018-03-17 05:04:08 nelsongames (182 views) 2018-03-05 17:56:34 Gornova (408 views) 2018-03-02 22:15:33 buddyBro (1068 views) 2018-02-28 16:59:18
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org