Skip to content

Commit ed1d579

Browse files
authored
Feature/simple (#2)
* WIP; switch to SwiftMath; use system libs; * Fix linux build * add ext and update app * update package * fix linux build * upgrade project * left handed projection matrix
1 parent 4d33a2f commit ed1d579

File tree

12 files changed

+257
-574
lines changed

12 files changed

+257
-574
lines changed

Package.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ import PackageDescription
55
let package = Package(
66
name: "OpenGLExampleApp",
77
dependencies: [
8-
.package(url: "https://github.com/SwiftGFX/SwiftMath", from: "3.3.0"),
9-
.package(url: "https://github.com/sakrist/GLAppBase", from: "0.0.3")
8+
// .package(path: "../SwiftMath"),
9+
// .package(url: "https://github.com/SwiftGFX/SwiftMath", from: "3.3.0"),
10+
.package(url: "https://github.com/sakrist/SwiftMath", .branch("feature/matrix3x3-tests")),
11+
.package(url: "https://github.com/sakrist/GLApplication", from: "0.0.4")
12+
//.package(url: "https://github.com/sakrist/GLAppBase", .branch("feature/build-with-spm"))
1013
],
1114
targets: [
12-
.target( name: "app", dependencies: [ "SwiftMath", "GLAppBase" ]),
15+
.target(name: "app",
16+
dependencies: [ "SwiftMath", "GLApplication" ],
17+
cSettings: [.define("GL_GLEXT_PROTOTYPES")]),
1318
]
1419
)
1520

16-
1721
#if os(Android)
1822
package.products.append(.library(name: "OpenGLExampleApp", type: .dynamic, targets: ["app"]))
1923
package.dependencies.append(.package(name: "SwiftProtobuf", url: "https://github.com/apple/swift-protobuf.git", .exact("1.13.0")))
@@ -28,9 +32,3 @@ package.targets += [
2832
]
2933
#endif
3034

31-
#if os(Linux)
32-
package.dependencies.append(.package(name: "COpenGL", url: "https://github.com/sakrist/COpenGL.swift.git", from:"1.0.7"))
33-
package.dependencies.append(.package(name: "CX11", url: "https://github.com/sakrist/CX11.swift.git", from:"1.0.5"))
34-
package.targets[0].dependencies += ["COpenGL", "CX11"]
35-
#endif
36-

Sources/app/App.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#endif
1919

2020
import SwiftMath
21-
import GLAppBase
21+
import GLApplication
2222

23-
class App: GLAppBase {
23+
class App: Application {
2424

2525
// Scene variable, getter and setter.
2626
var scene:Scene {
@@ -34,16 +34,18 @@ class App: GLAppBase {
3434

3535
var lastMousePoint:Point = Point()
3636

37-
var pitch:Float = 0.3
38-
var yaw:Float = -0.4
37+
var pitch:Float = 0.0
38+
var yaw:Float = 0.0
3939

4040
override func applicationCreate() {
4141

4242
if isGLOn() {
4343
// create scene
4444
self.scene = Scene()
4545
scene.size = Size(640, 480)
46-
scene.modelViewMatrix *= (xRotation(pitch) * yRotation(yaw))
46+
let rotateX = Matrix4x4f.rotate(x: Angle.init(radians: pitch))
47+
let rotateY = Matrix4x4f.rotate(y: Angle.init(radians: yaw))
48+
scene.modelViewMatrix = scene.modelViewMatrix * (rotateX * rotateY)
4749
scene.geometries.append(Cube())
4850

4951
// re-draw after init
@@ -71,10 +73,12 @@ class App: GLAppBase {
7173
let x = Float( (point.x - lastMousePoint.x) * scene.size.height/scene.size.width*0.5 )
7274
let y = Float( (point.y - lastMousePoint.y) * -(scene.size.width/scene.size.height*0.5) )
7375

74-
pitch += -degreesToRadians(y)
75-
yaw += degreesToRadians(x)
76+
pitch += -Angle.init(degrees:y).radians
77+
yaw += Angle.init(degrees:x).radians
7678

77-
scene.modelViewMatrix = translate(x:0, y:0, z:-4.0) * (xRotation(pitch) * yRotation(yaw))
79+
let rotateX = Matrix4x4f.rotate(x: Angle.init(radians: pitch))
80+
let rotateY = Matrix4x4f.rotate(y: Angle.init(radians: yaw))
81+
scene.modelViewMatrix = Matrix4x4f.translate(tx: 0, ty: 0, tz: 4) * (rotateX * rotateY)
7882

7983
lastMousePoint = point
8084

Sources/app/Cube.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
#if os(Linux)
1010
import Glibc
11-
import COpenGL.gl
12-
import COpenGL.glx
11+
import OpenGL
1312
#elseif os(OSX)
1413
import Darwin.C
1514
import Cocoa

Sources/app/Geometry.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
//
88

99
#if os(Linux)
10-
import Glibc
11-
import COpenGL.gl
12-
import COpenGL.glx
10+
import Glibc
11+
import OpenGL
1312
#elseif os(OSX)
14-
import Darwin.C
15-
import Cocoa
13+
import Darwin.C
14+
import Cocoa
15+
import OpenGL
1616
#elseif os(iOS)
17-
import OpenGLES
17+
import OpenGLES
1818
#elseif os(Android)
19-
import Glibc
20-
import GL.ES3
19+
import Glibc
20+
import GL.ES3
2121
#endif
2222

2323
func BUFFER_OFFSET(_ i: Int) -> UnsafeRawPointer? {

0 commit comments

Comments
 (0)