\hypertarget{group__EPhysics__Shape}{\section{E\+Physics Shape}
\label{group__EPhysics__Shape}\index{E\+Physics Shape@{E\+Physics Shape}}
}


Shapes are used to create bodies with shapes that differ from primitive ones, like box and cylinder.  


\subsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
typedef struct \+\_\+\+E\+Physics\+\_\+\+Shape \hyperlink{group__EPhysics__Shape_gadfcc565af1b4e898f2959292a9089e7e}{E\+Physics\+\_\+\+Shape}
\begin{DoxyCompactList}\small\item\em Shape handle, represents a shape to be used to create a body. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{group__Eina__Types__Group_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+P\+I} \hyperlink{group__EPhysics__Shape_gadfcc565af1b4e898f2959292a9089e7e}{E\+Physics\+\_\+\+Shape} $\ast$ \hyperlink{group__EPhysics__Shape_ga79ca252f9b15296416c3f73c75efa293}{ephysics\+\_\+shape\+\_\+new} (void)
\begin{DoxyCompactList}\small\item\em Create a new shape. \end{DoxyCompactList}\item 
\hyperlink{group__Eina__Types__Group_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+P\+I} void \hyperlink{group__EPhysics__Shape_ga9d91574e5cdac7772d6c75c22c32d8a7}{ephysics\+\_\+shape\+\_\+del} (\hyperlink{group__EPhysics__Shape_gadfcc565af1b4e898f2959292a9089e7e}{E\+Physics\+\_\+\+Shape} $\ast$shape)
\begin{DoxyCompactList}\small\item\em Delete a shape. \end{DoxyCompactList}\item 
\hyperlink{group__Eina__Types__Group_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+P\+I} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\+\_\+\+Bool} \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\+\_\+shape\+\_\+point\+\_\+add} (\hyperlink{group__EPhysics__Shape_gadfcc565af1b4e898f2959292a9089e7e}{E\+Physics\+\_\+\+Shape} $\ast$shape, double x, double y, double z)
\begin{DoxyCompactList}\small\item\em Add a new point to the shape. \end{DoxyCompactList}\item 
\hyperlink{group__Eina__Types__Group_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+P\+I} \hyperlink{group__EPhysics__Shape_gadfcc565af1b4e898f2959292a9089e7e}{E\+Physics\+\_\+\+Shape} $\ast$ \hyperlink{group__EPhysics__Shape_ga63339f80d1692ed327238cab5ef7f2a7}{ephysics\+\_\+shape\+\_\+load} (const char $\ast$filename)
\begin{DoxyCompactList}\small\item\em Load the shape from a file. \end{DoxyCompactList}\item 
\hyperlink{group__Eina__Types__Group_ga3db3556eec8ef18cb8ddb43816974ac8}{E\+A\+P\+I} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\+\_\+\+Bool} \hyperlink{group__EPhysics__Shape_ga60c974e4692ed765e0b7ba2e8a5d9819}{ephysics\+\_\+shape\+\_\+save} (const \hyperlink{group__EPhysics__Shape_gadfcc565af1b4e898f2959292a9089e7e}{E\+Physics\+\_\+\+Shape} $\ast$shape, const char $\ast$filename)
\begin{DoxyCompactList}\small\item\em Save the shape to a file. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Shapes are used to create bodies with shapes that differ from primitive ones, like box and cylinder. 

A shape consists in a group of points, the vertices of the body to be created later with \hyperlink{group__EPhysics__Body_gabe733ecf3e04d267005118ff7291daab}{ephysics\+\_\+body\+\_\+shape\+\_\+add()}.

A new shape is created with \hyperlink{group__EPhysics__Shape_ga79ca252f9b15296416c3f73c75efa293}{ephysics\+\_\+shape\+\_\+new()} and points are set with \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\+\_\+shape\+\_\+point\+\_\+add()}. A shape can be used to create many bodies. When done, it's required to delete the shape with \hyperlink{group__EPhysics__Shape_ga9d91574e5cdac7772d6c75c22c32d8a7}{ephysics\+\_\+shape\+\_\+del()}.

