Archived
Added glib and math dependencies, incorporated custom vector3, vector2, matrix4x4 structs
This commit is contained in:
+14
-14
@@ -1,18 +1,19 @@
|
||||
/**
|
||||
* A 4-by-4 matrix useful in OpenGL matrix operations.
|
||||
*/
|
||||
public struct Ch3.Mat4x4 {
|
||||
public struct Worldbuilder.Matrix4x4
|
||||
{
|
||||
public float data[4*4];
|
||||
|
||||
/**
|
||||
* Create a new matrix with a value along its diagonal.
|
||||
*/
|
||||
public Mat4x4 (float diagonal_value) {
|
||||
public Matrix4x4 (float diagonal_value) {
|
||||
for (int i = 0; i < 4; i++)
|
||||
this[i, i] = diagonal_value;
|
||||
}
|
||||
|
||||
public Mat4x4.identity () {
|
||||
public Matrix4x4.identity () {
|
||||
this (1.0f);
|
||||
}
|
||||
|
||||
@@ -24,7 +25,7 @@ public struct Ch3.Mat4x4 {
|
||||
* @param near distance to near plane along the z axis
|
||||
* @param far distance to far plane along the z axis
|
||||
*/
|
||||
public Mat4x4.perspective (float fov, float aspect_ratio, float near, float far) {
|
||||
public Matrix4x4.perspective (float fov, float aspect_ratio, float near, float far) {
|
||||
// see http://www.songho.ca/opengl/gl_projectionmatrix.html
|
||||
|
||||
float height_2 = Math.tanf (fov / 2) * near;
|
||||
@@ -48,7 +49,7 @@ public struct Ch3.Mat4x4 {
|
||||
* @param target what the camera is looking at
|
||||
* @param up a direction that represents "up"
|
||||
*/
|
||||
public Mat4x4.look_at (Vec3 position, Vec3 target, Vec3 up) {
|
||||
public Matrix4x4.look_at (Vector3 position, Vector3 target, Vector3 up) {
|
||||
// see https://learnopengl.com/Getting-started/Camera
|
||||
|
||||
up = up.normalized ();
|
||||
@@ -82,13 +83,13 @@ public struct Ch3.Mat4x4 {
|
||||
return data[col*4 + row];
|
||||
}
|
||||
|
||||
public Mat4x4 write (int row, int col, float value) {
|
||||
public Matrix4x4 write (int row, int col, float value) {
|
||||
var copy = this;
|
||||
copy[row, col] = value;
|
||||
return copy;
|
||||
}
|
||||
|
||||
public Mat4x4 rotateX (float radians) {
|
||||
public Matrix4x4 rotateX (float radians) {
|
||||
// see https://learnopengl.com/Getting-started/Transformations
|
||||
var copy = this;
|
||||
// rotate around x axis
|
||||
@@ -103,7 +104,7 @@ public struct Ch3.Mat4x4 {
|
||||
return copy;
|
||||
}
|
||||
|
||||
public Mat4x4 rotateY (float radians) {
|
||||
public Matrix4x4 rotateY (float radians) {
|
||||
var copy = this;
|
||||
// rotate around y axis
|
||||
float sin_y, cos_y;
|
||||
@@ -117,7 +118,7 @@ public struct Ch3.Mat4x4 {
|
||||
return copy;
|
||||
}
|
||||
|
||||
public Mat4x4 rotateZ (float radians) {
|
||||
public Matrix4x4 rotateZ (float radians) {
|
||||
var copy = this;
|
||||
// rotate around z axis
|
||||
float sin_z, cos_z;
|
||||
@@ -131,7 +132,7 @@ public struct Ch3.Mat4x4 {
|
||||
return copy;
|
||||
}
|
||||
|
||||
public Mat4x4 scale (float x, float y, float z) {
|
||||
public Matrix4x4 scale (float x, float y, float z) {
|
||||
var copy = this;
|
||||
copy[0, 0] *= x;
|
||||
copy[1, 1] *= y;
|
||||
@@ -139,7 +140,7 @@ public struct Ch3.Mat4x4 {
|
||||
return copy;
|
||||
}
|
||||
|
||||
public Mat4x4 translate (float x, float y, float z) {
|
||||
public Matrix4x4 translate (float x, float y, float z) {
|
||||
var copy = this;
|
||||
copy[0, 3] += x;
|
||||
copy[1, 3] += y;
|
||||
@@ -147,8 +148,8 @@ public struct Ch3.Mat4x4 {
|
||||
return copy;
|
||||
}
|
||||
|
||||
public Mat4x4 multiply (Mat4x4 other) {
|
||||
var result = Mat4x4 (0);
|
||||
public Matrix4x4 multiply (Matrix4x4 other) {
|
||||
var result = Matrix4x4 (0);
|
||||
|
||||
// this x other = result
|
||||
for (int row = 0; row < 4; row++)
|
||||
@@ -188,4 +189,3 @@ public struct Ch3.Mat4x4 {
|
||||
return sb.str;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
public class Worldbuilder.Texture2D : Object {
|
||||
public string path { get; construct; }
|
||||
public GL.uint id { get; private set; }
|
||||
|
||||
/**
|
||||
* Loads a 2D texture from a resource and sets up a GL texture buffer.
|
||||
*
|
||||
* @param filename basename
|
||||
*/
|
||||
public Texture2D (string filename) throws Error {
|
||||
Object (path: @"/com/brodybrooks/worldbuilder/textures/$filename");
|
||||
var pixbuf = new Gdk.Pixbuf.from_resource (this.path);
|
||||
debug ("loading %s ...", this.path);
|
||||
id = GL.gen_texture ();
|
||||
GL.bind_texture (GL.TEXTURE_2D, id);
|
||||
GL.tex_image_2D (GL.TEXTURE_2D, 0, GL.RGB, pixbuf.width, pixbuf.height, 0, GL.RGB, GL.UNSIGNED_BYTE, pixbuf.get_pixels ());
|
||||
GL.generate_mipmap (GL.TEXTURE_2D);
|
||||
GL.bind_texture (GL.TEXTURE_2D, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ public struct Worldbuilder.Vector2 {
|
||||
public float x;
|
||||
public float y;
|
||||
|
||||
public Vec2 (float x = 0, float y = 0) {
|
||||
public Vector2 (float x = 0, float y = 0) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
+10
-1
@@ -2,14 +2,21 @@ worldbuilder_sources = [
|
||||
'main.vala',
|
||||
'application.vala',
|
||||
'window.vala',
|
||||
'scene_renderer.vala',
|
||||
|
||||
'core/vector3.vala',
|
||||
'core/matrix4x4.vala',
|
||||
'core/vector2.vala',
|
||||
]
|
||||
|
||||
worldbuilder_deps = [
|
||||
config_dep,
|
||||
dependency('glib-2.0'),
|
||||
dependency('gtk4', version: '>= 4.2'),
|
||||
dependency('libadwaita-1', version: '>= 1.4'),
|
||||
cc.find_library('epoxy'),
|
||||
valac.find_library('gl', dirs: meson.source_root() / 'vapi'),
|
||||
cc.find_library('m', required: false) # optional on Windows
|
||||
]
|
||||
|
||||
worldbuilder_sources += gnome.compile_resources('worldbuilder-resources',
|
||||
@@ -17,7 +24,9 @@ worldbuilder_sources += gnome.compile_resources('worldbuilder-resources',
|
||||
c_name: 'worldbuilder'
|
||||
)
|
||||
|
||||
executable('worldbuilder', worldbuilder_sources,
|
||||
executable(
|
||||
'worldbuilder',
|
||||
worldbuilder_sources,
|
||||
dependencies: worldbuilder_deps,
|
||||
include_directories: config_inc,
|
||||
install: true,
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@
|
||||
<style>
|
||||
<class name="devel"/>
|
||||
</style>
|
||||
<property name="default-width">800</property>
|
||||
<property name="default-height">600</property>
|
||||
<property name="default-width">1280</property>
|
||||
<property name="default-height">720</property>
|
||||
<property name="content">
|
||||
<object class="AdwToolbarView">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user