wtc-math+wtc-gl实现篮球高尔夫网球重力下落碰撞动画效果代码
代码语言:html
所属分类:动画
代码描述:wtc-math+wtc-gl实现篮球高尔夫网球重力下落碰撞动画效果代码,篮球定在空中挡住高尔夫与网球的下落。
代码标签: wtc-math wtc-gl 篮球 高尔夫 网球 重力 下落 碰撞 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
body {
background: linear-gradient(#001122, #001122, #334455);
margin:0;
overflow:hidden;
}
canvas {
max-width: 100vw;
}
</style>
</head>
<body>
<script type="x-shader/vertex" id="vert">#version 300 es
in vec3 position;
in vec3 normal;
in vec2 uv;
in float index;
in vec2 offset;
in vec2 scale;
in float type;
out vec2 vUv;
out float vType;
uniform vec2 u_resolution;
vec2 getScreenSpace(vec2 p) {
vec2 uv = (p - 0.5 * u_resolution.xy) / min(u_resolution.y, u_resolution.x);
return uv;
}
void main() {
vec2 vuv = getScreenSpace(position.xy);
float a = scale.y;
float s = sin(a);
float c = cos(a);
vUv = uv;
vType = mod(type, 3.);
// gl_Position = vec4(position.xy * scale.x + offset, 0, 0);
vec2 pos = position.xy * mat2(c,-s,s,c);
gl_Position = vec4(pos/u_resolution * scale.x + offset/u_resolution, .5, 1);
}
</script>
<script type="x-shader/fragment" id="frag">#version 300 es
precision highp float;
in vec2 vUv;
in float vType;
uniform sampler2D s_ball1;
uniform sampler2D s_ball2;
uniform sampler2D s_ball3;
out vec4 col;
void main() {
col = vec4(smoothstep(0.01, 0., length(vUv-.5) - .495));
if(vType == 0.) col = texture(s_ball1, vUv);
else if(vType == 1.) col = texture(s_ball2, vUv);
else if(vType == 2.) col = texture(s_ball3, vUv);
col *= col.a;
// col = vec4(vUv, 1., 1.);
}
</script>
<script type="module">
import { Renderer, Drawable, Texture, Program, Plane, Geometry, GeometryAttribute, Mesh, Uniform } from "//repo.bfw.wiki/bfwrepo/js/module/wtc-gl.1.0.0-beta.49.js";
import { Vec2 } from "//repo.bfw.wiki/bfwrepo/js/module/wtc-math.1.0.17.js";
console.clear();
// Initialize global properties
const p = new Vec2(); // window size
const g = new Vec2(0, -1); // gravity
const num = 1000; // The number of instances
// Create the renderer and add it to the document
const r = new Renderer({ dpr: 2, premultipliedAlpha: true, alpha: true });
const gl = r.gl;
document.body.appendChild(gl.canvas);
// Create the uniforms array
const uniforms = {
'u_resolution': new Uniform({ name: 'resolution', value: r.dimensions.array }) };
// Handle window resize
const resize = e => {
p.reset(window.innerWidth, window.innerHeight);
r.dimensions = new Vec2(window.innerWidth, window.innerHeight);
uniforms.u_resolution.value = p.array;
};
window.addEventListener('resize', resize);
resize();
// Create the scene, this is the thing that we render
const scene = new Drawable(gl);
// In.........完整代码请登录后点击上方下载按钮下载查看
网友评论0