A shape can be loaded from a file describing it with \hyperlink{group__EPhysics__Shape_ga63339f80d1692ed327238cab5ef7f2a7}{ephysics\+\_\+shape\+\_\+load()}, and can be saved to a file with \hyperlink{group__EPhysics__Shape_ga60c974e4692ed765e0b7ba2e8a5d9819}{ephysics\+\_\+shape\+\_\+save()}. With that shapes can be done or visualized on design applications.

\begin{DoxyNote}{Note}
Using primitive shapes has better perfomance than generic shapes. 

For now, only convex shapes are supported. 
\end{DoxyNote}


\subsection{Typedef Documentation}
\hypertarget{group__EPhysics__Shape_gadfcc565af1b4e898f2959292a9089e7e}{\index{E\+Physics Shape@{E\+Physics Shape}!E\+Physics\+\_\+\+Shape@{E\+Physics\+\_\+\+Shape}}
\index{E\+Physics\+\_\+\+Shape@{E\+Physics\+\_\+\+Shape}!E\+Physics Shape@{E\+Physics Shape}}
\subsubsection[{E\+Physics\+\_\+\+Shape}]{\setlength{\rightskip}{0pt plus 5cm}{\bf E\+Physics\+\_\+\+Shape}}}\label{group__EPhysics__Shape_gadfcc565af1b4e898f2959292a9089e7e}


Shape handle, represents a shape to be used to create a body. 

Created with \hyperlink{group__EPhysics__Shape_ga79ca252f9b15296416c3f73c75efa293}{ephysics\+\_\+shape\+\_\+new()} and deleted with \hyperlink{group__EPhysics__Shape_ga9d91574e5cdac7772d6c75c22c32d8a7}{ephysics\+\_\+shape\+\_\+del()}. 

\subsection{Function Documentation}
\hypertarget{group__EPhysics__Shape_ga79ca252f9b15296416c3f73c75efa293}{\index{E\+Physics Shape@{E\+Physics Shape}!ephysics\+\_\+shape\+\_\+new@{ephysics\+\_\+shape\+\_\+new}}
\index{ephysics\+\_\+shape\+\_\+new@{ephysics\+\_\+shape\+\_\+new}!E\+Physics Shape@{E\+Physics Shape}}
\subsubsection[{ephysics\+\_\+shape\+\_\+new}]{\setlength{\rightskip}{0pt plus 5cm}{\bf E\+A\+P\+I} {\bf E\+Physics\+\_\+\+Shape}$\ast$ ephysics\+\_\+shape\+\_\+new (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}\label{group__EPhysics__Shape_ga79ca252f9b15296416c3f73c75efa293}


Create a new shape. 

The returned shape initially doesn't has points set, so it's required to set vertices with \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\+\_\+shape\+\_\+point\+\_\+add()}.

After the shape is completely defined, all the points were added, it's possible to create one or more bodies with \hyperlink{group__EPhysics__Body_gabe733ecf3e04d267005118ff7291daab}{ephysics\+\_\+body\+\_\+shape\+\_\+add()}.

\begin{DoxyReturn}{Returns}
The created shape or {\ttfamily N\+U\+L\+L} on error.
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__EPhysics__Shape_ga9d91574e5cdac7772d6c75c22c32d8a7}{ephysics\+\_\+shape\+\_\+del()}. 

\hyperlink{group__EPhysics__Shape_ga63339f80d1692ed327238cab5ef7f2a7}{ephysics\+\_\+shape\+\_\+load()}. 
\end{DoxySeeAlso}
\begin{Desc}
\item[Examples\+: ]\par
\hyperlink{test_shapes_8c-example}{test\+\_\+shapes.\+c}.\end{Desc}
\hypertarget{group__EPhysics__Shape_ga9d91574e5cdac7772d6c75c22c32d8a7}{\index{E\+Physics Shape@{E\+Physics Shape}!ephysics\+\_\+shape\+\_\+del@{ephysics\+\_\+shape\+\_\+del}}
\index{ephysics\+\_\+shape\+\_\+del@{ephysics\+\_\+shape\+\_\+del}!E\+Physics Shape@{E\+Physics Shape}}
\subsubsection[{ephysics\+\_\+shape\+\_\+del}]{\setlength{\rightskip}{0pt plus 5cm}{\bf E\+A\+P\+I} void ephysics\+\_\+shape\+\_\+del (
\begin{DoxyParamCaption}
\item[{{\bf E\+Physics\+\_\+\+Shape} $\ast$}]{shape}
\end{DoxyParamCaption}
)}}\label{group__EPhysics__Shape_ga9d91574e5cdac7772d6c75c22c32d8a7}


