Commits

Sebastien Mondet committed 965cfd5

webpdb: draw a list of translated/scaled spheres

Comments (0)

Files changed (1)

 open Lwt
 open Js
+module List = ListLabels
+module Array = ArrayLabels
 
 let error f =
   Printf.ksprintf (fun s -> Firebug.console##error (Js.string s); failwith s) f
 
   end
 
-  let start (pos,norm) =
+  type scene_object =
+    | Sphere of (float array * float) (* position, scale *)
+
+  type scene = scene_object list
+
+  let sphere ~position ~scale = Sphere (position, scale)
+
+  let start scene =
     let fps_text = Dom_html.document##createTextNode (Js.string "loading") in
     Opt.iter
       (Opt.bind ( Dom_html.document##getElementById(string "fps") )
     gl##uniform3fv_typed(lightPos_loc, lightPos);
     gl##uniform3fv_typed(ambientLight_loc, ambientLight);
 
+
+    (* Load scene: *)
+    let arrays =
+      List.map scene ~f:(function
+        | Sphere (position, scale) ->
+          let scaled_and_translated =
+            Array.mapi Data.sphere_vertices ~f:(fun i coord ->
+                let kind_of_coord = i mod 3 in
+                (coord *. scale) +. position.(kind_of_coord)) in
+          scaled_and_translated, Data.sphere_vertices)
+    in
+    let pos = float32array (Array.concat (List.map arrays ~f:fst)) in
+    let norm = float32array (Array.concat (List.map arrays ~f:snd)) in
     let pos_attr = gl##getAttribLocation(prog, string "a_position") in
     gl##enableVertexAttribArray(pos_attr);
 
     gl##bindBuffer(gl##_ARRAY_BUFFER_,array_buffer);
     gl##bufferData(gl##_ARRAY_BUFFER_,pos,gl##_STATIC_DRAW_);
     gl##vertexAttribPointer(pos_attr, 3, gl##_FLOAT, _false, 0, 0);
-
     let norm_attr = gl##getAttribLocation(prog, string "a_normal") in
     gl##enableVertexAttribArray(norm_attr);
 
     gl##bufferData(gl##_ARRAY_BUFFER_,norm,gl##_STATIC_DRAW_);
     gl##vertexAttribPointer(norm_attr, 3, gl##_FLOAT, _false, 0, 0);
 
+
     let pi = 4. *. (atan 1.) in
     let mat =
       Proj3D.(
       debug "START !";
       fetch_model  "http://www.pdb.org/pdb/files/4IS8.pdb"
       >>= fun _ ->
-      let pos =
-        Renderer.float32array Data.sphere_vertices in
-      let norm =
-        Renderer.float32array Data.sphere_vertices in
-      Renderer.start (pos, norm)
+      Renderer.start [
+        Renderer.sphere ~position:[| 0.; 0.; 0.|] ~scale:0.4;
+        Renderer.sphere ~position:[| 0.; 1.; 0.|] ~scale:0.6;
+      ]
     end
     (fun exn -> error "uncaught exception: %s" (Printexc.to_string exn)));
   _true
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.