source: GTP/trunk/App/Demos/Illum/PathMap/Transformed.cpp @ 896

Revision 896, 3.7 KB checked in by szirmay, 19 years ago (diff)
Line 
1#include "dxstdafx.h"
2#include "transformed.h"
3#include "Radion.hpp"
4
5
6bool Transformed::intersect(const Ray& ray, float& depth, float rayMin, float rayMax)
7{
8        Ray tfdRay;
9        worldToModel.transformPoint(ray.origin, tfdRay.origin);
10        worldToModel.transformDirection(ray.dir, tfdRay.dir);
11        float iscale = tfdRay.dir.norm();
12        float scale =  1.0f / iscale;
13        tfdRay.dir *= scale;
14        tfdRay.id = ray.id;
15        tfdRay.isShadowRay = ray.isShadowRay;
16        object->intersect(tfdRay, depth, rayMin * iscale, rayMax * iscale);
17        lastTestedRayId = object->lastTestedRayId;
18        lastTestedRayResult = object->lastTestedRayResult;
19        if(!ray.isShadowRay)
20        {
21                modelToWorld.transformDirection(object->lastTestedRayResult.normal, lastTestedRayResult.normal);
22                lastTestedRayResult.normal.normalize();
23                modelToWorld.transformPoint(object->lastTestedRayResult.point, lastTestedRayResult.point);
24                lastTestedRayResult.object = this;
25        }
26        depth = lastTestedRayResult.depth = object->lastTestedRayResult.depth * scale;
27        return lastTestedRayResult.isIntersect;
28}
29
30bool Transformed::intersectBackSide(const Ray& ray, float& depth, float rayMin, float rayMax)
31{
32        Ray tfdRay;
33        worldToModel.transformPoint(ray.origin, tfdRay.origin);
34        worldToModel.transformDirection(ray.dir, tfdRay.dir);
35        float iscale = tfdRay.dir.norm();
36        float scale =  1.0f / iscale;
37        tfdRay.dir *= scale;
38        tfdRay.id = ray.id;
39        tfdRay.isShadowRay = ray.isShadowRay;
40        object->intersectBackSide(tfdRay, depth, rayMin * iscale, rayMax * iscale);
41        lastTestedRayId = object->lastTestedRayId;
42        lastTestedRayResult = object->lastTestedRayResult;
43        if(!ray.isShadowRay)
44        {
45                modelToWorld.transformDirection(object->lastTestedRayResult.normal, lastTestedRayResult.normal);
46                lastTestedRayResult.normal.normalize();
47                modelToWorld.transformPoint(object->lastTestedRayResult.point, lastTestedRayResult.point);
48                lastTestedRayResult.object = this;
49        }
50        depth = lastTestedRayResult.depth = object->lastTestedRayResult.depth * scale;
51        return lastTestedRayResult.isIntersect;
52}
53
54void Transformed::translate(Vector translation)
55{
56        modelToWorld.t[0] += translation[0];
57        modelToWorld.t[1] += translation[1];
58        modelToWorld.t[2] += translation[2];
59        worldToModel.setInvert(modelToWorld);
60//      bbox.minPoint -= translation;
61//      bbox.maxPoint -= translation;
62        object->getTransformedBoundingBox(modelToWorld, bbox);
63}
64
65void Transformed::rotateZ(float angle)
66{
67        modelToWorld.rotateZ(angle);
68        worldToModel.setInvert(modelToWorld);
69        object->getTransformedBoundingBox(modelToWorld, bbox);
70}
71
72void Transformed::rotateY(float angle)
73{
74        modelToWorld.rotateY(angle);
75        worldToModel.setInvert(modelToWorld);
76        object->getTransformedBoundingBox(modelToWorld, bbox);
77}
78
79void Transformed::rotateX(float angle)
80{
81        modelToWorld.rotateX(angle);
82        worldToModel.setInvert(modelToWorld);
83        object->getTransformedBoundingBox(modelToWorld, bbox);
84}
85
86void Transformed::scale(float factor)
87{
88        modelToWorld.scale(factor);
89        worldToModel.setInvert(modelToWorld);
90        object->getTransformedBoundingBox(modelToWorld, bbox);
91}
92
93void Transformed::setTransforms(D3DXMATRIX& mw, D3DXMATRIX& itmw)
94{
95        modelToWorld.fill(mw[0], mw[1], mw[2], mw[4], mw[5], mw[6], mw[8], mw[9], mw[10], mw[12], mw[13], mw[14]);
96        worldToModel.setInvert(modelToWorld);
97}
98
99float Transformed::getSurfaceArea()
100{
101        Vector si(1.0f, 0.0f, 0.0f);
102        Vector su;
103        worldToModel.transformDirection(si, su);
104        return object->getSurfaceArea();// * su.norm2();
105}
106
107void Transformed::sampleSurface(Radion& radion)
108{
109        object->sampleSurface(radion);
110        Vector trpos, trnorm;
111        modelToWorld.transformPoint(radion.position, trpos);
112        worldToModel.transformDirectionTransposed(radion.normal, trnorm);
113        radion.position = trpos;
114        radion.normal = trnorm;
115        radion.normal.normalize();
116}
Note: See TracBrowser for help on using the repository browser.