M apps/tfex/lib/tf.ex +13 -2
@@ 1,4 1,15 @@
defmodule Tfex.Tf do
- @moduledoc "Struct for a transform, defaulting to Local Tangent Plane"
- defstruct id: :ltp, transform: Tfex.id()
+ @moduledoc "Struct for a transform connecting two points."
+ defstruct id: nil,
+ parent: nil,
+ offset: Graphmath.Vec3.create(),
+ rotation: Graphmath.Quatern.identity()
+
+ def new(id, parent) do
+ %Tfex.Tf{id: id, parent: parent}
+ end
+
+ def new(id, parent, offset, rotation) do
+ %Tfex.Tf{id: id, parent: parent, offset: offset, rotation: rotation}
+ end
end
M apps/tfex/lib/tfex.ex +60 -20
@@ 1,37 1,77 @@
defmodule Tfex do
@moduledoc """
- Documentation for `Tfex`.
+ So what we really want isn't to handle single tf's, which are really pretty boring,
+ but handle sets of them. Our rules are that tf's are named, each name is a symbol, and each name corresponds to exactly one tf -- so really what we want is a map of them.
+
+ That means that really we don't care about *nodes* at all, nodes are basically
+ nothing. What we care about is the *links* between the nodes.
"""
- @doc """
- Hello world.
-
- ## Examples
-
- iex> Tfex.hello()
- :world
-
- """
- def hello do
- :world
- end
@doc "Return vector3 for position"
- def vec3(x,y,z) do
- Matrex.new([[x,y,z]])
+ def pos3(x,y,z) do
+ Graphmath.Vec3.create(x,y,z)
end
@doc "Return identity transform matrix."
def id() do
- Matrex.eye(3)
+ Graphmath.Mat44.identity()
+ end
+
+ @doc "Create a new set of TF's. We store it as a tuple of {node, parents, children} links so we can easily index into it or walk up or down the tree. Since each node only specifies its single parent, if any, we will always have zero or more well-formed trees in out TF set."
+ def tfs() do
+ {%{}, %{}, %{}}
+ end
+
+ @doc "Create new tf structure's from a list of Tf's"
+ def tfs(nodelist) do
+ nodes = Enum.reduce(nodelist, %{}, fn node, acc -> Map.put(acc, node.id, node) end)
+ parents = %{}
+ children = %{}
+ {nodes, parents, children}
end
- @doc "Create a translation matrix from the vector v"
- def translation(v) do
+ @doc """
+ Insert the given tf into the set, returning the new set.
+
+ TODO: how to handle duplicates? I think for now this doesn't allow
+ duplicates, trying to add another will
+ can't find a convenient function for it yet though.
+
+ TODO: Prevent loops/DAG's, this must be a strict tree.
+ """
+ def add(tfs, tf) do
+ {nodes, parents, children} = tfs
+ new_nodes = Map.put(nodes, tf.id, tf)
+ new_parents = Map.put(parents, tf.id, tf.parent)
+ # The children set is a map of %{id, MapSet} so we have to initialize it with
+ # a new mapset if it doesn't exist
+ children_for_node = Map.get_lazy(children, tf.parent, MapSet.new)
+ new_children =
+ Map.put(tfs, key, tf)
end
- @doc "Create a rotation matrix from the vector v -- oh fucking hell quaternions"
- def rotation(v) do
+ def move(tfs, tf) do
+ end
+
+ @doc """
+ The actual base lookup operation. Returns an offset and rotation that
+ will take you from the `from` point to the `to` point.
+ """
+ def get_relative(tfs, from, to) do
+ end
+
+ @doc """
+ Finds all the root nodes in the tf tree. If there are multiple roots, uh I guess we just diedie.
+ """
+ def roots(tfs, from, to) do
+ end
+
+
+ @doc """
+ Shitty name, but, sets the listed base_frame to be the origin and returns a new set of TF's relative to it.
+ """
+ def render(tfs, base_frame) do
end
end
M apps/tfex/mix.exs +2 -1
@@ 23,7 23,8 @@ defmodule Tfex.MixProject do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
- {:matrex, "~> 0.6.0"},
+ #{:matrex, "~> 0.6.0"},
+ {:graphmath, "~> 2.5.0"},
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false},
]
end
M apps/tfex/mix.lock +1 -0
@@ 2,5 2,6 @@
"dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"},
"elixir_make": {:hex, :elixir_make, "0.8.3", "d38d7ee1578d722d89b4d452a3e36bcfdc644c618f0d063b874661876e708683", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "5c99a18571a756d4af7a4d89ca75c28ac899e6103af6f223982f09ce44942cc9"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
+ "graphmath": {:hex, :graphmath, "2.5.0", "46b327a521260a287a05ba662fb666fd84e363bb005ee6428cf7504abe582b01", [:mix], [], "hexpm", "2406cc35ecb4793320433176c3dba77b000a74bf25bc79ad778b99f422a4ba7a"},
"matrex": {:hex, :matrex, "0.6.8", "ccb491e661bae7931ee6b0e68f5e1cd28528e5360a59bc3ab4d759b89be1701e", [:make], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "043ef9fdd9809b012568915f2fc396ea5c5631fd792f75c1148f03d478d60901"},
}