Delete a shape. 

After a shape is used to create the wanted bodies, it's required to delete it. It won't be deleted automatically by ephysics at any point, even on shutdown. The creator is responsible to free it after usage is concluded.


\begin{DoxyParams}{Parameters}
{\em shape} & The shape to be deleted.\\
\hline
\end{DoxyParams}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__EPhysics__Shape_ga79ca252f9b15296416c3f73c75efa293}{ephysics\+\_\+shape\+\_\+new()}. 
\end{DoxySeeAlso}
\begin{Desc}
\item[Examples\+: ]\par
\hyperlink{test_shapes_8c-example}{test\+\_\+shapes.\+c}.\end{Desc}
\hypertarget{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{\index{E\+Physics Shape@{E\+Physics Shape}!ephysics\+\_\+shape\+\_\+point\+\_\+add@{ephysics\+\_\+shape\+\_\+point\+\_\+add}}
\index{ephysics\+\_\+shape\+\_\+point\+\_\+add@{ephysics\+\_\+shape\+\_\+point\+\_\+add}!E\+Physics Shape@{E\+Physics Shape}}
\subsubsection[{ephysics\+\_\+shape\+\_\+point\+\_\+add}]{\setlength{\rightskip}{0pt plus 5cm}{\bf E\+A\+P\+I} {\bf Eina\+\_\+\+Bool} ephysics\+\_\+shape\+\_\+point\+\_\+add (
\begin{DoxyParamCaption}
\item[{{\bf E\+Physics\+\_\+\+Shape} $\ast$}]{shape, }
\item[{double}]{x, }
\item[{double}]{y, }
\item[{double}]{z}
\end{DoxyParamCaption}
)}}\label{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}


Add a new point to the shape. 

Any point can be added to a shape, but only vertices matter. A vertex is a special kind of point that describes a corner of geometric shapes. The final shape will be constructed in such a way it will have all the added points and will be convex.

The center of mass will be the centroid, or geometric center of the shape.

The order of points doesn't matter.

For example, to create a pentagon\+:


\begin{DoxyCode}
1 EPhysics\_Shape *shape = ephysics\_shape\_new();
2 
3 ephysics\_shape\_point\_add(shape, 0, 24, -10);
4 ephysics\_shape\_point\_add(shape, 0, 24, 10);
5 ephysics\_shape\_point\_add(shape, 35, 0, -10);
6 ephysics\_shape\_point\_add(shape, 35, 0, 10);
7 ephysics\_shape\_point\_add(shape, 70, 24, -10);
8 ephysics\_shape\_point\_add(shape, 70, 24, 10);
9 ephysics\_shape\_point\_add(shape, 56, 66, -10);
10 ephysics\_shape\_point\_add(shape, 56, 66, 10);
11 ephysics\_shape\_point\_add(shape, 14, 66, -10);
12 ephysics\_shape\_point\_add(shape, 14, 66, 10);
13 
14 ephysics\_body\_shape\_add(world, shape);
15 
16 ephysics\_shape\_del(shape);
\end{DoxyCode}



\begin{DoxyParams}{Parameters}
{\em shape} & The shape to be modified. \\
\hline
{\em x} & Point position at x axis. \\
\hline
{\em y} & Point position at y axis. \\
\hline
{\em z} & Point position at z axis. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
{\ttfamily E\+I\+N\+A\+\_\+\+T\+R\+U\+E} on success or E\+I\+N\+A\+\_\+\+F\+A\+L\+S\+E on error.
\end{DoxyReturn}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__EPhysics__Shape_ga79ca252f9b15296416c3f73c75efa293}{ephysics\+\_\+shape\+\_\+new()}. 
\end{DoxySeeAlso}
\begin{Desc}
\item[Examples\+: ]\par
\hyperlink{test_shapes_8c-example}{test\+\_\+shapes.\+c}.\end{Desc}
\hypertarget{group__EPhysics__Shape_ga63339f80d1692ed327238cab5ef7f2a7}{\index{E\+Physics Shape@{E\+Physics Shape}!ephysics\+\_\+shape\+\_\+load@{ephysics\+\_\+shape\+\_\+load}}
\index{ephysics\+\_\+shape\+\_\+load@{ephysics\+\_\+shape\+\_\+load}!E\+Physics Shape@{E\+Physics Shape}}
\subsubsection[{ephysics\+\_\+shape\+\_\+load}]{\setlength{\rightskip}{0pt plus 5cm}{\bf E\+A\+P\+I} {\bf E\+Physics\+\_\+\+Shape}$\ast$ ephysics\+\_\+shape\+\_\+load (
\begin{DoxyParamCaption}
\item[{const char $\ast$}]{filename}
\end{DoxyParamCaption}
)}}\label{group__EPhysics__Shape_ga63339f80d1692ed327238cab5ef7f2a7}


