-Fixed a few bugs in Viewport
-Made a few demos using Viewport to show it's true power! -Fixed some start-up error messages.
This commit is contained in:
BIN
demos/viewport/2d_in_3d/ball.png
Normal file
BIN
demos/viewport/2d_in_3d/ball.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 203 B |
22
demos/viewport/2d_in_3d/engine.cfg
Normal file
22
demos/viewport/2d_in_3d/engine.cfg
Normal file
@ -0,0 +1,22 @@
|
||||
[application]
|
||||
|
||||
name="Pong 2D in 3D"
|
||||
main_scene="res://pong3d.scn"
|
||||
icon="res://icon.png"
|
||||
|
||||
[display]
|
||||
|
||||
width=640
|
||||
height=400
|
||||
stretch_2d=true
|
||||
|
||||
[input]
|
||||
|
||||
left_move_up=[key(A)]
|
||||
left_move_down=[key(Z)]
|
||||
right_move_up=[key(Up)]
|
||||
right_move_down=[key(Down)]
|
||||
|
||||
[render]
|
||||
|
||||
default_clear_color=#ff000000
|
||||
BIN
demos/viewport/2d_in_3d/icon.png
Normal file
BIN
demos/viewport/2d_in_3d/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 956 B |
BIN
demos/viewport/2d_in_3d/left_pallete.png
Normal file
BIN
demos/viewport/2d_in_3d/left_pallete.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 200 B |
73
demos/viewport/2d_in_3d/pong.gd
Normal file
73
demos/viewport/2d_in_3d/pong.gd
Normal file
@ -0,0 +1,73 @@
|
||||
|
||||
extends Node2D
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
const INITIAL_BALL_SPEED = 80
|
||||
var ball_speed = INITIAL_BALL_SPEED
|
||||
var screen_size = Vector2(640,400)
|
||||
#default ball direction
|
||||
var direction = Vector2(-1,0)
|
||||
var pad_size = Vector2(8,32)
|
||||
const PAD_SPEED = 150
|
||||
|
||||
|
||||
func _process(delta):
|
||||
|
||||
|
||||
# get ball positio and pad rectangles
|
||||
var ball_pos = get_node("ball").get_pos()
|
||||
var left_rect = Rect2( get_node("left").get_pos() - pad_size*0.5, pad_size )
|
||||
var right_rect = Rect2( get_node("right").get_pos() - pad_size*0.5, pad_size )
|
||||
|
||||
#integrate new ball postion
|
||||
ball_pos+=direction*ball_speed*delta
|
||||
|
||||
#flip when touching roof or floor
|
||||
if ( (ball_pos.y<0 and direction.y <0) or (ball_pos.y>screen_size.y and direction.y>0)):
|
||||
direction.y = -direction.y
|
||||
|
||||
#flip, change direction and increase speed when touching pads
|
||||
if ( (left_rect.has_point(ball_pos) and direction.x < 0) or (right_rect.has_point(ball_pos) and direction.x > 0)):
|
||||
direction.x=-direction.x
|
||||
ball_speed*=1.1
|
||||
direction.y=randf()*2.0-1
|
||||
direction = direction.normalized()
|
||||
|
||||
#check gameover
|
||||
if (ball_pos.x<0 or ball_pos.x>screen_size.x):
|
||||
ball_pos=screen_size*0.5
|
||||
ball_speed=INITIAL_BALL_SPEED
|
||||
direction=Vector2(-1,0)
|
||||
|
||||
|
||||
get_node("ball").set_pos(ball_pos)
|
||||
|
||||
#move left pad
|
||||
var left_pos = get_node("left").get_pos()
|
||||
|
||||
if (left_pos.y > 0 and Input.is_action_pressed("left_move_up")):
|
||||
left_pos.y+=-PAD_SPEED*delta
|
||||
if (left_pos.y < screen_size.y and Input.is_action_pressed("left_move_down")):
|
||||
left_pos.y+=PAD_SPEED*delta
|
||||
|
||||
get_node("left").set_pos(left_pos)
|
||||
|
||||
#move right pad
|
||||
var right_pos = get_node("right").get_pos()
|
||||
|
||||
if (right_pos.y > 0 and Input.is_action_pressed("right_move_up")):
|
||||
right_pos.y+=-PAD_SPEED*delta
|
||||
if (right_pos.y < screen_size.y and Input.is_action_pressed("right_move_down")):
|
||||
right_pos.y+=PAD_SPEED*delta
|
||||
|
||||
get_node("right").set_pos(right_pos)
|
||||
|
||||
|
||||
|
||||
func _ready():
|
||||
screen_size = get_viewport_rect().size # get actual size
|
||||
pad_size = get_node("left").get_texture().get_size()
|
||||
set_process(true)
|
||||
|
||||
183
demos/viewport/2d_in_3d/pong.xml
Normal file
183
demos/viewport/2d_in_3d/pong.xml
Normal file
@ -0,0 +1,183 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<resource_file type="PackedScene" subresource_count="6" version="0.99" version_name="Godot Engine v0.99.3735-pre-beta">
|
||||
<ext_resource path="res://pong.*" type="GDScript"></ext_resource>
|
||||
<ext_resource path="res://separator.*" type="ImageTexture"></ext_resource>
|
||||
<ext_resource path="res://left_pallete.*" type="ImageTexture"></ext_resource>
|
||||
<ext_resource path="res://right_pallete.*" type="ImageTexture"></ext_resource>
|
||||
<ext_resource path="res://ball.*" type="ImageTexture"></ext_resource>
|
||||
<main_resource>
|
||||
<dictionary name="_bundled" shared="false">
|
||||
<string> "names" </string>
|
||||
<string_array len="27">
|
||||
<string> "game" </string>
|
||||
<string> "Node2D" </string>
|
||||
<string> "visibility/visible" </string>
|
||||
<string> "visibility/opacity" </string>
|
||||
<string> "visibility/self_opacity" </string>
|
||||
<string> "visibility/on_top" </string>
|
||||
<string> "transform/pos" </string>
|
||||
<string> "transform/rot" </string>
|
||||
<string> "transform/scale" </string>
|
||||
<string> "script/script" </string>
|
||||
<string> "__meta__" </string>
|
||||
<string> "left" </string>
|
||||
<string> "Sprite" </string>
|
||||
<string> "texture" </string>
|
||||
<string> "centered" </string>
|
||||
<string> "offset" </string>
|
||||
<string> "flip_h" </string>
|
||||
<string> "flip_v" </string>
|
||||
<string> "vframes" </string>
|
||||
<string> "hframes" </string>
|
||||
<string> "frame" </string>
|
||||
<string> "modulate" </string>
|
||||
<string> "region" </string>
|
||||
<string> "region_rect" </string>
|
||||
<string> "right" </string>
|
||||
<string> "separator" </string>
|
||||
<string> "ball" </string>
|
||||
</string_array>
|
||||
<string> "version" </string>
|
||||
<int> 1 </int>
|
||||
<string> "conn_count" </string>
|
||||
<int> 0 </int>
|
||||
<string> "node_count" </string>
|
||||
<int> 5 </int>
|
||||
<string> "variants" </string>
|
||||
<array len="20" shared="false">
|
||||
<bool> True </bool>
|
||||
<real> 1 </real>
|
||||
<vector2> 0, 0 </vector2>
|
||||
<real> 0 </real>
|
||||
<vector2> 1, 1 </vector2>
|
||||
<resource resource_type="GDScript" path="res://pong.*"> </resource>
|
||||
<dictionary shared="false">
|
||||
<string> "__editor_plugin_states__" </string>
|
||||
<dictionary shared="false">
|
||||
<string> "Script" </string>
|
||||
<dictionary shared="false">
|
||||
<string> "current" </string>
|
||||
<int> 0 </int>
|
||||
<string> "sources" </string>
|
||||
<array len="1" shared="false">
|
||||
<string> "res://pong.gd" </string>
|
||||
</array>
|
||||
</dictionary>
|
||||
<string> "2D" </string>
|
||||
<dictionary shared="false">
|
||||
<string> "pixel_snap" </string>
|
||||
<bool> True </bool>
|
||||
<string> "zoom" </string>
|
||||
<real> 1.108033 </real>
|
||||
<string> "ofs" </string>
|
||||
<vector2> -54.59, -36.0052 </vector2>
|
||||
</dictionary>
|
||||
<string> "3D" </string>
|
||||
<dictionary shared="false">
|
||||
<string> "zfar" </string>
|
||||
<real> 500 </real>
|
||||
<string> "fov" </string>
|
||||
<real> 45 </real>
|
||||
<string> "viewports" </string>
|
||||
<array len="4" shared="false">
|
||||
<dictionary shared="false">
|
||||
<string> "distance" </string>
|
||||
<real> 4 </real>
|
||||
<string> "x_rot" </string>
|
||||
<real> 0 </real>
|
||||
<string> "y_rot" </string>
|
||||
<real> 0 </real>
|
||||
<string> "use_orthogonal" </string>
|
||||
<bool> False </bool>
|
||||
<string> "use_environment" </string>
|
||||
<bool> False </bool>
|
||||
<string> "pos" </string>
|
||||
<vector3> 0, 0, 0 </vector3>
|
||||
</dictionary>
|
||||
<dictionary shared="false">
|
||||
<string> "distance" </string>
|
||||
<real> 4 </real>
|
||||
<string> "x_rot" </string>
|
||||
<real> 0 </real>
|
||||
<string> "y_rot" </string>
|
||||
<real> 0 </real>
|
||||
<string> "use_orthogonal" </string>
|
||||
<bool> False </bool>
|
||||
<string> "use_environment" </string>
|
||||
<bool> False </bool>
|
||||
<string> "pos" </string>
|
||||
<vector3> 0, 0, 0 </vector3>
|
||||
</dictionary>
|
||||
<dictionary shared="false">
|
||||
<string> "distance" </string>
|
||||
<real> 4 </real>
|
||||
<string> "x_rot" </string>
|
||||
<real> 0 </real>
|
||||
<string> "y_rot" </string>
|
||||
<real> 0 </real>
|
||||
<string> "use_orthogonal" </string>
|
||||
<bool> False </bool>
|
||||
<string> "use_environment" </string>
|
||||
<bool> False </bool>
|
||||
<string> "pos" </string>
|
||||
<vector3> 0, 0, 0 </vector3>
|
||||
</dictionary>
|
||||
<dictionary shared="false">
|
||||
<string> "distance" </string>
|
||||
<real> 4 </real>
|
||||
<string> "x_rot" </string>
|
||||
<real> 0 </real>
|
||||
<string> "y_rot" </string>
|
||||
<real> 0 </real>
|
||||
<string> "use_orthogonal" </string>
|
||||
<bool> False </bool>
|
||||
<string> "use_environment" </string>
|
||||
<bool> False </bool>
|
||||
<string> "pos" </string>
|
||||
<vector3> 0, 0, 0 </vector3>
|
||||
</dictionary>
|
||||
</array>
|
||||
<string> "viewport_mode" </string>
|
||||
<int> 1 </int>
|
||||
<string> "default_light" </string>
|
||||
<bool> True </bool>
|
||||
<string> "show_grid" </string>
|
||||
<bool> True </bool>
|
||||
<string> "show_origin" </string>
|
||||
<bool> True </bool>
|
||||
<string> "znear" </string>
|
||||
<real> 0.1 </real>
|
||||
</dictionary>
|
||||
</dictionary>
|
||||
<string> "__editor_run_settings__" </string>
|
||||
<dictionary shared="false">
|
||||
<string> "custom_args" </string>
|
||||
<string> "-l $scene" </string>
|
||||
<string> "run_mode" </string>
|
||||
<int> 0 </int>
|
||||
</dictionary>
|
||||
<string> "__editor_plugin_screen__" </string>
|
||||
<string> "Script" </string>
|
||||
</dictionary>
|
||||
<vector2> 67.6875, 183.208 </vector2>
|
||||
<resource resource_type="ImageTexture" path="res://left_pallete.*"> </resource>
|
||||
<bool> False </bool>
|
||||
<int> 1 </int>
|
||||
<int> 0 </int>
|
||||
<color> 1, 1, 1, 1 </color>
|
||||
<rect2> 0, 0, 0, 0 </rect2>
|
||||
<vector2> 577, 187 </vector2>
|
||||
<resource resource_type="ImageTexture" path="res://right_pallete.*"> </resource>
|
||||
<vector2> 320, 200 </vector2>
|
||||
<resource resource_type="ImageTexture" path="res://separator.*"> </resource>
|
||||
<vector2> 320.283, 188 </vector2>
|
||||
<resource resource_type="ImageTexture" path="res://ball.*"> </resource>
|
||||
</array>
|
||||
<string> "nodes" </string>
|
||||
<int_array len="197"> -1, -1, 1, 0, -1, 9, 2, 0, 3, 1, 4, 1, 5, 0, 6, 2, 7, 3, 8, 4, 9, 5, 10, 6, 0, 0, 0, 12, 11, -1, 18, 2, 0, 3, 1, 4, 1, 5, 0, 6, 7, 7, 3, 8, 4, 13, 8, 14, 0, 15, 2, 16, 9, 17, 9, 18, 10, 19, 10, 20, 11, 21, 12, 22, 9, 23, 13, 0, 0, 0, 12, 24, -1, 18, 2, 0, 3, 1, 4, 1, 5, 0, 6, 14, 7, 3, 8, 4, 13, 15, 14, 0, 15, 2, 16, 9, 17, 9, 18, 10, 19, 10, 20, 11, 21, 12, 22, 9, 23, 13, 0, 0, 0, 12, 25, -1, 18, 2, 0, 3, 1, 4, 1, 5, 0, 6, 16, 7, 3, 8, 4, 13, 17, 14, 0, 15, 2, 16, 9, 17, 9, 18, 10, 19, 10, 20, 11, 21, 12, 22, 9, 23, 13, 0, 0, 0, 12, 26, -1, 18, 2, 0, 3, 1, 4, 1, 5, 0, 6, 18, 7, 3, 8, 4, 13, 19, 14, 0, 15, 2, 16, 9, 17, 9, 18, 10, 19, 10, 20, 11, 21, 12, 22, 9, 23, 13, 0 </int_array>
|
||||
<string> "conns" </string>
|
||||
<int_array len="0"> </int_array>
|
||||
</dictionary>
|
||||
|
||||
</main_resource>
|
||||
</resource_file>
|
||||
14
demos/viewport/2d_in_3d/pong3d.gd
Normal file
14
demos/viewport/2d_in_3d/pong3d.gd
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
extends Spatial
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
func _ready():
|
||||
# Initalization here
|
||||
var tex = get_node("Viewport").get_render_target_texture()
|
||||
get_node("Quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE,tex)
|
||||
pass
|
||||
|
||||
|
||||
BIN
demos/viewport/2d_in_3d/pong3d.scn
Normal file
BIN
demos/viewport/2d_in_3d/pong3d.scn
Normal file
Binary file not shown.
BIN
demos/viewport/2d_in_3d/right_pallete.png
Normal file
BIN
demos/viewport/2d_in_3d/right_pallete.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 202 B |
BIN
demos/viewport/2d_in_3d/separator.png
Normal file
BIN
demos/viewport/2d_in_3d/separator.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 203 B |
4
demos/viewport/3d_in_2d/engine.cfg
Normal file
4
demos/viewport/3d_in_2d/engine.cfg
Normal file
@ -0,0 +1,4 @@
|
||||
[application]
|
||||
|
||||
name="3D in 2D"
|
||||
main_scene="res://main.scn"
|
||||
BIN
demos/viewport/3d_in_2d/main.scn
Normal file
BIN
demos/viewport/3d_in_2d/main.scn
Normal file
Binary file not shown.
BIN
demos/viewport/3d_in_2d/player.scn
Normal file
BIN
demos/viewport/3d_in_2d/player.scn
Normal file
Binary file not shown.
1736
demos/viewport/3d_in_2d/player.xml
Normal file
1736
demos/viewport/3d_in_2d/player.xml
Normal file
File diff suppressed because one or more lines are too long
BIN
demos/viewport/3d_in_2d/player_2d.scn
Normal file
BIN
demos/viewport/3d_in_2d/player_2d.scn
Normal file
Binary file not shown.
BIN
demos/viewport/3d_in_2d/player_3d.scn
Normal file
BIN
demos/viewport/3d_in_2d/player_3d.scn
Normal file
Binary file not shown.
BIN
demos/viewport/3d_in_2d/robot_demo.png
Normal file
BIN
demos/viewport/3d_in_2d/robot_demo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
4
demos/viewport/gui_in_3d/engine.cfg
Normal file
4
demos/viewport/gui_in_3d/engine.cfg
Normal file
@ -0,0 +1,4 @@
|
||||
[application]
|
||||
|
||||
name="GUI in 3D"
|
||||
main_scene="res://gui_3d.scn"
|
||||
BIN
demos/viewport/gui_in_3d/gui.scn
Normal file
BIN
demos/viewport/gui_in_3d/gui.scn
Normal file
Binary file not shown.
44
demos/viewport/gui_in_3d/gui_3d.gd
Normal file
44
demos/viewport/gui_in_3d/gui_3d.gd
Normal file
@ -0,0 +1,44 @@
|
||||
|
||||
extends Spatial
|
||||
|
||||
# member variables here, example:
|
||||
# var a=2
|
||||
# var b="textvar"
|
||||
|
||||
var prev_pos=null
|
||||
|
||||
func _input(ev):
|
||||
if (ev.type in [InputEvent.MOUSE_BUTTON,InputEvent.MOUSE_MOTION]):
|
||||
var pos = ev.pos
|
||||
var rfrom = get_node("camera").project_ray_origin(pos)
|
||||
var rnorm = get_node("camera").project_ray_normal(pos)
|
||||
|
||||
#simple collision test against aligned plane
|
||||
#for game UIs of this kind consider more complex collision against plane
|
||||
var p = Plane(Vector3(0,0,1),0).intersects_ray(rfrom,rnorm)
|
||||
if (p==null):
|
||||
return
|
||||
|
||||
pos.x=(p.x+1.5)*100
|
||||
pos.y=(-p.y+0.75)*100
|
||||
ev.pos=pos
|
||||
ev.global_pos=pos
|
||||
if (prev_pos==null):
|
||||
prev_pos=pos
|
||||
if (ev.type==InputEvent.MOUSE_MOTION):
|
||||
ev.relative_pos=pos-prev_pos
|
||||
prev_pos=pos
|
||||
|
||||
get_node("viewport").input(ev)
|
||||
|
||||
|
||||
|
||||
|
||||
func _ready():
|
||||
# Initalization here
|
||||
get_node("quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE, get_node("viewport").get_render_target_texture() )
|
||||
set_process_input(true)
|
||||
|
||||
pass
|
||||
|
||||
|
||||
BIN
demos/viewport/gui_in_3d/gui_3d.scn
Normal file
BIN
demos/viewport/gui_in_3d/gui_3d.scn
Normal file
Binary file not shown.
Reference in New Issue
Block a user