# Real 4D World Rendering

[h1]What is 4 Dimension and how program it =)[/h1]
Let’s start simple.

[h2]1st dimension:[/h2]
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]
``````

[h2]2nd dimension:[/h2]
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 270°: x-
• angle 0°: z+
• angle 180°: z-

[h2]3rd dimension:[/h2]
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.

[h2]Dimension Plane[/h2]

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:

http://s21.postimg.org/qphh3hsqr/img1.png

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

http://s12.postimg.org/i5yewiopl/img.jpg

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

http://s21.postimg.org/5rbb5esw3/img0.png

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.

[h2]4th dimension[/h2]

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:

``````
//2D normalize
length = sqrt(x * x + y * y)
invlen = 1 / length
x *= length
y *= length

//3D
length = sqrt(x * x + y * y + z * z)
invlen = 1 / length
x *= length
y *= length
z *= length

//4D
length = sqrt(x * x + y * y + z * z + d * d)
invlen = 1 / length
x *= length
y *= length
z *= length
d *= 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.

http://s21.postimg.org/jrdcxjumb/img3.png

http://s21.postimg.org/m9z1y8gcj/img4.png

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.

http://s21.postimg.org/mhmouqrb7/img2.png

http://s21.postimg.org/qphh3hsqr/img1.png

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

http://s21.postimg.org/6xfb47h6r/img6.png

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

http://s3.postimg.org/nlk6rj21r/imgsss2.jpg

Cube in 4D have 4 Planes every Plane with own color.
[h2]Ray Progression 4D[/h2]

``````
y=0, z=2, x=2, d=1
y=0, z=3, x=2, d=1
y=0, z=3, x=3, d=1
y=-1, z=3, x=3, d=1// black

y=1, z=2, x=3, d=1
y=1, z=3, x=3, d=1
y=0, z=3, x=3, d=1
y=0, z=3, x=4, d=1
y=0, z=3, x=4, d=2// Purpl

y=1, z=2, x=3, d=1
y=1, z=3, x=3, d=1
y=1, z=3, x=4, d=1
y=1, z=3, x=4, d=2
y=0, z=3, x=4, d=2// Grean

``````

Every new plane add Sin self and Cos prev Planes
Camera ray Projection 3D

``````
ray.y += Dist * sin_Y;

ray.x += Dist * sin_X * cos_Y;
ray.z += -Dist * cos_X * cos_Y;

``````

Camera ray Projection 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;

``````

[h2]4D matrix Img[/h2]

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 =)

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.

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

http://s14.postimg.org/bh5h52frh/Move.jpg

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

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:

[tr][td]
[h1]What is the 4th dimension and how to program it =)[/h1]
Let’s start simple.

[h2]1st dimension:[/h2]
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. [icode]int[x][/icode]

[h2]2nd dimension:[/h2]
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): [icode]int[x][z][/icode]
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-

[h2]3rd dimension:[/h2]
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: [icode]int[x][z][y][/icode]
For rotating we use 2 defining angles:
Sinus for up and down and
Cos for the XZ plane.

[h2]More dimensions[/h2]
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:
[table][tr][td]
http://s21.postimg.org/qphh3hsqr/img1.jpg
[/td][/tr]

If we look diagonal with only 1 angle, we can only see 2 sides:
[tr][td]
http://s12.postimg.org/i5yewiopl/img.jpg
[/td][/tr]

This is how it looks like, when we see 2 X sides, 1 Z side and 2 Y sides:
[tr][td]
http://s21.postimg.org/5rbb5esw3/img0.jpg
[/td][/tr]

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.

[h2]4th dimension[/h2]
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: [icode]int[x][z][y][d][/icode]

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:

``````
// 2D normalize
length = sqrt(x * x + y * y)
invlen = 1 / length
x *= length
y *= length

// 3D
length = sqrt(x * x + y * y + z * z)
invlen = 1 / length
x *= length
y *= length
z *= length

// 4D
length = sqrt(x * x + y * y + z * z + d * d)
invlen = 1 / length
x *= length
y *= length
z *= length
d *= 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 ;D )

[tr][td]
http://s21.postimg.org/jrdcxjumb/img3.jpg
[/td][td]
http://s21.postimg.org/m9z1y8gcj/img4.jpg
[/td][/tr]

‘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.’

[tr][td]
http://s21.postimg.org/mhmouqrb7/img2.jpg
[/td][td]
http://s21.postimg.org/qphh3hsqr/img1.jpg
[/td][/tr]

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

[tr][td]
http://s21.postimg.org/6xfb47h6r/img6.jpg
[/td][/tr]

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:
[tr][td]
http://s14.postimg.org/dymqstmx9/imgsss.jpg
[/td][/tr]

[h3]Ray progression[/h3]

``````
float y=0, z=2, x=2, d=1
float y=0, z=3, x=2, d=1
float y=0, z=3, x=3, d=1
float y=-1, z=3, x=3, d=1// black

float y=1, z=2, x=3, d=1
float y=1, z=3, x=3, d=1
float y=0, z=3, x=3, d=1
float y=0, z=3, x=4, d=1
float y=0, z=3, x=4, d=2// Purple

float y=1, z=2, x=3, d=1
float y=1, z=3, x=3, d=1
float y=1, z=3, x=4, d=1
float y=1, z=3, x=4, d=2
float y=0, z=3, x=4, d=2// Green

Every new plane adds a sin for itself and a cos for previous planes
Camera 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 =)

[/td][/tr][/table] (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 )

Big Ty I Try fix all Now;)

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.

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

sorry wrong browser have double post

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

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

Have an imaginary virtual medal!

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

``````
/*
*/

``````

The result is:

=)
Add New 4D Img (Cube) Matrix

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

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)

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

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

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).