Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CA-Framework
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Courses
CA-Framework
Commits
a743ae3f
Commit
a743ae3f
authored
2 years ago
by
DALAB\sjtud
Browse files
Options
Downloads
Patches
Plain Diff
initialize
parent
9814ef6b
Branches
Branches containing commit
No related merge requests found
Changes
63
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/RigidObject.h
+67
-0
67 additions, 0 deletions
include/RigidObject.h
include/Simulation.h
+81
-0
81 additions, 0 deletions
include/Simulation.h
include/Simulator.h
+263
-0
263 additions, 0 deletions
include/Simulator.h
with
411 additions
and
0 deletions
include/RigidObject.h
0 → 100644
+
67
−
0
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
This diff is collapsed.
Click to expand it.
include/Simulation.h
0 → 100644
+
81
−
0
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
This diff is collapsed.
Click to expand it.
include/Simulator.h
0 → 100644
+
263
−
0
View file @
a743ae3f
This diff is collapsed.
Click to expand it.
Prev
1
2
3
4
Next
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment