SakiKawasaki %!s(int64=5) %!d(string=hai) anos
pai
achega
68a213c34e

+ 26 - 24
README.md

@@ -48,30 +48,30 @@
 
 ## Now available
 This section contains links to documentation for all nodes.
-|Core                |Default nodes             |Control nodes                  |2D Nodes                    |
-|:--:                |:--:                      |:--:                           |  :--:                      |
-|[Anchor][Anchor]    |[Node][Node]              |[Control][Control]             |[Node2D][Node2D]            |
-|[Color][Color]      |[Canvas][Canvas]          |[ColorRect][ColorRect]         |[Sprite][Sprite]            |
-|[ColorText][clrtext]|[Scene][Scene]            |[TextureRect][TextureRect]     |[AnimatedSprite][asprite]   |
-|[Enums][Enums]      |[AudioStreamPlayer][aplay]|[Label][Label]                 |[YSort][YSort]              |
-|[Exceptions][except]|                          |[Button][Button]               |[CollisionShape2D][cshape2d]|
-|[Image][Image]      |                          |[EditText][EditText]           |[Camera2D][Camera2D]        |
-|[Input][Input]      |                          |[RichLabel][RichLabel]         |                            |
-|[Rect2][Rect2]      |                          |[RichEditText][RichEditText]   |                            |
-|[Vector2][Vector2]  |                          |[Box][Box]                     |                            |
-|[Circle2][Circle2]  |                          |[HBox][HBox]                   |                            |
-|[Polygon2][Polygon2]|                          |[VBox][VBox]                   |                            |
-|[AudioStream][astrm]|                          |[GridBox][GridBox]             |                            |
-|[Animation][anim]   |                          |[Scroll][Scroll]               |                            |
-|[Vector3][Vector3]  |                          |[ProgressBar][ProgressBar]     |                            |
-|                    |                          |[Slider][Slider]               |                            |
-|                    |                          |[VProgressBar][VProgressBar]   |                            |
-|                    |                          |[VSlider][VSlider]             |                            |
-|                    |                          |[Popup][Popup]                 |                            |
-|                    |                          |[TextureButton][TextureButton] |                            |
-|                    |                          |[TextureProgressBar][tprogress]|                            |
-|                    |                          |[Counter][Counter]             |                            |
-|                    |                          |[Switch][Switch]               |                            |
+|Core                |Default nodes             |Control nodes                  |2D Nodes                    |3D Nodes        |
+|:--:                |:--:                      |:--:                           |  :--:                      |:--:            |
+|[Anchor][Anchor]    |[Node][Node]              |[Control][Control]             |[Node2D][Node2D]            |[Node3D][Node3D]|
+|[Color][Color]      |[Canvas][Canvas]          |[ColorRect][ColorRect]         |[Sprite][Sprite]            |                |
+|[ColorText][clrtext]|[Scene][Scene]            |[TextureRect][TextureRect]     |[AnimatedSprite][asprite]   |                |
+|[Enums][Enums]      |[AudioStreamPlayer][aplay]|[Label][Label]                 |[YSort][YSort]              |                |
+|[Exceptions][except]|                          |[Button][Button]               |[CollisionShape2D][cshape2d]|                |
+|[Image][Image]      |                          |[EditText][EditText]           |[Camera2D][Camera2D]        |                |
+|[Input][Input]      |                          |[RichLabel][RichLabel]         |                            |                |
+|[Rect2][Rect2]      |                          |[RichEditText][RichEditText]   |                            |                |
+|[Vector2][Vector2]  |                          |[Box][Box]                     |                            |                |
+|[Circle2][Circle2]  |                          |[HBox][HBox]                   |                            |                |
+|[Polygon2][Polygon2]|                          |[VBox][VBox]                   |                            |                |
+|[AudioStream][astrm]|                          |[GridBox][GridBox]             |                            |                |
+|[Animation][anim]   |                          |[Scroll][Scroll]               |                            |                |
+|[Vector3][Vector3]  |                          |[ProgressBar][ProgressBar]     |                            |                |
+|                    |                          |[Slider][Slider]               |                            |                |
+|                    |                          |[VProgressBar][VProgressBar]   |                            |                |
+|                    |                          |[VSlider][VSlider]             |                            |                |
+|                    |                          |[Popup][Popup]                 |                            |                |
+|                    |                          |[TextureButton][TextureButton] |                            |                |
+|                    |                          |[TextureProgressBar][tprogress]|                            |                |
+|                    |                          |[Counter][Counter]             |                            |                |
+|                    |                          |[Switch][Switch]               |                            |                |
 
 
 
