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

Method OnCreateVolumeCone

editor/LightingDialog.cpp:800–897  ·  view source on GitHub ↗

Creates a volumetric cone of light that casts from the center of the current face

Source from the content-addressed store, hash-verified

798
799// Creates a volumetric cone of light that casts from the center of the current face
800void CLightingDialog::OnCreateVolumeCone() {
801 int i, t;
802
803 ASSERT(Curface < Curroomp->num_faces);
804 int resolution = m_resolution;
805 int first_vert_index, first_face_index, center_index;
806
807 vector faceverts[MAX_VERTS_PER_FACE];
808 vector center;
809 matrix face_matrix;
810
811 vector fvec = Curroomp->faces[Curface].normal;
812
813 float pitch_increment = 65536 / resolution;
814 float heading_increment = 65536 / resolution;
815 float desired_angle = m_angle;
816 float pitch, heading;
817
818 // Fixup angle for our system
819 desired_angle = (desired_angle / 360.0) * 65536;
820
821 // Get face matrix
822 vm_VectorToMatrix(&face_matrix, &fvec, NULL, NULL);
823 vm_TransposeMatrix(&face_matrix);
824
825 // Get polygon center
826 face *fp = &Curroomp->faces[Curface];
827 for (i = 0; i < fp->num_verts; i++)
828 faceverts[i] = Curroomp->verts[fp->face_verts[i]];
829 vm_GetCentroid(&center, faceverts, fp->num_verts);
830
831 // Add vertices to room
832 center_index = Curroomp->num_verts;
833 RoomAddVertices(Curroomp, resolution + 1);
834 Curroomp->verts[center_index] = center;
835 first_vert_index = center_index + 1;
836
837 for (i = 0; i < resolution; i++) {
838 vector dest_vec;
839 vector hit_vec;
840
841 matrix tempm;
842
843 // Get our direction
844 heading = FixCos(heading_increment * i);
845 pitch = FixSin(pitch_increment * i);
846
847 vm_AnglesToMatrix(&tempm, pitch * desired_angle, heading * desired_angle, 0);
848 vm_MatrixMulVector(&dest_vec, &tempm.fvec, &face_matrix);
849
850 dest_vec *= m_falloff;
851 dest_vec += center;
852
853 // Now shoot a ray out
854 ShootRayForLighting(&hit_vec, &center, &dest_vec, Curroomp - Rooms);
855
856 Curroomp->verts[first_vert_index + i] = hit_vec;
857 }

Callers

nothing calls this directly

Calls 14

RoomAddVerticesFunction · 0.85
RoomAddFacesFunction · 0.85
InitRoomFaceFunction · 0.85
ComputeFaceNormalFunction · 0.85
Float_to_ubyteFunction · 0.85
vm_VectorToMatrixFunction · 0.50
vm_TransposeMatrixFunction · 0.50
vm_GetCentroidFunction · 0.50
FixCosFunction · 0.50
FixSinFunction · 0.50
vm_AnglesToMatrixFunction · 0.50

Tested by

no test coverage detected