klasy
No notes
Syntax:
C++
#pragma once #include "SVec3.h" struct SRay { public: SRay(void); SRay(float _posX, float _posY, float _posZ, float _directX, float _directY, float _directZ ); SRay(SVec3 _pos, SVec3 _direct); ~SRay(void); /// Znajduje punkt po przesunieciu o t SVec3 PointInRay(float t); SVec3 pos; SVec3 direct; }; #include "StdAfx.h" #include "SRay.h" SRay::SRay(void) { } SRay::SRay( float _posX, float _posY, float _posZ, float _directX, float _directY, float _directZ ) { pos[0] = _posX; pos[1] = _posY; pos[2] = _posZ; direct[0] = _directX; direct[1] = _directY; direct[2] = _directZ; direct.Normalize(); } SRay::SRay( SVec3 _pos, SVec3 _direct ) { pos = _pos; direct = _direct; direct.Normalize(); } SRay::~SRay(void) { } SVec3 SRay::PointInRay(float t) { SVec3 point(pos.x + direct.x * t, pos.y + direct.y * t, pos.z + direct.z * t); return point; } #pragma once #include "SVec3.h" #include "SRay.h" struct SPlane { SVec3 normal; float d; SPlane() { d = 0.0f; } SPlane(float _a, float _b, float _c, float _d) : normal (_a, _b, _c) , d(_d) {} SPlane(SVec3& _normal, float _d) : normal(_normal), d(_d){} /// Konstruktor tworzacy plaszyzne na podstawie jej normalej i punktu ktory jest na tej plaszczyzlnie SPlane( const SVec3& planeNormal, const SVec3& pointOnPlane ) : normal ( planeNormal ) { d = -planeNormal.DotProduct( pointOnPlane ); } /// Sprawdza czy promien przecina plaszyczne /// result - punkt przeciecia jezeli istnieje bool FindIntersecion(const SRay& _ray, SVec3& _result); }; #include "StdAfx.h" #include "SPlane.h" #include "MyMath.h" bool SPlane::FindIntersecion(const SRay& _ray, SVec3& _result) // usuwam const przed ray { // http://www.siggraph.org/education/materials/HyperGraph/raytrace/rayplane_intersection.htm float denominator = _ray.direct.DotProduct(normal); if( denominator < EPSILON) return false; // promien rownolegly do plaszyzny float numerator = - _ray.pos.DotProduct(normal) + d; float t = numerator / denominator; if(t < EPSILON) return false; // promien przecina sie po zlej stronie //SVec3 XXXXXXXXXX = //_ray.PointInRay( _t); SVec3 anyVec = _ray.PointInRay(0); _result.x = 5;//XXXXXXXXXX; return true; }