1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * Copyright (c) 2004-2013 HUBzero Foundation, LLC |
---|
4 | * |
---|
5 | * Authors: |
---|
6 | * Wei Qiao <qiaow@purdue.edu> |
---|
7 | */ |
---|
8 | |
---|
9 | // update velocity based on acceleration |
---|
10 | |
---|
11 | #include "common.cg" |
---|
12 | |
---|
13 | float4 main(in float2 uv : TEXCOORD0, |
---|
14 | uniform samplerRECT pos_tex, |
---|
15 | uniform samplerRECT vel_tex, |
---|
16 | uniform sampler2D terrain_tex, |
---|
17 | uniform float timestep = 0.01, |
---|
18 | uniform float damping = 0.99, |
---|
19 | uniform float3 gravity = float3(0, -1, 0), |
---|
20 | uniform float3 spherePos, |
---|
21 | uniform float3 sphereVel) : COLOR |
---|
22 | { |
---|
23 | const float3 terrain_scale = float3(8.0, 2.0, 8.0); |
---|
24 | const float3 terrain_offset = float3(-4.0, 0.01, -4.0); |
---|
25 | |
---|
26 | float3 pos = texRECT(pos_tex, uv).xyz; |
---|
27 | float3 vel = texRECT(vel_tex, uv).xyz; |
---|
28 | |
---|
29 | float3 pos_next = pos + vel * timestep; // predicted position next timestep |
---|
30 | |
---|
31 | float3 force = gravity; |
---|
32 | // float3 force = 0.0; |
---|
33 | // Gravitation(pos, spherePos, force, 0.1); |
---|
34 | |
---|
35 | SphereCollide(pos_next, vel, spherePos, 1.0, sphereVel, 0.5, force); |
---|
36 | // FloorCollide(pos_next, vel, 0.0, 0.5, force); |
---|
37 | TerrainCollide(pos_next, vel, terrain_tex, terrain_scale, terrain_offset, 0.5); |
---|
38 | |
---|
39 | const float inv_mass = 1.0; |
---|
40 | vel += force * inv_mass * timestep; // F = ma |
---|
41 | vel *= damping; |
---|
42 | |
---|
43 | return float4(vel, 1.0); |
---|
44 | } |
---|