Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions arcade/examples/gl/spritelist_interaction_bouncing_coins.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import arcade
from arcade.gl.types import BufferDescription
from arcade import hitbox

WINDOW_WIDTH = 800
WINDOW_HEIGHT = 600
Expand All @@ -31,10 +32,14 @@ def __init__(self):

# Generate lots of coins in random positions
self.coins = arcade.SpriteList(use_spatial_hash=None)
texture = arcade.load_texture(
":resources:images/items/coinGold.png",
hit_box_algorithm=hitbox.algo_bounding_box,
)
for _ in range(NUM_COINS):
self.coins.append(
arcade.Sprite(
":resources:images/items/coinGold.png",
texture,
scale=0.25,
center_x=randint(0, WINDOW_WIDTH),
center_y=randint(0, WINDOW_HEIGHT),
Expand All @@ -53,14 +58,14 @@ def __init__(self):
uniform float delta_time;
uniform vec2 size;

in vec2 in_pos;
in vec3 in_pos;
in vec2 in_vel;

out vec2 out_pos;
out vec3 out_pos;
out vec2 out_vel;

void main() {
vec2 pos = in_pos + in_vel * 100.0 * delta_time;
vec2 pos = in_pos.xy + in_vel * 100.0 * delta_time;
vec2 vel = in_vel;
if (pos.x > size.x) {
pos.x = size.x;
Expand All @@ -78,7 +83,7 @@ def __init__(self):
pos.y = 0.0;
vel.y *= -1.0;
}
out_pos = pos;
out_pos = vec3(pos, in_pos.z);
out_vel = vel;
}
""",
Expand All @@ -102,14 +107,14 @@ def __init__(self):
# Geometry input: Copied positions and first velocity buffer
self.geometry_1 = self.ctx.geometry(
[
BufferDescription(self.buffer_pos_copy, "2f", ["in_pos"]),
BufferDescription(self.buffer_pos_copy, "3f", ["in_pos"]),
BufferDescription(self.buffer_velocity_1, "2f", ["in_vel"]),
]
)
# Geometry input: Copied positions and second velocity buffer
self.geometry_2 = self.ctx.geometry(
[
BufferDescription(self.buffer_pos_copy, "2f", ["in_pos"]),
BufferDescription(self.buffer_pos_copy, "3f", ["in_pos"]),
BufferDescription(self.buffer_velocity_2, "2f", ["in_vel"]),
]
)
Expand Down
23 changes: 12 additions & 11 deletions arcade/examples/gl/spritelist_interaction_hijack_positions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""
import math
import arcade
from arcade import hitbox

NUM_COINS = 500

Expand All @@ -22,13 +23,12 @@ def __init__(self):
# Generate lots of coins. We don't care about the initial positions
# since our shader is setting those
self.coins = arcade.SpriteList()
texture = arcade.load_texture(
":resources:images/items/coinGold.png",
hit_box_algorithm=hitbox.algo_bounding_box,
)
for _ in range(NUM_COINS):
self.coins.append(
arcade.Sprite(
":resources:images/items/coinGold.png",
scale=0.5,
)
)
self.coins.append(arcade.Sprite(texture, scale=0.5))
# Ensure the internal buffers are up to date (size etc)
self.coins.write_sprite_buffers_to_gpu()

Expand All @@ -39,23 +39,24 @@ def __init__(self):

// The current time to add some movement
uniform float time;
// The bendyness value accelerating rotations
// The "bendyness" value accelerating rotations
uniform float bend;

// The current size of the screen
uniform vec2 size;

// The new positions we are writing into a new buffer
out vec2 out_pos;
out vec3 out_pos;

void main() {
// gl_VertexID is the sprite position in the spritelist.
// We can use that to value to create unique positions with
// some simple math.
float vertId = float(gl_VertexID);
out_pos = size / 2.0 + vec2(
out_pos = vec3(size, 0.0) / 2.0 + vec3(
sin(vertId + time + vertId * bend),
cos(vertId + time + vertId * bend)
cos(vertId + time + vertId * bend),
0.0
) * vertId;
}
"""
Expand All @@ -78,7 +79,7 @@ def on_update(self, delta_time: float):
self.time += delta_time
# Keep updating the current time to animation the movement
self.position_program["time"] = self.time / 4
# Update the bendyness value
# Update the "bendyness" value
self.position_program["bend"] = math.cos(self.time) / 400

def on_resize(self, width: int, height: int):
Expand Down
10 changes: 5 additions & 5 deletions arcade/examples/gl/spritelist_interaction_visualize_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ def __init__(self):
#version 330

// Sprite positions from SpriteList
in vec2 in_pos;
in vec3 in_pos;

// Output to geometry shader
out vec2 v_position;
out vec3 v_position;

void main() {
// This shader just forwards info to geo shader
Expand Down Expand Up @@ -80,16 +80,16 @@ def __init__(self):

// The position input from vertex shader.
// It's an array because geo shader can take more than one input
in vec2 v_position[];
in vec3 v_position[];

void main() {
// ONLY emit a line between the sprite and origin when within the distance
if (distance(v_position[0], origin) < maxDistance) {
if (distance(v_position[0].xy, origin) < maxDistance) {
// First line segment position (origin)
gl_Position = window.projection * window.view * vec4(origin, 0.0, 1.0);
EmitVertex();
// Second line segment position (sprite position)
gl_Position = window.projection * window.view * vec4(v_position[0], 0.0, 1.0);
gl_Position = window.projection * window.view * vec4(v_position[0].xy, 0.0, 1.0);
EmitVertex();
}
}
Expand Down
12 changes: 6 additions & 6 deletions arcade/examples/gl/spritelist_interaction_visualize_dist_los.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ def __init__(self):
#version 330

// Sprite positions from SpriteList
in vec2 in_pos;
in vec3 in_pos;

// Output to geometry shader
out vec2 v_position;
out vec3 v_position;

void main() {
// This shader just forwards info to geo shader
Expand Down Expand Up @@ -105,7 +105,7 @@ def __init__(self):

// The position input from vertex shader.
// It's an array because geo shader can take more than one input
in vec2 v_position[];
in vec3 v_position[];

// Helper function converting screen coordinates to texture coordinates.
// Texture coordinates are normalized (0.0 -> 1.0) were 0,0 is in the
Expand All @@ -115,13 +115,13 @@ def __init__(self):

void main() {
// ONLY emit a line between the sprite and origin when within the distance
if (distance(v_position[0], origin) > maxDistance) return;
if (distance(v_position[0].xy, origin) > maxDistance) return;

// Read samples from the wall texture in a line looking for obstacles
// We simply make a vector between the original and the sprite location
// and trace pixels in this path with a reasonable step.
int numSteps = int(maxDistance / 2.0);
vec2 dir = v_position[0] - origin;
vec2 dir = v_position[0].xy - origin;
for (int i = 0; i < numSteps; i++) {
// Read pixels along the vector
vec2 pos = origin + dir * (float(i) / float(numSteps));
Expand All @@ -134,7 +134,7 @@ def __init__(self):
gl_Position = window.projection * window.view * vec4(origin, 0.0, 1.0);
EmitVertex();
// Second line segment position (sprite position)
gl_Position = window.projection * window.view * vec4(v_position[0], 0.0, 1.0);
gl_Position = window.projection * window.view * vec4(v_position[0].xy, 0.0, 1.0);
EmitVertex();
EndPrimitive();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ def __init__(self):
#version 330

// Sprite positions from SpriteList
in vec2 in_pos;
in vec3 in_pos;

// Output to geometry shader
out vec2 v_position;
out vec3 v_position;

void main() {
// This shader just forwards info to geo shader
Expand All @@ -107,7 +107,7 @@ def __init__(self):

// The position input from vertex shader.
// It's an array because geo shader can take more than one input
in vec2 v_position[];
in vec3 v_position[];
// This shader outputs all the sprite indices it selected.
// NOTE: We use floats here for compatibility since integers are always working
out float spriteIndex;
Expand All @@ -120,13 +120,13 @@ def __init__(self):

void main() {
// ONLY emit a line between the sprite and origin when within the distance
if (distance(v_position[0], origin) > maxDistance) return;
if (distance(v_position[0].xy, origin) > maxDistance) return;

// Read samples from the wall texture in a line looking for obstacles
// We simply make a vector between the original and the sprite location
// and trace pixels in this path with a reasonable step.
int numSteps = int(maxDistance / 2.0);
vec2 dir = v_position[0] - origin;
vec2 dir = v_position[0].xy - origin;
for (int i = 0; i < numSteps; i++) {
// Read pixels along the vector
vec2 pos = origin + dir * (float(i) / float(numSteps));
Expand Down
12 changes: 6 additions & 6 deletions arcade/experimental/shapes_buffered_2_glow.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, width, height, title):
"""
super().__init__(width, height, title)

self.shape_list = arcade.ShapeElementList()
self.shape_list = arcade.shape_list.ShapeElementList()
self.shape_list.center_x = SCREEN_WIDTH // 2
self.shape_list.center_y = SCREEN_HEIGHT // 2
self.shape_list.angle = 0
Expand All @@ -52,7 +52,7 @@ def __init__(self, width, height, title):
color = random.choice(colors)
points = [(px + x, py + y) for px, py in point_list]

my_line_strip = arcade.create_line_strip(points, color, 5)
my_line_strip = arcade.shape_list.create_line_strip(points, color, 5)
self.shape_list.append(my_line_strip)

point_list = ((-50, -50),
Expand All @@ -62,7 +62,7 @@ def __init__(self, width, height, title):
x = SCREEN_WIDTH // 2 - random.randrange(SCREEN_WIDTH - 50)
y = SCREEN_HEIGHT // 2 - random.randrange(SCREEN_HEIGHT - 50)
points = [(px + x, py + y) for px, py in point_list]
triangle_filled = arcade.create_triangles_filled_with_colors(
triangle_filled = arcade.shape_list.create_triangles_filled_with_colors(
points,
random.sample(colors, 3)
)
Expand All @@ -76,7 +76,7 @@ def __init__(self, width, height, title):
x = SCREEN_WIDTH // 2 - random.randrange(SCREEN_WIDTH - 50)
y = SCREEN_HEIGHT // 2 - random.randrange(SCREEN_HEIGHT - 50)
points = [(px + x, py + y) for px, py in point_list]
rect_filled = arcade.create_rectangle_filled_with_colors(
rect_filled = arcade.shape_list.create_rectangle_filled_with_colors(
points,
random.sample(colors, 4)
)
Expand All @@ -88,10 +88,10 @@ def __init__(self, width, height, title):
(200, 200),
(250, 150),
(200, 100))
poly = arcade.create_polygon(point_list, (255, 10, 10))
poly = arcade.shape_list.create_polygon(point_list, (255, 10, 10))
self.shape_list.append(poly)

ellipse = arcade.create_ellipse(20, 30, 50, 20, (230, 230, 0))
ellipse = arcade.shape_list.create_ellipse(20, 30, 50, 20, (230, 230, 0))
self.shape_list.append(ellipse)

self.background_color = arcade.color.BLACK
Expand Down
5 changes: 3 additions & 2 deletions arcade/experimental/shapes_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import random

import arcade
from arcade.types import NamedPoint

SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
Expand Down Expand Up @@ -89,12 +90,12 @@ def __init__(self, width, height, title):

# line strip
self.line_strip = [
arcade.NamedPoint(random.randint(0, SCREEN_WIDTH), random.randint(0, SCREEN_HEIGHT))
NamedPoint(random.randint(0, SCREEN_WIDTH), random.randint(0, SCREEN_HEIGHT))
for _ in range(10)
]
# Random list of points
self.points = [
arcade.NamedPoint(random.randint(0, SCREEN_WIDTH), random.randint(0, SCREEN_HEIGHT))
NamedPoint(random.randint(0, SCREEN_WIDTH), random.randint(0, SCREEN_HEIGHT))
for _ in range(10_000)
]

Expand Down
31 changes: 31 additions & 0 deletions arcade/experimental/sprite_depth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import math
import arcade


class MyGame(arcade.Window):

def __init__(self):
super().__init__(800, 600, "Sprite Depth")
self.sprite_list = arcade.SpriteList()
texture = arcade.load_texture(":resources:images/test_textures/xy_square.png")
self.time = 0.0

for i in range(10):
sprite = arcade.Sprite(texture, center_x=150 + 50 * i, center_y=300)
self.sprite_list.append(sprite)

def on_draw(self):
self.clear()
with self.ctx.enabled(self.ctx.DEPTH_TEST):
self.sprite_list.draw()

for i, sprite in enumerate(self.sprite_list):
arcade.draw_point(150 + 50 * i, 300 + sprite.depth, arcade.color.WHITE, 10)

def on_update(self, delta_time):
self.time += delta_time
for i, sprite in enumerate(self.sprite_list):
sprite.depth = math.cos(self.time + i) * 50


MyGame().run()
4 changes: 2 additions & 2 deletions arcade/resources/shaders/collision/col_trans_vs.glsl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#version 330
// A simple passthrough shader forwarding data to the geomtry shader

in vec2 in_pos;
in vec3 in_pos;
in vec2 in_size;

out vec2 pos;
out vec2 size;

void main() {
pos = in_pos;
pos = in_pos.xy;
size = in_size;
}
Loading