Monday, December 1, 2008
Accelerated 3D rendering.
Friday, November 7, 2008
Projecting vectors
Sometimes we need to project one vector over another. See the picture below , we can see a vector u. Now we need to project this u on to x axis, .
This can be done with this equation : p = x * u . (x / Norm[x] ) . p is the result
"." means Dot product. What that equation means is we need to normalize x first ( in general to which we are projecting u vector ) and find the dot product between u and normalized x , and mulitply our x(destingation ) vector by this scalar value. Now we will get the result.
Tuesday, November 4, 2008
A rotation matrix can be represented as
x1 x2 x3
y1 y2 y3
z1 z2 z3
Where (x1, y1, z1) are the first vector (x2, y2, z2), (x3, y3, z3) are the second and third vectors.
Note this matrix is column major oriented.
When you multiply this matrix by an arbitrary vector in space you will get the rotated vector coordinates.
In some situations it is important to know the axis of rotation. Here I am going to present one method to get the rotation axis from rotation matrix.
Consider this matrix which represents a rotation around axis ( 0.7017,0.7017,0 ) , this actually a vector in x-y plane rotated by 45 degree, Like this
The rotation matrix for rotating around this vector by 45 degree is shown below (which I calculated using quaternion)
0.8536 0.146 0.500
0.1460 0.850 -0.500
-0.500 0.500 0.707
When we multiply a arbitrary vector (x,y,z) by this matrix we gets the vector function F as below
(X 0.8536 + y 0.146 + z 0.5) i + ( x 0.146 + y 0.85 – z 0.5 ) j + ( -x 0.5 + y 0.5 + y 0.707 ) k
I,j,k are the base vectors.
Taking curl of this vector function F, we get the axis of rotation.
I calculated the curl of that function and it is (1,-1, 0). After normalizing this vector we can see the result as (.707,-.707, 0),. Earlier we had created the rotation matrix to rotate around the axis ( .707,.707,0). Our answer curl is in the opposite direction of (.707,.707,0) , but it is still correct.
Only problem is with the direction of rotation that is clockwise or anti clock wise..
Monday, November 3, 2008
A few months back i decided to study calculas. I don't want to solve equations. But understanding the concept like infinitily small things and how we can use that in practical purposes. I got a book , which explains very basically the concepts..
As a start of the study i decided to find the area of circle. Everyone knows it .. It is Pi * r ^2.
How it came ? Old people know it . Old indian mathematicians , egyptions all know that.. But calculas is developed after that.. By Sir Newtorn & Sir Lebnitz.
I decided to use caluclas to find the area of circle. We know the cirlcle can be divided in to many triangles see the follwing picture
you can see that a cirlcle containing a triangle. Suppose if we could divide the circle with very small tiny ! triangle , the area will be equal to that of the sum of all area of the triangles.
Okay this is how Infinitely small items can be useful for practical purpose. Here the area of the one Infinitely small triangle is this ( based on radius r )
Area = 1/2 * r cos(theta) * r sin(theta)
Integrating this to 0-2Pi gives the result , see below for the idea
Monday, October 6, 2008
Collision detection using Separating Axis Theorem
// If three points are inside the box, definitily the triangle is inside the ABBBox.
return Interfaces3D::InterSectionIn;
fExtent = satAxis[i].Dot( vtRadius );
fCenterBox = satAxis[i].Dot( GetPosition() );
fProjBox[0] = fCenterBox + fExtent;
fProjBox[1] = fCenterBox - fExtent;
FindMinMax( fProjBox, 2,fBoxMin,fBoxMax );
// projecting triangle coordinates
fProjTri[0] = satAxis[i].Dot( refTri.m_Pt1 );
fProjTri[1] = satAxis[i].Dot( refTri.m_Pt2 );
fProjTri[2] = satAxis[i].Dot( refTri.m_Pt3 );
FindMinMax( fProjTri, 3,fMin,fMax );
// check for overlapping on the SAT axis
if( (fMin < fBoxMin && fMax < fBoxMin ) || (fMin > fBoxMax && fMax > fBoxMax ) )
return Interfaces3D::InterSectionOut; // the triangle is outside.
Collision detection using SAT
// If three points are inside the box, definitily the triangle is inside the ABBBox.
return Interfaces3D::InterSectionIn;
fExtent = satAxis[i].Dot( vtRadius );fCenterBox = satAxis[i].Dot( GetPosition() );fProjBox[0] = fCenterBox + fExtent;
fProjBox[1] = fCenterBox - fExtent;FindMinMax( fProjBox, 2,fBoxMin,fBoxMax );
// projecting triangle coordinates
Saturday, September 20, 2008
3DS file rendering
Saturday, September 13, 2008
std::vector and pointers.
std::vector<SomeClass> Objects;
// i am feeding the vector here... like Objects.push_back( .. )
like SomeClass* pThink = &Objects[0];
Wednesday, July 23, 2008
Checking a point inside Quadratic curve
Thursday, July 17, 2008
Quadratic curve Interpolation
substituting b and c in Equation (2) gives
The final equation becomes t^2(p1-p0'-p0) + p0' * t + p0 .
At t = 0 it will give p0 and at t=1 it will give p1 as output. You can change p0' to change the shape of the curve. p0' is a vector , if its direction is same as p1-p0 vector the result will be straight line connectin p0 and p1 . Try changing t and p0' to get the desired results.
Good luck
Wednesday, June 18, 2008
BSP Portal generation some thoughts
Recently i started to learn something more about portal and PVS (potential visible set) , and decided to write a my own engine. Everyone who are going to write a BSP tree and portal generation system would get some pain in their eyes . I am sure about it. It is not as easy as we think , BSP tree is ok , but an efficient automatic Portal generation is algorithm is difficult .
I am looking some methods to do it . BSP tree helps to divide the input geometry data in to convex polygons , that means the leaf of the node will contain the convex polygons. If the input data is not a suitable one the bsp will be an unbalanced one , and also cause to split many polygons. So an efficient BSP tree algorithm is needed ,
Which should do the following things.
1. It should select the best splitter polygon from the given polygon set
2. The criteria may be the ratio between the split count and balanced leaf count ( Right leaf Poly count/Left leaf poly count , if it is 1 this is ideal , and you are lucky).
The next thing is to generate portals . I am stopping now . i will update this page soon (i have no idea ),
I am thinking about an algorithm currently which can generate portals efficiently. ..
Contd...
4-7-2008
I started BSP tree works , it is not much complicated, i need to avoid recursion to avoid stack overflow during the creation of tree.. In case of small low poly models the triangle count are normally less and i can use recursion to create tree.. anyway it is not a big problem.. The Big problem is generating the portals , it may be impossible to 100% generate correct portals automatically.. hmm..Let me see.. I want to keep the current momentum.
I just completed BSP tree works.. It works!!... I have some few problems now , like calculating the texture coordinates when triangles got cut . My friend decided to implement Sutherland-Hodgman clipping algorithm for creating portals. Now I am waiting for his results..
Tuesday, January 29, 2008
C++ overloading operator& ( Or Find the addess of a object)
more tricky. I will explain ( by showing the code) here both two methods.
Method 1.
template<typename T>
class Addressfinder : public T
{
public:
Addressfinder* operator&() { return this; }
};
and you use it like this
AddressBlocker
blockMe;
Addressfinder<AddressBlocker>& finder = static_cast<Addressfinder<AddressBlocker>&> ( blockMe );
and address can be retrieved by simple "AddressBlocker* pValid = &finder;" . This will work since i overloaded the &operator in Addressfinder class.
Method 2.
I think this is more good compared to the above. Since it is not creating any more relationships with the classes. and also no need for casting to use it.
template <typename T>
class AddressfinderII
{
T& tOb;
public:
AddressfinderII(T& t): tOb(t){}
T * operator&()
{
return reinterpret_cast<T*> ( *reinterpret_cast<int *>( this ) );
}
};
AddressBlocker blocker;
AddressfinderII<AddressBlocker> finderII(blocker);AddressBlocker * pAddress = &finderII;
if you look the size of this class , it just 4 bytes. because storing reference is same as pointer.
The class object's memory will have just the real address of object. And i extracted that value in operator& and returned.
Ok.. There is a more convenient way , he told me . and it is used in boost libraries. anyway i could find some alternatives
Method 3
template<typename T>
T* addessof(T& t)
{
return reinterpret_cast<T*>(& reinterpret_cast<int&> ( t ) );
}
and can be use like addressof( blocker); it is more convenient. it has similarities with method 1. So now no more address hiding..