Two common functions written using DirectX

Source: Internet
Author: User

1: Find the line formed by the intersection of two planes: bool getintersectionline (d3dxplane & plane01, d3dxplane & plane02, crayline & line) {d3dxplanenormalize (& plane01, & plane01 ); crop (& plane02, & plane02); d3dxvector3 plane01normal =-d3dxvector3 (crop, crop, crop); d3dxvector3 plane02normal =-d3dxvector3 (crop, crop, crop); d3dxvector3 tempd; d3dxvec3cross (& tempd, & plane01normal, & plane02normal); If (d3dxvec3length (& tempd) <0.0001) return false; line. setdirection (tempd); float S1, S2, a, B; S1 = plane01.d; S2 = plane02.d; float n1n2dot = d3dxvec3dot (& plane01normal, & plane02normal ); float n1normsqr = d3dxvec3dot (& plane01normal, & plane01normal); float n2normsqr = d3dxvec3dot (& plane02normal, & plane02normal); A = (S2 * n1n2dot-s1 * n2normsqr) /(n1n2dot * n1n2dot-n1normsqr * n2normsqr); B = (S1 * n1n2dot-s2 * n2normsqr)/(n1n2dot * n1n2dot-n1normsqr * n2normsqr); line. setorigin (A * plane01normal + B * plane02normal); Return true;} 2: calculates the intersection of a straight line and a plane. bool tool: lineintersectplane (const crayline & line, const d3dxplane & plane, float & T, d3dxvector3 & intersection) {float S1 = d3dxvec3dot (& line. getdirection (), & d3dxvector3 (plane. a, plane. b, plane. c); float S2 = line. getorigin (). x * plane. A + line. getorigin (). y * plane. B + line. getorigin (). z * plane. c + plane. d; If (ABS (S1) <0.00001) {If (ABS (S2) <0.00001) {T = 0; return true ;}else {return false ;}} T =-S2; t = T/S1; intersection = line. getorigin () + T * line. getdirection (); Return true ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.