WHY? the 3d camera looks in 2d

Godot Version

4.2

Question

Good afternoon, I have a very strange and annoying problem with the camera, I have not been able to do some 3D perspective project because the camera is rendering everything as 2D or something like that, I honestly don’t know what is happening :face_with_spiral_eyes:


:point_right:(I have not added any script to the scene, there are only nodes)

the environment and light are both samples, not really present in the game. You can add the samples to the scene, by clicking this three dot menu by the preview buttons, and selecting “add to scene”

It worked, well, only half, because I still can’t find a way to completely render the tesseract :thinking:

tesseract? I don’t think Godot is 4D capable by default, and you’ll have a tough time completely rendering anything from the 4th dimension onto a 2D screen. Are you using a plugin? What is the tesseract, can you show your scene tree?

I’m just using vector4, the adding faces part is where it’s not complete:
escena 3d

extends Node3D

var hypercube_vertices = []
var hypercube_edges = []
var hypercube_faces = []
var rotation_angle = 0.0

func _ready():
    generate_hypercube()
    set_process(true)

func _process(delta):
    rotation_angle += delta
    draw_hypercube()

func generate_hypercube():
    var cube_vertices = [
        Vector3(-1, -1, -1),
        Vector3(1, -1, -1),
        Vector3(1, 1, -1),
        Vector3(-1, 1, -1),
        Vector3(-1, -1, 1),
        Vector3(1, -1, 1),
        Vector3(1, 1, 1),
        Vector3(-1, 1, 1)
    ]
    for vertex in cube_vertices:
        hypercube_vertices.append(Vector4(vertex.x, vertex.y, vertex.z, -1))
        hypercube_vertices.append(Vector4(vertex.x, vertex.y, vertex.z, 1))
    
    # Define the edges of the hypercube
    hypercube_edges = [
        [0, 1], [1, 2], [2, 3], [3, 0],
        [4, 5], [5, 6], [6, 7], [7, 4],
        [0, 4], [1, 5], [2, 6], [3, 7],
        [8, 9], [9, 10], [10, 11], [11, 8],
        [12, 13], [13, 14], [14, 15], [15, 12],
        [8, 12], [9, 13], [10, 14], [11, 15],
        [0, 8], [1, 9], [2, 10], [3, 11],
        [4, 12], [5, 13], [6, 14], [7, 15]
    ]

    # Define the faces of the hypercube
    hypercube_faces = [
        [0, 1, 2, 3], [4, 5, 6, 7], [0, 1, 5, 4], [1, 2, 6, 5],
        [2, 3, 7, 6], [3, 0, 4, 7], [8, 9, 10, 11], [12, 13, 14, 15],
        [8, 9, 13, 12], [9, 10, 14, 13], [10, 11, 15, 14], [11, 8, 12, 15],
        [0, 8, 9, 1], [1, 9, 10, 2], [2, 10, 11, 3], [3, 11, 8, 0],
        [4, 12, 13, 5], [5, 13, 14, 6], [6, 14, 15, 7], [7, 15, 12, 4]
    ]

func rotate_4d(vertex, angle):
    var cos_angle = cos(angle)
    var sin_angle = sin(angle)
    return Vector4(
        vertex.x * cos_angle - vertex.w * sin_angle,
        vertex.y,
        vertex.z,
        vertex.x * sin_angle + vertex.w * cos_angle
    )

func project_to_3d(vertex4):
    var w = 2 / (2 - vertex4.w)
    return Vector3(vertex4.x * w, vertex4.y * w, vertex4.z * w)

func draw_hypercube():
    var mesh_instance = get_node("MeshInstance3D")
    var array_mesh = ArrayMesh.new()
    var vertices = PackedVector3Array()
    var indices = PackedInt32Array()
    
    var projected_vertices = []
    for vertex4 in hypercube_vertices:
        var rotated_vertex = rotate_4d(vertex4, rotation_angle)
        var vertex3 = project_to_3d(rotated_vertex)
        projected_vertices.append(vertex3)
        vertices.append(vertex3)
    
    # Add edges as lines
    for edge in hypercube_edges:
        indices.append(edge[0])
        indices.append(edge[1])
    
    var arrays = []
    arrays.resize(Mesh.ARRAY_MAX)
    arrays[Mesh.ARRAY_VERTEX] = vertices
    arrays[Mesh.ARRAY_INDEX] = indices
    
    array_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_LINES, arrays)
    
    mesh_instance.mesh = array_mesh
    
    # Debug messages
    print("Number of projected vertices: ", projected_vertices.size())
    print("Number of indices: ", indices.size())

    # Count the number of projected edges
    var num_edges = float(indices.size()) / 2.0
    print("Number of projected edges: ", num_edges)

    if indices.size() % 2 != 0:
        print("Error: The number of indices is not a multiple of 2")
    else:
        print("The indices are correct")

1 Like

Sick, I am out of my depth here, I could not complete course 1 of 4D Golf. Good luck!

Are the green lines rendered or did you hand-draw them in post as an example?

it’s for the cube
cube 4d

Do you know anyone in this community who has some knowledge or interest in geometry?