Browse Source

add sphere :eyes:

Ethosa 4 years ago
parent
commit
cbb94669e6

+ 1 - 1
README.md

@@ -7,7 +7,7 @@
 [![time tracker](https://wakatime.com/badge/github/Ethosa/nodesnim.svg)](https://wakatime.com/badge/github/Ethosa/nodesnim)
 [![test](https://github.com/Ethosa/nodesnim/workflows/test/badge.svg)](https://github.com/Ethosa/nodesnim/actions)
 
-<h4>Stable version - 0.2.2</h4>
+<h4>Stable version - 0.2.3</h4>
 </div>
 
 ## Install

+ 1 - 2
engine/scenes/projects/project_template.nim

@@ -15,7 +15,6 @@ build:
       call move(-2, -2)
       call resize(256, 20)
       call setTextAlign(1, 0, 1, 0)
-      call setFont(GLUT_BITMAP_HELVETICA_18, 18)
       mousemode: MOUSEMODE_IGNORE
 
 project@on_process(self):
@@ -28,5 +27,5 @@ project@on_process(self):
     s.color = Color(0x1d242aff)
 
 project@on_click(self, x, y):
-  changeScene("Editor", @[(k: "title", v: self.getNode("Title").LabelRef.text)])
+  changeScene("Editor", @[(k: "title", v: self.getNode("Title").LabelRef.getText())])
   glutReshapeWindow(1280, 720)

+ 1 - 1
nodesnim.nimble

@@ -1,7 +1,7 @@
 [Package]
 name = "nodesnim"
 author = "Ethosa"
-version = "0.2.2"
+version = "0.2.3"
 description = "The Nim GUI/2D framework based on OpenGL and SDL2."
 license = "MIT"
 srcDir = "src"

+ 2 - 2
src/nodesnim/core/exceptions.nim

@@ -1,5 +1,5 @@
 # author: Ethosa
 
 type
-  MainSceneNotLoadedError* = object of ValueError
-  WindowNotCreatedError* = object of ValueError
+  SceneError* = object of ValueError
+  WindowError* = object of ValueError

+ 1 - 1
src/nodesnim/core/polygon2.nim

@@ -78,7 +78,7 @@ proc intersects*(self, other: Polygon2Ref): bool =
       if intersects(a, b, c, d):
         return true
 
-proc intersects*(self: Polygon2Ref, r: Rect2Ref): bool =
+proc intersects*(self: Polygon2Ref, r: Rect2Obj): bool =
   ## Returns true, if rect intersect with polygon.
   var next = 1
   let length = self.positions.len()

+ 12 - 13
src/nodesnim/core/rect2.nim

@@ -6,32 +6,31 @@ import vector2
 type
   Rect2Obj* = object
     x*, y*, w*, h*: float
-  Rect2Ref* = ref Rect2Obj
 
 
-proc Rect2*(x, y, w, h: float): Rect2Ref =
-  Rect2Ref(x: x, y: y, w: w, h: h)
+proc Rect2*(x, y, w, h: float): Rect2Obj =
+  Rect2Obj(x: x, y: y, w: w, h: h)
 
-proc Rect2*(pos, size: Vector2Obj): Rect2Ref =
-  Rect2Ref(
+proc Rect2*(pos, size: Vector2Obj): Rect2Obj =
+  Rect2Obj(
     x: pos.x, y: pos.y,
     w: size.x, h: size.y
   )
 
 
-proc contains*(self: Rect2Ref, x, y: float): bool {.inline.} =
+proc contains*(self: Rect2Obj, x, y: float): bool {.inline.} =
   self.x <= x and self.x+self.w >= x and self.y <= y and self.y+self.h >= y
 
-proc contains*(self: Rect2Ref, vector: Vector2Obj): bool {.inline.} =
+proc contains*(self: Rect2Obj, vector: Vector2Obj): bool {.inline.} =
   self.contains(vector.x, vector.y)
 
-proc contains*(self, other: Rect2Ref): bool =
+proc contains*(self, other: Rect2Obj): bool =
   (self.contains(other.x, other.y) and
    self.contains(other.x+other.w, other.y) and
    self.contains(other.x, other.y+other.h) and
    self.contains(other.x+other.w, other.y+other.h))
 
-proc intersects*(self, other: Rect2Ref): bool =
+proc intersects*(self, other: Rect2Obj): bool =
   if self.w > other.w and self.h > other.h:
     (self.contains(other.x, other.y) or
      self.contains(other.x, other.y+other.h) or
@@ -43,13 +42,13 @@ proc intersects*(self, other: Rect2Ref): bool =
      other.contains(self.x+other.w, self.y) or
      other.contains(self.x+other.w, self.y+self.h))
 
-proc contains*(self: Rect2Ref, a, b: Vector2Obj): bool =
+proc contains*(self: Rect2Obj, a, b: Vector2Obj): bool =
   let
     left = intersects(a, b, Vector2(self.x, self.y), Vector2(self.x, self.y+self.h))
     right = intersects(a, b, Vector2(self.x+self.w, self.y), Vector2(self.x+self.w, self.y+self.h))
     top = intersects(a, b, Vector2(self.x, self.y), Vector2(self.x+self.w, self.y))
     bottom = intersects(a, b, Vector2(self.x, self.y+self.h), Vector2(self.x+self.w, self.y+self.h))
-  return left or right or bottom or top
+  left or right or bottom or top
 
 proc clamp*(a, b, c: float): float =
   if a < b:
@@ -59,7 +58,7 @@ proc clamp*(a, b, c: float): float =
   else:
     a
 
-proc isCollideWithCircle*(self: Rect2Ref, x, y, r: float): bool =
+proc isCollideWithCircle*(self: Rect2Obj, x, y, r: float): bool =
   let
     dx = clamp(x, self.x, self.x+self.w) - x
     dy = clamp(y, self.y, self.y+self.h) - y
@@ -67,5 +66,5 @@ proc isCollideWithCircle*(self: Rect2Ref, x, y, r: float): bool =
 
 
 # --- Operators --- #
-proc `$`*(x: Rect2Ref): string =
+proc `$`*(x: Rect2Obj): string {.inline.} =
   "Rect2(x: " & $x.x & ", y: " & $x.y & ", w: " & $x.w & ", h: " & $x.h & ")"

+ 2 - 2
src/nodesnim/window.nim

@@ -257,7 +257,7 @@ proc setMainScene*(name: string) =
 proc setTitle*(title: cstring) =
   ## Changes window title.
   if not window_created:
-    raise newException(WindowNotCreatedError, "Window not created!")
+    raise newException(WindowError, "Window not created!")
   glutSetWindowTitle(title)
 
 proc setMaxDistance*(distance: GLdouble) =
@@ -305,7 +305,7 @@ proc windowLaunch* =
   glutMotionFunc(motion)
   glutPassiveMotionFunc(motion)
   if main_scene == nil:
-    raise newException(MainSceneNotLoadedError, "Main scene is not indicated!")
+    raise newException(SceneError, "Main scene is not indicated!")
   changeScene(main_scene.name)
   when defined(debug):
     info("window launched")

+ 7 - 1
tests/test37.nim

@@ -15,6 +15,10 @@ build:
     - GeometryInstance geometry2:
       translation: Vector3(-1, 0, 2)
       color: Color(122, 133, 144, 0.8)
+    - GeometryInstance geometry3:
+      translation: Vector3(1, 0, 2)
+      color: Color(144, 111, 144)
+      geometry: GEOMETRY_SPHERE
     - Button button:
       text: stext"Hello! ^^"
       call resize(256, 64)
@@ -24,8 +28,10 @@ geometry1@on_input(self, event):
   if event.isInputEventMouseMotion() and event.pressed:
     geometry1.rotateX(-event.yrel)
     geometry1.rotateY(-event.xrel)
-    geometry2.rotateX(-event.yrel)
+    geometry2.rotateX(event.yrel)
     geometry2.rotateY(-event.xrel)
+    geometry3.rotateX(event.yrel)
+    geometry3.rotateY(-event.xrel)
 
 addMainScene(scene)
 windowLaunch()