Ethosa hace 3 años
padre
commit
706f0e4013
Se han modificado 2 ficheros con 16 adiciones y 12 borrados
  1. 7 7
      src/nodesnim/core/nodes_os.nim
  2. 9 5
      src/nodesnim/nodes3d/geometry_instance.nim

+ 7 - 7
src/nodesnim/core/nodes_os.nim

@@ -10,17 +10,17 @@ const
   home_folder* = getHomeDir()
   nodesnim_folder* = home_folder / "NodesNim"
   saves_folder* = "NodesNim" / "saves"
-  standard_font_path* =
-    when defined(windows):
-      "C://Windows/Fonts/segoeuib.ttf"
-    elif defined(android):
-      "/system/fonts/DroidSans.ttf"
-    else:
-      currentSourcePath().parentDir() / "unifont.ttf"
 
 discard existsOrCreateDir(nodesnim_folder)
 discard existsOrCreateDir(home_folder / saves_folder)
 
+let standard_font_path* =
+  when defined(windows):
+    "C://Windows/Fonts/segoeuib.ttf"
+  elif defined(android):
+    "/system/fonts/DroidSans.ttf"
+  else:
+      currentSourcePath().parentDir() / "unifont.ttf"
 var standard_font*: FontPtr = nil
 
 proc setStandardFont*(path: cstring, size: cint) =

+ 9 - 5
src/nodesnim/nodes3d/geometry_instance.nim

@@ -21,7 +21,7 @@ type
     GEOMETRY_SPHERE
   GeometryInstanceObj* = object of Node3DObj
     geometry*: GeometryType
-    sides*: int
+    sides*, rings*: int
     color*: ColorRef
     radius*: float
   GeometryInstanceRef* = ref GeometryInstanceObj
@@ -38,6 +38,7 @@ proc GeometryInstance*(name: string = "GeometryInstance", geometry: GeometryType
   node3dpattern()
   result.geometry = geometry
   result.sides = 8
+  result.rings = 8
   result.radius = 1
   result.color = Color(1.0, 1.0, 1.0)
   result.kind = GEOMETRY_INSTANCE_NODE
@@ -96,6 +97,7 @@ method draw*(self: GeometryInstanceRef, w, h: Glfloat) =
     glVertex3f(1,  1, -1)
     glEnd()
   of GEOMETRY_CYLINDER:
+    # Draw sides
     glBegin(GL_QUAD_STRIP)
     for i in 0..self.sides:
       let angle = TAU*i.float/self.sides.float
@@ -103,12 +105,14 @@ method draw*(self: GeometryInstanceRef, w, h: Glfloat) =
       glVertex3f(sin(angle)*self.radius, -1, cos(angle)*self.radius)
     glEnd()
 
+    # Draw top
     glBegin(GL_POLYGON)
     for i in 0..self.sides:
       let angle = TAU*i.float/self.sides.float
       glVertex3f(sin(angle)*self.radius, 1, cos(angle)*self.radius)
     glEnd()
 
+    # Draw bottom
     glBegin(GL_POLYGON)
     for i in 0..self.sides:
       let angle = TAU*i.float/self.sides.float
@@ -116,11 +120,11 @@ method draw*(self: GeometryInstanceRef, w, h: Glfloat) =
     glEnd()
   of GEOMETRY_SPHERE:
     var
-      R = 2 * PI / 24f
-      S = PI / 48f
+      R = 2 * PI / self.rings.float
+      S = PI / self.sides.float
     glBegin(GL_TRIANGLE_STRIP)
-    for ring in 0..24:
-      for sector in 0..48:
+    for ring in 0..self.rings:
+      for sector in 0..self.sides:
         var
           s = sector.float
           r = ring.float