📄 ivp_physic_private.cxx
字号:
}
// a not simulated object is revived and will be simulated again in next PSI
// returns IVP_TRUE when a friction system was grown -> needed for sim_unit revival algorithm
IVP_BOOL IVP_Core::revive_simulation_core()
{
IVP_Core *core=this;
IVP_ASSERT( !core->physical_unmoveable );
IVP_ASSERT( core->movement_state == IVP_MT_NOT_SIM);
for(int c = core->objects.len()-1;c>=0;c--) {
IVP_Real_Object *r_obj=core->objects.element_at(c);
IVP_IF(1) {
IVP_ASSERT( r_obj->get_movement_state() >= IVP_MT_NOT_SIM );
}
r_obj->set_movement_state(IVP_MT_MOVING);
}
core->init_core_for_simulation();
IVP_Event_Sim es(environment, environment->get_next_PSI_time() - environment->get_current_time());
core->calc_next_PSI_matrix_zero_speed(&es);
// @@@ hack, go back to last PSI at wakeup at PSI ( satisfy init_PSI )
IVP_IF (environment->get_env_state() == IVP_ES_PSI){
IVP_DOUBLE d_time = environment->get_delta_PSI_time();
core->time_of_last_psi += -d_time;
}
IVP_IF(IVP_DEBUG_OBJECT0){
const char *search0 = IVP_DEBUG_OBJECT0;
const char *name0 = core->objects.element_at(0)->get_name();
if ( !P_String::string_cmp(name0, search0, IVP_FALSE)){
if ( core->environment->get_current_time().get_time() >= IVP_DEBUG_TIME){
printf("revive object %s time:%f\n", name0, environment->get_current_time().get_time());
}
}
}
IVP_IF(IVP_DEBUG_OBJECT1){
const char *search0 = IVP_DEBUG_OBJECT1;
const char *name0 = core->objects.element_at(0)->get_name();
if ( !P_String::string_cmp(name0, search0, IVP_FALSE)){
if ( core->environment->get_current_time().get_time() >= IVP_DEBUG_TIME){
printf("revive object %s time:%f\n", name0, environment->get_current_time().get_time());
}
}
}
//IVP_Friction_Info_For_Core *my_info=core->moveable_core_has_friction_info();
//if(my_info==NULL) {
// grow a friction system (search for near objects and put them into one friction system )
IVP_BOOL fs_was_grown=core->grow_friction_system();
//}
for(int d = core->objects.len()-1;d>=0;d--) {
IVP_Real_Object *r_obj=core->objects.element_at(d);
{ // fire object-dependant 'object revived' event
IVP_Event_Object event_revived;
event_revived.real_object = r_obj;
event_revived.environment = core->environment;
core->environment->get_cluster_manager()->fire_event_object_revived(&event_revived);
}
{ // fire global 'object revived' event
IVP_Event_Object event_revived;
event_revived.real_object = r_obj;
event_revived.environment = core->environment;
core->environment->fire_event_object_revived(&event_revived);
}
}
return fs_was_grown;
}
void IVP_Core::fire_event_object_frozen(){
// fire events
for (int i=this->objects.len()-1; i>=0; i--) {
IVP_Real_Object *real_object = this->objects.element_at(i);
{ // fire object-dependant 'object frozen' event
IVP_Event_Object event_frozen;
event_frozen.real_object = real_object;
event_frozen.environment = this->environment;
this->environment->get_cluster_manager()->fire_event_object_frozen(&event_frozen);
}
{ // fire global 'object frozen' event
IVP_Event_Object event_frozen;
event_frozen.real_object = real_object;
event_frozen.environment = this->environment;
this->environment->fire_event_object_frozen(&event_frozen);
}
}
}
void IVP_Core::freeze_simulation_core(){
IVP_Core *r_core=this;
r_core->stop_physical_movement(); //because of Interpolations
/// deactivate all mindists
IVP_IF(IVP_DEBUG_OBJECT0){
const char *search0 = IVP_DEBUG_OBJECT0;
const char *name0 = r_core->objects.element_at(0)->get_name();
if ( !P_String::string_cmp(name0, search0, IVP_FALSE)){
if ( r_core->environment->get_current_time().get_time() >= IVP_DEBUG_TIME){
printf("freeze object %s time:%f\n", name0, environment->get_current_time().get_time());
}
}
}
IVP_IF(IVP_DEBUG_OBJECT1){
const char *search0 = IVP_DEBUG_OBJECT1;
const char *name0 = r_core->objects.element_at(0)->get_name();
if ( !P_String::string_cmp(name0, search0, IVP_FALSE)){
if ( r_core->environment->get_current_time().get_time() >= IVP_DEBUG_TIME){
printf("freeze object %s time:%f\n", name0, environment->get_current_time().get_time());
}
}
}
fire_event_object_frozen();
}
void IVP_Core::debug_out_movement_vars() {
printf("core_status %lx trans %f %f %f rot %f %f %f\n",(long)this&0x0000ffff,speed.k[0],speed.k[1],speed.k[2],rot_speed.k[0],rot_speed.k[1],rot_speed.k[2]);
}
void IVP_Core::debug_vec_movement_state() {
IVP_Core *my_core=this;
IVP_Core *one_object=this;
IVP_IF( 0 ){
char *out_text;
IVP_U_Float_Point ivp_pointer;
IVP_U_Point ivp_start;
int v_color;
ivp_start.set(my_core->get_position_PSI());
ivp_pointer.set(0.0f,-7.0f,0.0f);
out_text=p_make_string("oob%lx_sp%.3f",(long)one_object&0x0000ffff,one_object->speed.real_length());//,one_object->get_energy_on_test(&one_object->speed,&one_object->rot_speed));
if(my_core->movement_state==IVP_MT_CALM) {
//out_text=p_export_error("%lxo_calm%lx",(long)one_object&0x0000ffff,(long)fr_i&0x0000ffff);
//sprintf(out_text,"%ldobj_calm%lx",counter,(long)one_object);
v_color=3;
} else {
if(my_core->movement_state==IVP_MT_SLOW)
{
//out_text=p_export_error("%lxdo_not_m%lx",(long)one_object&0x0000ffff,(long)fr_i&0x0000ffff);
v_color=6;
} else {
//out_text=p_export_error("%lxdo_moved%lx",(long)one_object&0x0000ffff,(long)fr_i&0x0000ffff);
//sprintf(out_text,"%obj_moved%lx",(long)one_object);
v_color=1;
}
}
this->environment->add_draw_vector(&ivp_start,&ivp_pointer,out_text,v_color);
P_FREE(out_text);
}
}
// check for not moving objects
// object is removed from simulation if not moving for 1 sec or slowling moving for 10 sec
// exception: objects belonging to friction systems
// friction systems are tested separately, all objects of fr_system are removed at a time
IVP_Friction_System::IVP_Friction_System(IVP_Environment *env)
{
IVP_IF(env->get_debug_manager()->check_fs) {
fprintf(env->get_debug_manager()->out_deb_file,"create_fs %f %lx\n",env->get_current_time().get_time(),(long)this);
}
//printf("creating_new_fs %lx at time %f\n",(long)this,env->get_current_time());
l_environment=env;
//first_friction_obj=NULL;
union_find_necessary=IVP_FALSE;
first_friction_dist=NULL;
friction_obj_number=0;
friction_dist_number=0;
static_fs_handle.l_friction_system=this;
energy_fs_handle.l_friction_system=this;
}
IVP_Friction_System::~IVP_Friction_System()
{
//printf("deleting_of_fs %lx at time %f\n",(long)this,l_environment->get_current_time());
IVP_IF(l_environment->get_debug_manager()->check_fs) {
fprintf(l_environment->get_debug_manager()->out_deb_file,"delete_fs %f %lx\n",l_environment->get_current_time().get_time(),(long)this);
}
// deleteing of real friction systems filled with information is not yet implemented (not trivial : unlink whole friction infos)
//Assertion: when
}
void IVP_Friction_System::fs_recalc_all_contact_points() {
for (int i = fr_pairs_of_objs.len()-1; i>=0;i--){
IVP_Friction_Core_Pair *my_pair = fr_pairs_of_objs.element_at(i);
IVP_FLOAT energy_diff_sum=0.0f;
for (int j = my_pair->fr_dists.len()-1; j>=0;j--){
IVP_Contact_Point *fr_mindist = my_pair->fr_dists.element_at(j);
IVP_FLOAT old_gap_len=fr_mindist->get_gap_length();
fr_mindist->recalc_friction_s_vals();
//energy considerations
//when gap is gettinger bigger, potential energy is gained
//when pressure is going up, do not mind
IVP_FLOAT gap_diff= old_gap_len - fr_mindist->get_gap_length();
energy_diff_sum+=fr_mindist->now_friction_pressure * gap_diff;
}
if(energy_diff_sum > 0.0f) {
my_pair->integrated_anti_energy += energy_diff_sum;
}
}
}
// is union find necessary after removing of dist ?
IVP_BOOL IVP_Friction_System::dist_removed_update_pair_info(IVP_Contact_Point *old_dist)
{
//manage info of obj pairs
{
IVP_Friction_Core_Pair *my_pair_info;
IVP_Core *core0,*core1;
core0=old_dist->get_synapse(0)->l_obj->physical_core;
core1=old_dist->get_synapse(1)->l_obj->physical_core;
my_pair_info=this->get_pair_info_for_objs(core0,core1);
if(!my_pair_info)
{
CORE;
}
my_pair_info->del_fr_dist_obj_pairs(old_dist);
if(my_pair_info->number_of_pair_dists()==0)
{
this->del_fr_pair(my_pair_info);
P_DELETE(my_pair_info);
// start union find
return IVP_TRUE;
} else {
return IVP_FALSE;
}
}
}
void IVP_Friction_System::remove_dist_from_system(IVP_Contact_Point *old_dist)
{
IVP_IF(l_environment->get_debug_manager()->check_fs) {
fprintf(l_environment->get_debug_manager()->out_deb_file,"rem_dist_from_fs %f %lx from %lx\n",l_environment->get_current_time().get_time(),(long)old_dist,(long)this);
}
//manage list of all dists
{
IVP_Contact_Point *previous=old_dist->prev_dist_in_friction;
IVP_Contact_Point *following=old_dist->next_dist_in_friction;
if(following!=NULL)
{
following->prev_dist_in_friction=previous;
}
if(previous)
{
previous->next_dist_in_friction=following;
} else {
this->first_friction_dist=following;
}
}
friction_dist_number--;
}
void IVP_Friction_System::dist_added_update_pair_info(IVP_Contact_Point *new_dist)
{
//manage info of obj pairs
{
IVP_Friction_Core_Pair *my_pair_info;
IVP_Core *core0,*core1;
core0=new_dist->get_synapse(0)->l_obj->physical_core;
core1=new_dist->get_synapse(1)->l_obj->physical_core;
my_pair_info=this->get_pair_info_for_objs(core0,core1);
if(my_pair_info)
{
;
} else {
my_pair_info=new IVP_Friction_Core_Pair();
my_pair_info->objs[0]=core0;
my_pair_info->objs[1]=core1;
this->add_fr_pair(my_pair_info);
}
my_pair_info->add_fr_dist_obj_pairs(new_dist);
}
}
void IVP_Friction_System::add_dist_to_system(IVP_Contact_Point *new_dist)
{
IVP_IF(l_environment->get_debug_manager()->check_fs) {
fprintf(l_environment->get_debug_manager()->out_deb_file,"add_dist_to_fs %f %lx to %lx\n",l_environment->get_current_time().get_time(),(long)new_dist,(long)this);
}
new_dist->l_friction_system=this;
//manage list of all dists
{
IVP_Contact_Point *first=this->first_friction_dist;
new_dist->prev_dist_in_friction=NULL;
new_dist->next_dist_in_friction=first;
this->first_friction_dist=new_dist;
if(first)
{
first->prev_dist_in_friction=new_dist;
}
}
//new_dist->number_in_friction = this->friction_dist_number; //dists are numbered the wrong way: last has number 0
IVP_IF(l_environment->debug_information->debug_mindist){
printf("added_dist %d\n",(int)friction_dist_number);
}
friction_dist_number++;
//fr_solver.calc_calc_solver(this); //solver matrix must be greater and temporary results also
}
void IVP_Friction_System::add_core_to_system(IVP_Core *new_obj)
{
IVP_IF(l_environment->get_debug_manager()->check_fs) {
fprintf(l_environment->get_debug_manager()->out_deb_file,"add_core_to_fs %f %lx to %lx\n",l_environment->get_current_time().get_time(),(long)new_obj,(long)this);
}
cores_of_friction_system.add(new_obj);
if(!new_obj->physical_unmoveable) {
moveable_cores_of_friction_system.add(new_obj);
new_obj->add_core_controller(&static_fs_handle);
new_obj->add_core_controller(this);
new_obj->add_core_controller(&energy_fs_handle);
//new_obj->sim_unit_of_core->add_controller_of_core( new_obj, &this->static_fs_handle );
//new_obj->sim_unit_of_core->add_controller_of_core( new_obj, this );
//new_obj->sim_unit_of_core->add_controller_of_core( new_obj, &this->energy_fs_handle );
}
friction_obj_number++;
}
void IVP_Friction_System::remove_core_from_system(IVP_Core *old_obj)
{
IVP_IF(l_environment->get_debug_manager()->check_fs) {
fprintf(l_environment->get_debug_manager()->out_deb_file,"remove_core_from_fs %f %lx from %lx\n",l_environment->get_current_time().get_time(),(long)old_obj,(long)this);
}
if(!old_obj->physical_unmoveable) {
moveable_cores_of_friction_system.remove(old_obj);
old_obj->rem_core_controller(&this->energy_fs_handle);
old_obj->rem_core_controller(this);
old_obj->rem_core_controller(&static_fs_handle);
}
cores_of_friction_system.remove(old_obj);
friction_obj_number--;
}
void IVP_Environment::remove_revive_core(IVP_Core *c) {
int index=this->core_revive_list.index_of(c);
if(index>=0) {
IVP_ASSERT(c->is_in_wakeup_vec==IVP_TRUE);
this->core_revive_list.remove_at(index);
c->is_in_wakeup_vec=IVP_FALSE;
}
}
void IVP_Environment::add_revive_core(IVP_Core *c)
{
if(c->is_in_wakeup_vec==IVP_TRUE) {
return;
}
IVP_IF(1) {
IVP_ASSERT(this->core_revive_list.index_of(c)<0);
}
core_revive_list.add(c);
c->is_in_wakeup_vec=IVP_TRUE;
}
void IVP_Environment::revive_cores_PSI(){
for(int i=core_revive_list.len()-1;i>=0;i--) {
IVP_Core *my_core=core_revive_list.element_at(i);
IVP_ASSERT(my_core->physical_unmoveable==IVP_FALSE);
my_core->ensure_core_to_be_in_simulation();
my_core->is_in_wakeup_vec=IVP_FALSE;
}
core_revive_list.clear();
}
void IVP_Universe_Manager::ensure_objects_in_environment(IVP_Real_Object * /*object*/,
IVP_U_Float_Point * /*sphere_center*/,
IVP_DOUBLE /*sphere_radius*/) {
;
}
void IVP_Universe_Manager::object_no_longer_needed(IVP_Real_Object *) {
;
}
void IVP_Universe_Manager::event_object_deleted(IVP_Real_Object *) {
;
}
const IVP_Universe_Manager_Settings *IVP_Universe_Manager::provide_universe_settings() {
return NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -