MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / ComputeCreatePnt

Method ComputeCreatePnt

Descent3/matcen.cpp:546–677  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

544}
545
546bool matcen::ComputeCreatePnt() {
547 if (m_status & MSTAT_MANUAL_UPDATE_CREATE_PNT) {
548 return true;
549 } else if (m_type != MT_UNASSIGNED) {
550 float spawn_dist;
551
552 if (m_cached_prod_index >= 0 && m_cached_prod_index < m_num_prod_types && m_prod_type[m_cached_prod_index] >= 0 &&
553 m_prod_type[m_cached_prod_index] <= MAX_OBJECT_TYPES &&
554 Object_info[m_prod_type[m_cached_prod_index]].type != OBJ_NONE) {
555 spawn_dist = Object_info[m_prod_type[m_cached_prod_index]].size + 1.0f;
556 } else {
557 spawn_dist = 8.0f;
558 }
559
560 if (m_type == MT_ROOM) {
561 bool f_computed = false;
562
563 if (!(m_roomnum >= 0 && m_roomnum <= Highest_room_index && Rooms[m_roomnum].used))
564 goto error;
565
566 if (m_num_spawn_pnts) {
567 int i;
568 int num_valid_faces = 0;
569 room *rp = &Rooms[m_roomnum];
570
571 m_create_pnt = Zero_vector;
572
573 for (i = 0; i < m_num_spawn_pnts; i++) {
574 if (m_spawn_pnt[i] >= 0 && m_spawn_pnt[i] < rp->num_faces) {
575 face *fp = &rp->faces[m_spawn_pnt[i]];
576 int y;
577
578 m_spawn_vec[num_valid_faces].x = m_spawn_vec[num_valid_faces].y = m_spawn_vec[num_valid_faces].z = 0;
579
580 for (y = 0; y < fp->num_verts; y++)
581 m_spawn_vec[num_valid_faces] += rp->verts[fp->face_verts[y]];
582
583 m_spawn_vec[num_valid_faces] /= fp->num_verts;
584 m_create_pnt += m_spawn_vec[num_valid_faces];
585
586 m_spawn_normal[num_valid_faces] = fp->normal;
587
588 num_valid_faces++;
589 }
590 }
591
592 if (num_valid_faces) {
593 m_create_pnt /= num_valid_faces;
594
595 for (i = 0; i < num_valid_faces; i++) {
596 // Compute the vector to the m_create_pnt
597 vector to_dist = m_create_pnt - m_spawn_vec[i];
598 float dot = m_spawn_normal[i] * to_dist;
599
600 if (dot < spawn_dist) {
601 float add_dist = spawn_dist - dot;
602 m_create_pnt += (add_dist * m_spawn_normal[i]);
603 }

Callers

nothing calls this directly

Calls 3

ObjGetFunction · 0.85
WeaponCalcGunFunction · 0.85
fvi_FindIntersectionFunction · 0.85

Tested by

no test coverage detected