mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-04 06:09:46 +03:00
Merge pull request #366 from aaronfranke/matrix-transform
Add Matrix Transform demo
This commit is contained in:
15
misc/matrix_transform/2D.tscn
Normal file
15
misc/matrix_transform/2D.tscn
Normal file
@@ -0,0 +1,15 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://marker/AxisMarker2D.tscn" type="PackedScene" id=1]
|
||||
|
||||
[node name="2D" type="Node2D"]
|
||||
|
||||
[node name="Scale100" type="Node2D" parent="."]
|
||||
rotation = 2.98023e-08
|
||||
scale = Vector2( 100, 100 )
|
||||
|
||||
[node name="AxisMarker" parent="Scale100" instance=ExtResource( 1 )]
|
||||
|
||||
[node name="AxisMarker2" parent="Scale100/AxisMarker" instance=ExtResource( 1 )]
|
||||
position = Vector2( 1.5, 1 )
|
||||
rotation = 0.349066
|
||||
10
misc/matrix_transform/3D.tscn
Normal file
10
misc/matrix_transform/3D.tscn
Normal file
@@ -0,0 +1,10 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://marker/AxisMarker3D.tscn" type="PackedScene" id=1]
|
||||
|
||||
[node name="3D" type="Spatial"]
|
||||
|
||||
[node name="AxisMarker" parent="." instance=ExtResource( 1 )]
|
||||
|
||||
[node name="AxisMarker" parent="AxisMarker" instance=ExtResource( 1 )]
|
||||
transform = Transform( 0.921381, -0.293412, 0.254887, 0.254887, 0.951251, 0.173648, -0.293412, -0.0950286, 0.951251, 1, 1, -1 )
|
||||
25
misc/matrix_transform/README.md
Normal file
25
misc/matrix_transform/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# Matrix Transform
|
||||
|
||||
This demo project is a playground where you can visualize how transforms work.
|
||||
|
||||
Do not "run" this project. You are only meant to use it within the Godot editor.
|
||||
|
||||
For more information, see the [Matrices and Transforms](https://docs.godotengine.org/en/latest/tutorials/math/matrices_and_transforms.html) article.
|
||||
|
||||
## How does it work?
|
||||
|
||||
In both 2D and 3D, colored lines are drawn indicating the basis vectors as well as the origin vector. For 3D, this means cuboids. If you translate, rotate, scale, or shear the AxisMarker objects, you will be able to see how it affects the transform's component vectors, and all children objects are also appropriately transformed.
|
||||
|
||||
You are encouraged to manipulate the AxisMarker objects both in the main viewport and in the inspector. You are encouraged to duplicate them in the hierarchy and parent them any way you wish.
|
||||
|
||||
In 2D, red and green lines represent the X and Y axes, with blue representing the origin.
|
||||
|
||||
In 3D, red, green, and blue lines represent the X, Y, and Z axes, with cyan representing the origin.
|
||||
|
||||
One noteworthy implementation detail: to avoid jitter, the origin vector is a parent of a Node, and inherits the AxisMarker's parent's transform.
|
||||
|
||||
## Screenshots
|
||||
|
||||

|
||||
|
||||

|
||||
7
misc/matrix_transform/default_env.tres
Normal file
7
misc/matrix_transform/default_env.tres
Normal file
@@ -0,0 +1,7 @@
|
||||
[gd_resource type="Environment" load_steps=2 format=2]
|
||||
|
||||
[sub_resource type="ProceduralSky" id=1]
|
||||
|
||||
[resource]
|
||||
background_mode = 2
|
||||
background_sky = SubResource( 1 )
|
||||
BIN
misc/matrix_transform/icon.png
Normal file
BIN
misc/matrix_transform/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
34
misc/matrix_transform/icon.png.import
Normal file
34
misc/matrix_transform/icon.png.import
Normal file
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.png"
|
||||
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
11
misc/matrix_transform/marker/AxisMarker2D.gd
Normal file
11
misc/matrix_transform/marker/AxisMarker2D.gd
Normal file
@@ -0,0 +1,11 @@
|
||||
tool
|
||||
class_name AxisMarker2D, "res://marker/AxisMarker2D.svg"
|
||||
extends Node2D
|
||||
|
||||
func _process(_delta):
|
||||
var line: Line2D = get_child(0).get_child(0)
|
||||
var marker_parent: Node2D = get_parent()
|
||||
|
||||
line.points[1] = transform.origin
|
||||
if marker_parent as Node2D != null:
|
||||
line.transform = marker_parent.global_transform
|
||||
1
misc/matrix_transform/marker/AxisMarker2D.svg
Normal file
1
misc/matrix_transform/marker/AxisMarker2D.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m3.9844 15a1 1 0 0 1 -.69141-.29102l-2-2a1 1 0 0 1 0-1.4141 1 1 0 0 1 1.4141 0l.29297.29297v-8.5859002h8.5859l-.29297-.29297a1 1 0 0 1 0-1.4141 1 1 0 0 1 1.4141 0l2 2a1 1 0 0 1 0 1.4141l-2 2a1 1 0 0 1 -.7207.29102 1 1 0 0 1 -.69336-.29102 1 1 0 0 1 0-1.4141l.29297-.29297h-6.5859v6.5859002l.29297-.29297a1 1 0 0 1 1.4141 0 1 1 0 0 1 0 1.4141l-2 2a1 1 0 0 1 -.72266.29102z" fill="#a5b7f3"/></svg>
|
||||
|
After Width: | Height: | Size: 488 B |
34
misc/matrix_transform/marker/AxisMarker2D.svg.import
Normal file
34
misc/matrix_transform/marker/AxisMarker2D.svg.import
Normal file
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/AxisMarker2D.svg-a52a23070c2ca9dcdd860a47183ce756.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://marker/AxisMarker2D.svg"
|
||||
dest_files=[ "res://.import/AxisMarker2D.svg-a52a23070c2ca9dcdd860a47183ce756.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
40
misc/matrix_transform/marker/AxisMarker2D.tscn
Normal file
40
misc/matrix_transform/marker/AxisMarker2D.tscn
Normal file
@@ -0,0 +1,40 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://marker/AxisMarker2D.gd" type="Script" id=1]
|
||||
|
||||
[node name="AxisMarker" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Origin" type="Node" parent="."]
|
||||
|
||||
[node name="Line" type="Line2D" parent="Origin"]
|
||||
points = PoolVector2Array( 0, 0, 0, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0, 0.266667, 1, 1 )
|
||||
__meta__ = {
|
||||
"_edit_lock_": true
|
||||
}
|
||||
|
||||
[node name="Center" type="Line2D" parent="."]
|
||||
points = PoolVector2Array( -0.05, 0, 0.05, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0, 0.266667, 1, 1 )
|
||||
__meta__ = {
|
||||
"_edit_lock_": true
|
||||
}
|
||||
|
||||
[node name="X" type="Line2D" parent="."]
|
||||
points = PoolVector2Array( 0.05, 0, 1, 0 )
|
||||
width = 0.1
|
||||
default_color = Color( 0.866667, 0, 0, 1 )
|
||||
__meta__ = {
|
||||
"_edit_lock_": true
|
||||
}
|
||||
|
||||
[node name="Y" type="Line2D" parent="."]
|
||||
points = PoolVector2Array( 0, 0.05, 0, 1 )
|
||||
width = 0.1
|
||||
default_color = Color( 0, 0.866667, 0, 1 )
|
||||
__meta__ = {
|
||||
"_edit_lock_": true
|
||||
}
|
||||
17
misc/matrix_transform/marker/AxisMarker3D.gd
Normal file
17
misc/matrix_transform/marker/AxisMarker3D.gd
Normal file
@@ -0,0 +1,17 @@
|
||||
tool
|
||||
class_name AxisMarker3D, "res://marker/AxisMarker3D.svg"
|
||||
extends Spatial
|
||||
|
||||
func _process(_delta):
|
||||
var holder: Spatial = get_child(0).get_child(0)
|
||||
var cube: Spatial = holder.get_child(0)
|
||||
# "Hide" the origin vector if the AxisMarker is at (0, 0, 0)
|
||||
if translation == Vector3():
|
||||
holder.transform = Transform()
|
||||
cube.transform = Transform().scaled(Vector3.ONE * 0.0001)
|
||||
return
|
||||
|
||||
holder.transform = Transform(Basis(), translation / 2)
|
||||
holder.transform = holder.transform.looking_at(translation, Vector3.UP)
|
||||
holder.transform = get_parent().global_transform * holder.transform
|
||||
cube.transform = Transform(Basis().scaled(Vector3(0.1, 0.1, translation.length())))
|
||||
1
misc/matrix_transform/marker/AxisMarker3D.svg
Normal file
1
misc/matrix_transform/marker/AxisMarker3D.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m3.9902 1a1 1 0 0 0 -.69141.29102l-2 2a1 1 0 0 0 0 1.4141 1 1 0 0 0 1.4141 0l.29297-.29297v8.5859h8.5859l-.29297.29297a1 1 0 0 0 0 1.4141 1 1 0 0 0 1.4141 0l2-2a1 1 0 0 0 0-1.4141l-2-2a1 1 0 0 0 -.72266-.29102 1 1 0 0 0 -.69141.29102 1 1 0 0 0 0 1.4141l.29297.29297h-5.1719l5.5859-5.5859v.41602a1 1 0 0 0 1 1 1 1 0 0 0 1-1v-2.8301a1 1 0 0 0 -1-1h-2.8301a1 1 0 0 0 -1 1 1 1 0 0 0 1 1h.41602l-5.5859 5.5859v-5.1719l.29297.29297a1 1 0 0 0 1.4141 0 1 1 0 0 0 0-1.4141l-2-2a1 1 0 0 0 -.72266-.29102z" fill="#fc9c9c"/></svg>
|
||||
|
After Width: | Height: | Size: 611 B |
34
misc/matrix_transform/marker/AxisMarker3D.svg.import
Normal file
34
misc/matrix_transform/marker/AxisMarker3D.svg.import
Normal file
@@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/AxisMarker3D.svg-613a31ba426aca266949d27353333ae4.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://marker/AxisMarker3D.svg"
|
||||
dest_files=[ "res://.import/AxisMarker3D.svg-613a31ba426aca266949d27353333ae4.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
50
misc/matrix_transform/marker/AxisMarker3D.tscn
Normal file
50
misc/matrix_transform/marker/AxisMarker3D.tscn
Normal file
@@ -0,0 +1,50 @@
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://marker/AxisMarker3D.gd" type="Script" id=1]
|
||||
|
||||
[sub_resource type="CubeMesh" id=1]
|
||||
size = Vector3( 1, 1, 1 )
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=2]
|
||||
albedo_color = Color( 0, 1, 1, 1 )
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=3]
|
||||
albedo_color = Color( 1, 0, 0, 1 )
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=4]
|
||||
albedo_color = Color( 0, 1, 0, 1 )
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=5]
|
||||
albedo_color = Color( 0, 0, 1, 1 )
|
||||
|
||||
[node name="AxisMarker" type="Spatial"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Origin" type="Node" parent="."]
|
||||
|
||||
[node name="Holder" type="Spatial" parent="Origin"]
|
||||
|
||||
[node name="Cube" type="MeshInstance" parent="Origin/Holder"]
|
||||
transform = Transform( 0.0001, 0, 0, 0, 0.0001, 0, 0, 0, 0.0001, 0, 0, 0 )
|
||||
mesh = SubResource( 1 )
|
||||
material/0 = SubResource( 2 )
|
||||
|
||||
[node name="Center" type="MeshInstance" parent="."]
|
||||
transform = Transform( 0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0, 0, 0 )
|
||||
mesh = SubResource( 1 )
|
||||
material/0 = SubResource( 2 )
|
||||
|
||||
[node name="X" type="MeshInstance" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0.55, 0, 0 )
|
||||
mesh = SubResource( 1 )
|
||||
material/0 = SubResource( 3 )
|
||||
|
||||
[node name="Y" type="MeshInstance" parent="."]
|
||||
transform = Transform( 0.1, 0, 0, 0, 1, 0, 0, 0, 0.1, 0, 0.55, 0 )
|
||||
mesh = SubResource( 1 )
|
||||
material/0 = SubResource( 4 )
|
||||
|
||||
[node name="Z" type="MeshInstance" parent="."]
|
||||
transform = Transform( 0.1, 0, 0, 0, 0.1, 0, 0, 0, 1, 0, 0, 0.55 )
|
||||
mesh = SubResource( 1 )
|
||||
material/0 = SubResource( 5 )
|
||||
35
misc/matrix_transform/project.godot
Normal file
35
misc/matrix_transform/project.godot
Normal file
@@ -0,0 +1,35 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=4
|
||||
|
||||
_global_script_classes=[ {
|
||||
"base": "Node2D",
|
||||
"class": "AxisMarker2D",
|
||||
"language": "GDScript",
|
||||
"path": "res://marker/AxisMarker2D.gd"
|
||||
}, {
|
||||
"base": "Spatial",
|
||||
"class": "AxisMarker3D",
|
||||
"language": "GDScript",
|
||||
"path": "res://marker/AxisMarker3D.gd"
|
||||
} ]
|
||||
_global_script_class_icons={
|
||||
"AxisMarker2D": "res://marker/AxisMarker2D.svg",
|
||||
"AxisMarker3D": "res://marker/AxisMarker3D.svg"
|
||||
}
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Matrix Transform"
|
||||
run/main_scene="res://3D.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[rendering]
|
||||
|
||||
environment/default_environment="res://default_env.tres"
|
||||
0
misc/matrix_transform/screenshots/.gdignore
Normal file
0
misc/matrix_transform/screenshots/.gdignore
Normal file
BIN
misc/matrix_transform/screenshots/2D.png
Normal file
BIN
misc/matrix_transform/screenshots/2D.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.3 KiB |
BIN
misc/matrix_transform/screenshots/3D.png
Normal file
BIN
misc/matrix_transform/screenshots/3D.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
Reference in New Issue
Block a user