<commit_before>(ns minimal-3d-physics.core
  (:require [play-clj.core :refer :all]
            [play-clj.g3d :refer :all]
            [play-clj.g3d-physics :refer :all]
            [play-clj.math :refer :all]
            [play-clj.ui :refer :all]))

(def ^:const mass 10)

(defn get-material
  []
  (let [c (color (+ 0.5 (* 0.5 (rand)))
                 (+ 0.5 (* 0.5 (rand)))
                 (+ 0.5 (* 0.5 (rand)))
                 1)]
    (material :set (attribute! :color :create-specular 1 1 1 1)
              :set (attribute! :float :create-shininess 8)
              :set (attribute! :color :create-diffuse c))))

(defn get-attrs
  []
  (bit-or (usage :position) (usage :normal)))

(defn create-sphere-body!
  [screen]
  (let [shape (sphere-shape 2)
        local-inertia (vector-3 0 0 0)]
    (sphere-shape! shape :calculate-local-inertia mass local-inertia)
    (->> (rigid-body-info mass nil shape local-inertia)
         rigid-body
         (add-body! screen))))

(defn create-sphere!
  [screen mat attrs]
  (-> (model-builder)
      (model-builder! :create-sphere 4 4 4 24 24 mat attrs)
      model
      (assoc :body (create-sphere-body! screen))))

(defn create-box-body!
  [screen]
  (let [shape (box-shape (vector-3 2 2 1))
        local-inertia (vector-3 0 0 0)]
    (box-shape! shape :calculate-local-inertia mass local-inertia)
    (->> (rigid-body-info mass nil shape local-inertia)
         rigid-body
         (add-body! screen))))

(defn create-box!
  [screen mat attrs]
  (-> (model-builder)
      (model-builder! :create-box 4 4 2 mat attrs)
      model
      (assoc :body (create-box-body! screen))))

(defscreen main-screen
  :on-show
  (fn [screen entities]
    (let [env (let [attr-type (attribute-type :color :ambient-light)
                    attr (attribute :color attr-type 0.3 0.3 0.3 1)]
                (environment :set attr))
          cam (doto (perspective 67 (game :width) (game :height))
                (position! 10 10 10)
                (direction! 0 0 0))
          screen (update! screen
                          :renderer (model-batch)
                          :world (bullet-3d :discrete-dynamics
                                            :set-gravity (vector-3 0 -10 0))
                          :attributes env
                          :camera cam)]
      [(doto (create-sphere! screen (get-material) (get-attrs))
         (body-position! 0 5 5))
       (doto (create-box! screen (get-material) (get-attrs))
         (body-position! 0 5 0))]))
  :on-render
  (fn [screen entities]
    (clear!)
    (->> entities
         (render! screen)
         (step! screen)))
  :on-resize
  (fn [{:keys [width height] :as screen} entities]
    (size! screen width height))
  :on-touch-down
  (fn [{:keys [x y] :as screen} entities]
    (conj entities (create-box! screen (get-material) (get-attrs)))))
<commit_msg>Move step! function<commit_after>(ns minimal-3d-physics.core
  (:require [play-clj.core :refer :all]
            [play-clj.g3d :refer :all]
            [play-clj.g3d-physics :refer :all]
            [play-clj.math :refer :all]
            [play-clj.ui :refer :all]))

(def ^:const mass 10)

(defn get-material
  []
  (let [c (color (+ 0.5 (* 0.5 (rand)))
                 (+ 0.5 (* 0.5 (rand)))
                 (+ 0.5 (* 0.5 (rand)))
                 1)]
    (material :set (attribute! :color :create-specular 1 1 1 1)
              :set (attribute! :float :create-shininess 8)
              :set (attribute! :color :create-diffuse c))))

(defn get-attrs
  []
  (bit-or (usage :position) (usage :normal)))

(defn create-sphere-body!
  [screen]
  (let [shape (sphere-shape 2)
        local-inertia (vector-3 0 0 0)]
    (sphere-shape! shape :calculate-local-inertia mass local-inertia)
    (->> (rigid-body-info mass nil shape local-inertia)
         rigid-body
         (add-body! screen))))

(defn create-sphere!
  [screen mat attrs]
  (-> (model-builder)
      (model-builder! :create-sphere 4 4 4 24 24 mat attrs)
      model
      (assoc :body (create-sphere-body! screen))))

(defn create-box-body!
  [screen]
  (let [shape (box-shape (vector-3 2 2 1))
        local-inertia (vector-3 0 0 0)]
    (box-shape! shape :calculate-local-inertia mass local-inertia)
    (->> (rigid-body-info mass nil shape local-inertia)
         rigid-body
         (add-body! screen))))

(defn create-box!
  [screen mat attrs]
  (-> (model-builder)
      (model-builder! :create-box 4 4 2 mat attrs)
      model
      (assoc :body (create-box-body! screen))))

(defscreen main-screen
  :on-show
  (fn [screen entities]
    (let [env (let [attr-type (attribute-type :color :ambient-light)
                    attr (attribute :color attr-type 0.3 0.3 0.3 1)]
                (environment :set attr))
          cam (doto (perspective 67 (game :width) (game :height))
                (position! 10 10 10)
                (direction! 0 0 0))
          screen (update! screen
                          :renderer (model-batch)
                          :world (bullet-3d :discrete-dynamics
                                            :set-gravity (vector-3 0 -10 0))
                          :attributes env
                          :camera cam)]
      [(doto (create-sphere! screen (get-material) (get-attrs))
         (body-position! 0 5 5))
       (doto (create-box! screen (get-material) (get-attrs))
         (body-position! 0 5 0))]))
  :on-render
  (fn [screen entities]
    (clear!)
    (->> entities
         (step! screen)
         (render! screen)))
  :on-resize
  (fn [{:keys [width height] :as screen} entities]
    (size! screen width height))
  :on-touch-down
  (fn [{:keys [x y] :as screen} entities]
    (conj entities (create-box! screen (get-material) (get-attrs)))))

{'fraction_non_alphanumeric': 0.14956369982547993, 'fraction_numerical': 0.026527050610820245, 'mean_word_length': 1.9495625321667525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7487388', 'n_tokens_mistral': 2028, 'n_tokens_neox': 1905, 'n_words': 532}