Load the shape from a file. 

Useful to edit shapes on design tools and load it from an exported file.

Also it helps to avoid lots of \hyperlink{group__EPhysics__Shape_ga2548c7a3aaf658b9be6132f60c1b3948}{ephysics\+\_\+shape\+\_\+point\+\_\+add()} in the code, and keep a better separation between code logic and design stuff.


\begin{DoxyParams}{Parameters}
{\em filename} & The path to the file describing the shape. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The loaded shape or {\ttfamily N\+U\+L\+L} on error.
\end{DoxyReturn}
\begin{DoxyNote}{Note}
Not implemented yet.
\end{DoxyNote}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__EPhysics__Shape_ga79ca252f9b15296416c3f73c75efa293}{ephysics\+\_\+shape\+\_\+new()} for more details. 

\hyperlink{group__EPhysics__Shape_ga60c974e4692ed765e0b7ba2e8a5d9819}{ephysics\+\_\+shape\+\_\+save()}. 
\end{DoxySeeAlso}
\hypertarget{group__EPhysics__Shape_ga60c974e4692ed765e0b7ba2e8a5d9819}{\index{E\+Physics Shape@{E\+Physics Shape}!ephysics\+\_\+shape\+\_\+save@{ephysics\+\_\+shape\+\_\+save}}
\index{ephysics\+\_\+shape\+\_\+save@{ephysics\+\_\+shape\+\_\+save}!E\+Physics Shape@{E\+Physics Shape}}
\subsubsection[{ephysics\+\_\+shape\+\_\+save}]{\setlength{\rightskip}{0pt plus 5cm}{\bf E\+A\+P\+I} {\bf Eina\+\_\+\+Bool} ephysics\+\_\+shape\+\_\+save (
\begin{DoxyParamCaption}
\item[{const {\bf E\+Physics\+\_\+\+Shape} $\ast$}]{shape, }
\item[{const char $\ast$}]{filename}
\end{DoxyParamCaption}
)}}\label{group__EPhysics__Shape_ga60c974e4692ed765e0b7ba2e8a5d9819}


Save the shape to a file. 

It can be useful to visualize it on design tools.


\begin{DoxyParams}{Parameters}
{\em shape} & The shape to be saved. \\
\hline
{\em filename} & The path to save the shape. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
{\ttfamily E\+I\+N\+A\+\_\+\+T\+R\+U\+E} on success or E\+I\+N\+A\+\_\+\+F\+A\+L\+S\+E on error.
\end{DoxyReturn}
\begin{DoxyNote}{Note}
Not implemented yet.
\end{DoxyNote}
\begin{DoxySeeAlso}{See also}
\hyperlink{group__EPhysics__Shape_ga79ca252f9b15296416c3f73c75efa293}{ephysics\+\_\+shape\+\_\+new()}. 

\hyperlink{group__EPhysics__Shape_ga63339f80d1692ed327238cab5ef7f2a7}{ephysics\+\_\+shape\+\_\+load()}. 
\end{DoxySeeAlso}
