Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

silly variable macro expansion

  • Loading branch information...
commit 1b2ab15effdd8232f07ca89221078785581af74b 1 parent 1cd23e0
James Halliday authored
Showing with 28 additions and 9 deletions.
  1. +18 −0 Makefile
  2. +3 −6 hw/3/Main.hs
  3. +7 −3 hw/proj1/Main.hs
18 Makefile
View
@@ -72,6 +72,24 @@ hw3i:
lib/Graphics/UI/Simulation3D/Navigator.hs \
lib/Graphics/UI/Simulation3D/Shader.hs \
+proj1:
+ ghc --make -threaded -o hw3 \
+ hw/proj1/Main.hs \
+ lib/Graphics/UI/Simulation3D.hs \
+ lib/Graphics/UI/Simulation3D/Base.hs \
+ lib/Graphics/UI/Simulation3D/Util.hs \
+ lib/Graphics/UI/Simulation3D/Navigator.hs \
+ lib/Graphics/UI/Simulation3D/Shader.hs \
+
+proj1i:
+ ghci \
+ hw/proj1/Main.hs \
+ lib/Graphics/UI/Simulation3D.hs \
+ lib/Graphics/UI/Simulation3D/Base.hs \
+ lib/Graphics/UI/Simulation3D/Util.hs \
+ lib/Graphics/UI/Simulation3D/Navigator.hs \
+ lib/Graphics/UI/Simulation3D/Shader.hs \
+
clean:
rm -f hw1 hw2
find -name \*.hi -exec rm {} \;
9 hw/3/Main.hs
View
@@ -18,9 +18,8 @@ instance Simulation EllipsoidSim where
display = do
prog <- simShader <$> getSimulation
- [x,y,z,w] <- map (!! 3) . toLists . inv . cameraMatrix <$> getCamera
+ --[x,y,z,_] <- map (!! 3) . toLists . inv . cameraMatrix <$> getCamera
--liftIO $ bindProgram prog "camera" $ vertex3f x y z
- --liftIO $ withProgram prog $ preservingMatrix $ do
liftIO $ withProgram prog $ preservingMatrix $ do
renderObject Solid $ Sphere' 1.5 6 6
@@ -69,11 +68,11 @@ fragmentShader = [$here|
);
float c_ = (a * C.x * C.x) + (b * C.y * C.y) + (c * C.z * C.z) - k;
- float t = -1.0; // default to non-real answer
if (b_ * b_ < 4.0 * a_ * c_) discard;
float t1 = (-b_ + sqrt(b_ * b_ - 4.0 * a_ * c_)) / (2.0 * a_);
float t2 = (-b_ - sqrt(b_ * b_ - 4.0 * a_ * c_)) / (2.0 * a_);
+ float t;
if (t1 >= 0.0 && t2 >= 0.0) {
t = min(t1,t2); // two solutions, pick nearest
}
@@ -85,16 +84,14 @@ fragmentShader = [$here|
//vec3 norm = normalize(vec3(2 * point.x, 2 * point.y, 2 * point.z));
//vec4 proj = gl_ProjectionMatrix * vec4(vec3(point),1.0);
//gl_FragDepth = 0.1; // 0.5 + 0.5 * (proj.z / proj.w);
-
//gl_FragColor = vec4(norm, 1.0);
- gl_FragColor = vec4(point, 1.0);
+ gl_FragColor = vec4(t1 > 0.0 ? 1.0 : 0.0, t2 > 0.0 ? 1.0 : 0.0, 0.0, 1.0);
}
|]
drawFloor :: HookIO EllipsoidSim ()
drawFloor = do
texPtr <- checkerTex <$> getSimulation
-
liftIO $ do
tex : [] <- genObjectNames 1
textureBinding Texture2D $= Just tex
10 hw/proj1/Main.hs
View
@@ -53,15 +53,18 @@ fragmentShader = [$here|
varying vec3 camera;
varying vec3 offset;
- #define surface(C,D,x) \
- C.x + x * x + D.x * (x + 1)
+ #define surface(C,D,T) \
+ C.x + T
void main() {
// P(t) = C + t * D, t >= 0
vec3 C = camera;
vec3 D = offset;
- float tn_prev = 0, tn = 1, v;
+ float tn_prev = 0.0;
+ float tn = 1.0;
+ float v;
+
for (int i = 0; i < 4; i++) {
float s = surface(C,D,tn);
float sp = surface(C,D,tn_prev);
@@ -69,6 +72,7 @@ fragmentShader = [$here|
tn_prev = tn;
tn = tn - v;
}
+
if (abs(v) > 0.01) discard;
vec3 point = C + tn * D; // point of intersection
Please sign in to comment.
Something went wrong with that request. Please try again.