@@ -165,3 +165,5 @@ Use the [`Nim compiler user guide`](https://nim-lang.org/docs/nimc.html#dynlibov
 [KinematicBody2D]:https://ethosa.github.io/nodesnim/nodesnim/nodes2d/kinematic_body2d.html
 [Camera2D]:https://ethosa.github.io/nodesnim/nodesnim/nodes2d/camera2d.html
 [Node2D]:https://ethosa.github.io/nodesnim/nodesnim/nodes2d/node2d.html
+
+[Node3D]:https://ethosa.github.io/nodesnim/nodesnim/nodes3d/node3d.html

+ 6 - 2
src/nodesnim.nim

@@ -68,7 +68,9 @@ import
   nodesnim/nodes2d/ysort,
   nodesnim/nodes2d/collision_shape2d,
   nodesnim/nodes2d/kinematic_body2d,
-  nodesnim/nodes2d/camera2d
+  nodesnim/nodes2d/camera2d,
+
+  nodesnim/nodes3d/node3d
 
 export
   # Third party
@@ -85,4 +87,6 @@ export
   rich_label, rich_edit_text, scroll, progress_bar, vprogress_bar, slider, vslider, popup,
   texture_button, texture_progress_bar, counter, switch,
   # 2D nodes
-  node2d, sprite, animated_sprite, ysort, collision_shape2d, kinematic_body2d, camera2d
+  node2d, sprite, animated_sprite, ysort, collision_shape2d, kinematic_body2d, camera2d,
+  # 3D nodes
+  node3d

+ 6 - 1
src/nodesnim/core/enums.nim

@@ -45,4 +45,9 @@ type
     VBOX_NODE,
     VPROGRESS_BAR_NODE,
     VSLIDER_NODE,
-    NODE_3D
+    NODE3D_NODE
+  NodeTypes* {.pure.} = enum
+    NODE_TYPE_DEFAULT,
+    NODE_TYPE_CONTROL,
+    NODE_TYPE_2D,
+    NODE_TYPE_3D

+ 5 - 0
src/nodesnim/nodes/node.nim

@@ -15,6 +15,7 @@ import
 type
   NodeObj* = object of RootObj
     kind*: NodeKind
+    node_type*: NodeTypes
     visible*: bool
     is_ready*: bool
     can_use_anchor*: bool
@@ -88,6 +89,10 @@ method calcGlobalPosition*(self: NodeRef) {.base.} =
     if self.relative_z_index:
       self.z_index_global += current.z_index
 
+method calcGlobalPosition3*(self: NodeRef) {.base.} =
+  ## Uses in the 3D nodes.
+  discard
+
 method calcPositionAnchor*(self: NodeRef) {.base.} =
   ## Calculates node position with anchor.
   ## This used in the Window object.

+ 1 - 0
src/nodesnim/nodes/scene.nim

@@ -29,6 +29,7 @@ method drawScene*(scene: SceneRef, w, h: GLfloat, paused: bool) {.base.} =
       continue
     if child.visible:
       child.calcGlobalPosition()
+      child.calcGlobalPosition3()
       if not child.is_ready:
         child.on_ready(child)
         child.is_ready = true

+ 1 - 0
src/nodesnim/nodes2d/node2d.nim

@@ -25,6 +25,7 @@ type
 template node2dpattern*: untyped =
   result.centered = true
   result.timed_position = Vector2()
+  result.node_type = NODE_TYPE_2D
 
 proc Node2D*(name: string = "Node2D"): Node2DRef =
   ## Creates a new Node2D.

+ 102 - 0
src/nodesnim/nodes3d/node3d.nim

@@ -0,0 +1,102 @@
+# author: Ethosa
+import
+  ../thirdparty/opengl,
+
+  ../core/vector2,
+  ../core/vector3,
+  ../core/enums,
+  ../core/anchor,
+  ../core/input,
+
+  ../nodes/node
+
+
+type
+  Node3DObj* = object of NodeObj
+    rotation*, translation*, scale*: Vector3Obj
+    global_rotation*, global_translation*, global_scale*: Vector3Obj
+  Node3DRef* = ref Node3DObj
+
+
+template node3dpattern* =
+  result.rotation = Vector3()
+  result.translation = Vector3()
+  result.scale = Vector3()
+  result.global_rotation = Vector3()
+  result.global_translation = Vector3()
+  result.global_scale = Vector3()
+  result.node_type = NODE_TYPE_3D
+
+
+proc Node3D*(name: string = "Node3D"): Node3DRef =
+  ## Creates a new Node3D object.
+  ##
+  ## Arguments:
+  ## - `name` is a node name.
+  runnableExamples:
+    var node = Node3D("Node3D")
+  nodepattern(Node3DRef)
+  node3dpattern()
+  result.kind = NODE3D_NODE
+
+
+method calcGlobalPosition3*(self: Node3DRef) =
+  var current: NodeRef = self
+  self.global_translation = self.translation
+  self.global_rotation = self.rotation
+  self.global_scale = self.scale
+
+  while current.parent != nil:
+    current = current.parent
+    if current.node_type == NODE_TYPE_3D:
+      self.global_translation += current.Node3DRef.translation
+      self.global_rotation += current.Node3DRef.rotation
+      self.global_scale += current.Node3DRef.scale
+
+
+method rotate*(self: Node3DRef, x, y, z: float) {.base.} =
+  self.rotation += Vector3(x, y, z)
+
+method rotate*(self: Node3DRef, xyz: Vector3Obj) {.base.} =
+  self.rotation += xyz
+
+method rotateX*(self: Node3DRef, x: float) {.base.} =
+  self.rotation.x += x
+
+method rotateY*(self: Node3DRef, y: float) {.base.} =
+  self.rotation.y += y
+
+method rotateZ*(self: Node3DRef, z: float) {.base.} =
+  self.rotation.z += z
+
+
+method translate*(self: Node3DRef, x, y, z: float) {.base.} =
+  self.translation += Vector3(x, y, z)
+
+method translate*(self: Node3DRef, xyz: Vector3Obj) {.base.} =
+  self.translation += xyz
+
+method translateX*(self: Node3DRef, x: float) {.base.} =
+  self.translation.x += x
+
+method translateY*(self: Node3DRef, y: float) {.base.} =
+  self.translation.y += y
+
+method translateZ*(self: Node3DRef, z: float) {.base.} =
+  self.translation.z += z
+
+
+method transform*(self: Node3DRef, x, y, z: float) {.base.} =
+  self.scale += Vector3(x, y, z)
+
+method transform*(self: Node3DRef, xyz: Vector3Obj) {.base.} =
+  self.scale += xyz
+
+method transformX*(self: Node3DRef, x: float) {.base.} =
+  self.scale.x += x
+
+method transformY*(self: Node3DRef, y: float) {.base.} =
+  self.scale.y += y
+
+method transformZ*(self: Node3DRef, z: float) {.base.} =
+  self.scale.z += z

+ 1 - 0
src/nodesnim/nodescontrol/control.nim

@@ -48,6 +48,7 @@ template controlpattern*: untyped =
   result.on_release = proc(self: ControlRef, x, y: float) = discard
   result.on_focus = proc(self: ControlRef) = discard
   result.on_unfocus = proc(self: ControlRef) = discard
+  result.node_type = NODE_TYPE_CONTROL
 
 proc Control*(name: string = "Control"): ControlRef =
   ## Creates a new Control.

+ 1 - 1
src/nodesnim/thirdparty/sdl2.nim

@@ -27,7 +27,7 @@ else:
 when not defined(android) and not defined(ios):
   type csize_t_const* = csize_t
 else:
-  type csize_t_const* = size_t
+  type csize_t_const* = csize
 
 
 include sdl2/private/keycodes

+ 1 - 0
tests/README.md

@@ -37,3 +37,4 @@
 35. [Event handlers with macros.](https://github.com/Ethosa/nodesnim/blob/master/tests/test35.nim)
 36. [Rotation.](https://github.com/Ethosa/nodesnim/blob/master/tests/test36.nim)
 37. [Use Camera2D node.](https://github.com/Ethosa/nodesnim/blob/master/tests/test37.nim)
+38. [Use Node3D.](https://github.com/Ethosa/nodesnim/blob/master/tests/test38.nim)

+ 14 - 0
tests/test38.nim

@@ -0,0 +1,14 @@
+# --- Test 38. Use Node3D. --- #
+import nodesnim
+
+Window("smth here")
+
+var
+  scene = Scene("Main")
+  node = Node3D()
+
+scene.addChild(node)
+
+
+addMainScene(scene)
+windowLaunch()