Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Courses
CA-Framework
Commits
a743ae3f
Commit
a743ae3f
authored
Feb 24, 2023
by
DALAB\sjtud
Browse files
initialize
parent
9814ef6b
Changes
63
Expand all
Show whitespace changes
Inline
Side-by-side
include/RigidObject.h
0 → 100644
View file @
a743ae3f
#ifndef RIGIDOBJECT_H
#define RIGIDOBJECT_H
#include "BaseObject.h"
/*
* Base class representing a simple rigid object.
*/
class
RigidObject
:
public
BaseObject
{
public:
RigidObject
()
{}
RigidObject
(
const
std
::
string
&
mesh_path
,
const
ObjType
t
=
ObjType
::
DYNAMIC
);
virtual
~
RigidObject
()
{}
void
applyForceToCOM
(
const
Eigen
::
Vector3d
&
f
);
/*
* Apply force f at point p.
*/
void
applyForce
(
const
Eigen
::
Vector3d
&
f
,
const
Eigen
::
Vector3d
&
p
);
void
applyTorque
(
const
Eigen
::
Vector3d
&
t
);
void
printDebug
(
const
std
::
string
&
message
=
""
)
const
;
#pragma region GettersAndSetters
virtual
void
setType
(
ObjType
t
)
override
;
void
setMass
(
double
m
);
void
setInertia
(
const
Eigen
::
Matrix3d
&
I
);
void
setLinearMomentum
(
const
Eigen
::
Vector3d
&
p
);
void
setAngularMomentum
(
const
Eigen
::
Vector3d
&
l
);
void
setLinearVelocity
(
const
Eigen
::
Vector3d
&
v
);
void
setAngularVelocity
(
const
Eigen
::
Vector3d
&
w
);
void
setForce
(
const
Eigen
::
Vector3d
&
f
);
void
setTorque
(
const
Eigen
::
Vector3d
&
t
);
void
resetForce
();
void
resetTorque
();
double
getMass
()
const
;
double
getMassInv
()
const
;
Eigen
::
Matrix3d
getInertia
()
const
;
Eigen
::
Matrix3d
getInertiaInv
()
const
;
Eigen
::
Matrix3d
getInertiaInvWorld
()
const
;
Eigen
::
Matrix3d
getInertiaWorld
()
const
;
Eigen
::
Vector3d
getLinearMomentum
()
const
;
Eigen
::
Vector3d
getAngularMomentum
()
const
;
Eigen
::
Vector3d
getLinearVelocity
()
const
;
Eigen
::
Vector3d
getVelocity
(
const
Eigen
::
Vector3d
&
point
)
const
;
Eigen
::
Vector3d
getAngularVelocity
()
const
;
Eigen
::
Vector3d
getForce
()
const
;
Eigen
::
Vector3d
getTorque
()
const
;
#pragma endregion GettersAndSetters
protected:
virtual
void
resetMembers
()
override
;
private:
double
m_mass
;
// Body mass
double
m_massInv
;
// Inverted mass
Eigen
::
Matrix3d
m_inertia
;
// Intertial Tensor (initially set to cube)
Eigen
::
Matrix3d
m_inertiaInv
;
// Inverse
Eigen
::
Vector3d
m_v
;
// Linear velocity
Eigen
::
Vector3d
m_w
;
// Angular velocity
Eigen
::
Vector3d
m_force
;
// Force on body
Eigen
::
Vector3d
m_torque
;
// Torque on body
};
#endif
\ No newline at end of file
include/Simulation.h
0 → 100644
View file @
a743ae3f
#ifndef SIMULATION_H
#define SIMULATION_H
#include <igl/opengl/glfw/Viewer.h>
#include "RigidObject.h"
/*
* Base class for different kinds of simulation. Provides methods for
* controlling the simulation and rendering it in a Gui.
*/
class
Simulation
{
public:
Simulation
()
{}
virtual
~
Simulation
()
{}
/*
* Initialize the necessary class variables at the beginning of the
* simulation.
*/
virtual
void
init
()
{}
/*
* Reset class variables to reset the simulation.
*/
void
reset
()
{
m_time
=
0.0
;
m_step
=
0
;
resetMembers
();
}
/*
* Update the rendering data structures. This method will be called in
* alternation with advance(). This method blocks rendering in the
* viewer, so do *not* do extensive computation here (leave it to
* advance()).
*/
virtual
void
updateRenderGeometry
()
=
0
;
/*
* Performs one simulation step of length m_dt. This method *must* be
* thread-safe with respect to renderRenderGeometry() (easiest is to not
* touch any rendering data structures at all). You have to update the time
* variables at the end of each step if they are necessary for your
* simulation.
* Return true means the simulation is finished.
*/
virtual
bool
advance
()
=
0
;
/*
* Perform any actual rendering here. This method *must* be thread-safe with
* respect to advance(). This method runs in the same thread as the
* viewer and blocks user IO, so there really should not be any extensive
* computation here or the UI will lag/become unresponsive (the whole reason
* the simulation itself is in its own thread.)
*/
virtual
void
renderRenderGeometry
(
igl
::
opengl
::
glfw
::
Viewer
&
viewer
)
=
0
;
void
setTimestep
(
double
t
)
{
m_dt
=
t
;
}
double
getTime
()
const
{
return
m_time
;
}
unsigned
long
getStep
()
const
{
return
m_step
;
}
std
::
vector
<
RigidObject
>
&
getObjects
()
{
return
m_objects
;
}
protected:
/*
* Reset class variables specific to a certain simulation. Is called by
* Simulation::reset().
*/
virtual
void
resetMembers
()
=
0
;
std
::
vector
<
RigidObject
>
m_objects
;
// vector of all objects in the simulation
double
m_dt
=
0.0
;
// length of timestep
double
m_time
=
0.0
;
// current time
unsigned
long
m_step
=
0
;
// number of performed steps in simulation
};
#endif
\ No newline at end of file
include/Simulator.h
0 → 100644
View file @
a743ae3f
This diff is collapsed.
Click to expand it.
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment