Jump to content
  • Advertisement

terryeverlast

Member
  • Content Count

    106
  • Joined

  • Last visited

Everything posted by terryeverlast

  1. terryeverlast

    Geometric approach to finding 8 points of the view frustum?

    Never mind. I got it with this link after looking for days   http://gamedev.stackexchange.com/questions/19774/determine-corners-of-a-specific-plane-in-the-frustum
  2. If the camera is positioned at (-20,35,-50)   And finding the d – a vector with the direction of the camera’s view ray. In here it is assumed that this vector has been normalized   which d = w ..in the picture below and it is normalized.   camera is positioned at (–20, 35, –50) and looking at the point (10, 0, 30).     T = (10, 0, 30)   So with that info, and the formula   fc = p + d * farDist   1. fc is the center of the far plane of the view frustum 2. p is the position of the camera 3. d is the direction of the camera view 4. farDist is the distance between the camera and the farplane   Im using this perspective matrix     Which the distance is 200 from the camera and the far plane.   so does fc(farplane center) = (44.98,-40.82,123.28)
  3. terryeverlast

    rotation of a vector

    Ok. Say I have the vector u = (3,0,0). I want it to be parallel to vector  v = (3,3,0) first find cross product of these vectors so we can rotate around this axis(w) to make u parallel to v.   w = (0,0,9)   To rotate so that it aims in the same direction as v, we must rotate by an angle of 45 degrees about the  w axis .       I took the vector u (3,0,0) * The Rodriguez matrix of rotation but didn't come up with the right answer.     I don't want to just use the vector u * a rotation matrix.   I want to involve u, w, and rotation. how do I rotate around w. the cross product of u and v.        
  4. terryeverlast

    Geometric approach to finding 8 points of the view frustum?

    Ok..i think I got it but I need someone to verify this code if it is right. #include <iostream> #include <conio.h> #include <D3dx9math.h> using namespace std; void main() { D3DXMATRIXA16 mat; D3DXVECTOR3 vecFrustum[8]; D3DXMATRIX matView; D3DXMATRIX matProj; matView._11 = 0.9363f; matView._12 = 0.1331f; matView._13 = 0.3249f; matView._14 = 0.0f; matView._21 = 0.0f; matView._22 = 0.9253f; matView._23 = -0.3791f; matView._24 = 0.0f; matView._31 = -0.3511f; matView._32 = 0.3549f; matView._33 = 0.8664f; matView._34 = 0.0f; matView._41 = 1.170f; matView._42 = -11.98f; matView._43 = 63.09f; matView._44 = 1.0f; matProj._11 = 1.86603; matProj._12 = 0.0; matProj._13 = 0.0f; matProj._14 = 0.0f; matProj._21 = 0.0f; matProj._22 = 3.73205f; matProj._23 = 0.0; matProj._24 = 0.0f; matProj._31 = 0.0f; matProj._32 = 0.0f; matProj._33 = 1.02564f; matProj._34 = 1.0f; matProj._41 = 0.0f; matProj._42 = 0.0f; matProj._43 = -5.12821f; matProj._44 = 0.0f; //1. multiply the matrices together D3DXMatrixMultiply( &mat, &matView, &matProj ); D3DXMatrixInverse( &mat, NULL, &mat ); //2. create the 8 points of a cube in unit-space vecFrustum[0] = D3DXVECTOR3(-1.0f, -1.0f, 0.0f); // xyz vecFrustum[1] = D3DXVECTOR3( 1.0f, -1.0f, 0.0f); // Xyz vecFrustum[2] = D3DXVECTOR3(-1.0f, 1.0f, 0.0f); // xYz vecFrustum[3] = D3DXVECTOR3( 1.0f, 1.0f, 0.0f); // XYz vecFrustum[4] = D3DXVECTOR3(-1.0f, -1.0f, 1.0f); // xyZ vecFrustum[5] = D3DXVECTOR3( 1.0f, -1.0f, 1.0f); // XyZ vecFrustum[6] = D3DXVECTOR3(-1.0f, 1.0f, 1.0f); // xYZ vecFrustum[7] = D3DXVECTOR3( 1.0f, 1.0f, 1.0f); // XYZ //3. transform all 8 points by the view/proj matrix. Doing this // gives us that ACTUAL 8 corners of the frustum area. for( int i = 0; i < 8; i++ ) D3DXVec3TransformCoord( &vecFrustum[i], &vecFrustum[i], &mat ); cout << "(" << vecFrustum[0].x << "," << vecFrustum[0].y << "," << vecFrustum[0].z << ")" << " NBLC"; cout << endl; cout << "(" << vecFrustum[1].x << "," << vecFrustum[1].y << "," << vecFrustum[1].z << ")" << " NBRC"; cout << endl; cout << "(" << vecFrustum[2].x << "," << vecFrustum[2].y << "," << vecFrustum[2].z << ")" << " NTLC"; cout << endl; cout << "(" << vecFrustum[3].x << "," << vecFrustum[3].y << "," << vecFrustum[3].z << ")" << " NTRC"; cout << endl; cout << "(" << vecFrustum[4].x << "," << vecFrustum[4].y << "," << vecFrustum[4].z << ")" << " FBLC"; cout << endl; cout << "(" << vecFrustum[5].x << "," << vecFrustum[5].y << "," << vecFrustum[5].z << ")" << " FBRC"; cout << endl; cout << "(" << vecFrustum[6].x << "," << vecFrustum[6].y << "," << vecFrustum[6].z << ")" << " FTLC"; cout << endl; cout << "(" << vecFrustum[7].x << "," << vecFrustum[7].y << "," << vecFrustum[7].z << ")" << " FTRC"; cout << endl; getch(); }
  5. terryeverlast

    rotation of a vector

    Ah..I see.   Thank you
  6. terryeverlast

    rotation of a vector

    Ok. To make (3,0,0) parallel to (3,3,0), I did the above and got   (2.121320,2.121320,0.000000)   which is at a 45 angle and is parallel to (3,3,0)   should I have gotten (3,3,0) ? or just the right direction (it aims in the same direction) matters as in  (2.121320,2.121320,0.000000)
  7. terryeverlast

    Geometric approach to finding 8 points of the view frustum?

    I found another way.   Take  (0,0,0) Bottom Left Near,  (0,0,1) Bottom Left Far,  (0,1,0) Bottom Right Near...and so on   and multiply it by (viewMatrix*ProjectionMatrix)-1    .......the inverse of those multiplied together.     is this right?
  8.     I came up with using a change of coordinate transformation  matrix  and scaling matrix with the point.   a = [1,1,0,1] the point 1,1 b = [1 0 0 0,0 1 0 0, 0 0 1 0, 2 2 0 1] the change of coordinate matrix c = [2 0 0 0, 0 1 0 0, 0 0 1 0, 0 0 0 1] the scaling matrix     [a]**[c]   multiplying those gave me wrong answer  and scales But it doesn't work. What am I doing wrong?
  9. terryeverlast

    Change of coordinate matrix

    How do I do what is in the picture?   I took the point * change of coordinate matrix * scale matrix but it didn't work.   [1,1,0,1] * [1 0 0 0, 0 1 0 0, 0 0 1 0, 2 2 0 1] * [2 0 0 0, 0 1 0 0, 0 0 1 0, 0 0 0 1]   this didn't work.  
  10. terryeverlast

    Change of coordinate matrix

    Ok. after I multiply all these matrix with the point, will one matrix do it all for all four points of the box. or do I have to change the coordinate of the points .that is one negative x value and the other positive .   like in order to make [1,1,0]  to [4,1,0]......I use point [1,1,0] to make [1,1,0] to [0,1,0]..I use point [-1,1,0]
  11. terryeverlast

    Scaling a point in the center of a frame.

    sorry. posted in wrong section. now in the math section
  12. I have searched and cant really find anything about page flipping. I have over 100 images that make a animation and I want to put it on a cube playing frame by frame. What are the steps of doing this? What apis of directx 11? I put the pictures in a atlas to. This can be done in the shader right?
  13. terryeverlast

    Some ideas about page flipping?

    For the vertex shader I got this part of the code vout.Tex = float2((vin.Tex.x*0.10)+0.10*tframe,vin.Tex.y); // 0.10 is one image of 10 of the texel ..and tframe is the time function below return vout; //and the time function in the main part of the code float t_base = 0.0f; if( (mTimer.TotalTime() - t_base) >= 0.05f ) { t_base += 0.05f; timetime = timetime + 1; if(timetime >= 10) { timetime = 0; } } timetime is sent to a cbuffer in the .fx file   I know I said I had over 100 image..which it should be .01..but I just put 10 together in the texel  
  14. terryeverlast

    Some ideas about page flipping?

    Alright thx. I got it to work
  15. So I got this code to compute a normal. Here it is. void ComputeNormal(const D3DXVECTOR3& p0, const D3DXVECTOR3& p1, const D3DXVECTOR3& p2, D3DXVECTOR3& out) { D3DXVECTOR3 u = p1 - p0; D3DXVECTOR3 v = p2 - p0; D3DXVec3Cross(&out, &u, &v); D3DXVec3Normalize(&out, &out); } And I got my drawing part of my directx right here. draws a pyramid void LightingApp::DRAWMYPYRMAID() { D3DXVECTOR3 test; ComputeNormal(D3DXVECTOR3(-2.0f, 0.0f, -2.0f),DD3DXVECTOR3(0.0f, 2.0f, 0.0f),3DXVECTOR3(2.0f, 0.0f, -2.0f),test); Vertex vertices[] = { { XMFLOAT3(-2.0f, 0.0f, 2.0f) }, { XMFLOAT3(2.0f, 0.0f, 2.0f) }, { XMFLOAT3(0.0f, 2.0f, 0.0f) }, { XMFLOAT3(-2.0f, 0.0f, -2.0f) }, { XMFLOAT3(2.0f, 0.0f, -2.0f), } }; D3D11_BUFFER_DESC vbd; vbd.Usage = D3D11_USAGE_IMMUTABLE; vbd.ByteWidth = sizeof(Vertex) * 5; vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; vbd.CPUAccessFlags = 0; vbd.MiscFlags = 0; vbd.StructureByteStride = 0; D3D11_SUBRESOURCE_DATA vinitData; vinitData.pSysMem = vertices; HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mBoxVB)); Vertex normal[] =     { { XMFLOAT3(test.x, test.y, test.z)  }     }; D3D11_BUFFER_DESC vbds;     vbds.Usage = D3D11_USAGE_IMMUTABLE;     vbds.ByteWidth = sizeof(Vertex) * 1;     vbds.BindFlags = D3D11_BIND_VERTEX_BUFFER;     vbds.CPUAccessFlags = 0;     vbds.MiscFlags = 0; vbds.StructureByteStride = 0;     D3D11_SUBRESOURCE_DATA vinitDatas;     vinitDatas.pSysMem = normal;     HR(md3dDevice->CreateBuffer(&vbds, &vinitDatas, &mBoxVBs)); // Create the index buffer UINT indices[] = { 0,1,4, 4,3,0, 0,2,1, 1,2,4, 4,2,3, 3,2,0 }; D3D11_BUFFER_DESC ibd; ibd.Usage = D3D11_USAGE_IMMUTABLE; ibd.ByteWidth = sizeof(UINT) * 18; ibd.BindFlags = D3D11_BIND_INDEX_BUFFER; ibd.CPUAccessFlags = 0; ibd.MiscFlags = 0; ibd.StructureByteStride = 0; D3D11_SUBRESOURCE_DATA iinitData; iinitData.pSysMem = indices; HR(md3dDevice->CreateBuffer(&ibd, &iinitData, &mBoxIB)); } Im getting two sides colored and the whole bottom colored. Im only calculating one normal for one side, so I only want one triangle to be colored. But im seeing two sides colored and the bottom colored. What am I messing up on in the code? how can I resolve this?
  16. terryeverlast

    Computing normals for lighting?

    I think im confused here. Do I use Face normal or Vertex Normals for lighting?   if I use vertex normals, is this code correct? Vertex normal[] = { { XMFLOAT3(1.0f, 0.0f, 1.0f) }, { XMFLOAT3(1.0f, 0.0f, 1.0f) }, { XMFLOAT3(0.0f, 1.0f, 0.0f) }, { XMFLOAT3(1.0f, 0.0f, 1.0f) }, { XMFLOAT3(1.0f, 0.0f, 1.0f) }, };
  17. terryeverlast

    Computing Normal Vectors

    For a differentiable surface, we can use calculus to find the normals of points on the surface. Unfortunately, a triangle mesh is not differentiable. The technique that is generally applied to triangle meshes is called vertex normal averaging. The vertex normal n for an arbitrary vertex v in a mesh is found by averaging the face normals of every polygon in the mesh that shares the vertex v. For example, in Figure 1, four polygons in the mesh share the vertex v; thus, the vertex normal for v is given by:       Figure 1     The middle vertex is shared by the neighboring four polygons, so we approximate the middle vertex normal by averaging the four polygon face normals.      <-- TO FIND Navg     Im familiar with finding face normal in a triangle with this formula,   But how do I find n0,n1,n2,n3 if there not in a triangle, but in the middle of a square as in Figure 1
  18. terryeverlast

    Perspective matrix

      Find the vertical field of view angle ?, the aspect ratio r, and the near and far plane values that were used to build this matrix. For the view angle, it is 30 degrees i think. the aspect ration is 1.3 i think to. and for the value 1.02564, i think the near plane is 1 and the far plane is 40..when i enter 1 and 40 into the B part which is -nf/f - n....it doesnt work unless i multiply by 5   any help on this..thx The B field -5.12821, i am confused.   here is the matrix skeleton
  19. terryeverlast

    Perspective matrix

    Ok, thank you. I got the right answer. Im going to learn formulas a b c d
  20. terryeverlast

    Perspective matrix

    20 or 200?  -5.12821/(1-1.02564) = 200 ..ill go with 20   I plugged 20 for f = 20 and 5 for n = 5 into the equation -nf/f-n and didn't get the right answers..i got 6.6666677.. and it should be -5.12821
  21. terryeverlast

    Perspective matrix

    I still don't know the value of the far plane..i tried plugging 5 into the equation -fn/f-n for n and not getting the right result...
  22. What are the values of s and t in the formula in the picture? For the formula p(s,t) = v0 + s(v1 - v0) + t(v2 - v0). Im a little famialr with barycentric coordinates...but don't know this formula , s and t values Vertex Attribute Interpolation    
  23. terryeverlast

    Vertex Attribute Interpolation of a triangle

    Heres what I put together with..something that calculates the barycentric coordiantes #include <iostream> #include <math.h> #include <conio.h> class vector { public: vector(){} vector(float X0, float Y0) { x0 = X0; y0 = Y0; } vector operator-(vector& test); vector operator*(float s); vector operator+(vector& test); vector operator=(vector& test); float x0, y0; }; vector vector::operator=(vector& test) { this->x0 = test.x0; this->y0 = test.y0; return *this; } vector vector::operator+(vector& test) { return vector(this->x0 + test.x0, this->y0 + test.y0); } vector vector::operator*(float s) { return vector(this->x0 * s, this->y0 * s); } vector vector::operator-(vector& test) { return vector(this->x0 - test.x0, this->y0 - test.y0); } // compute the area of a triangle using Heron's formula float triarea(float a, float b, float c) { float s = (a + b + c)/2.0; return sqrt(s*(s-a)*(s-b)*(s-c)); } // compute the distance between two 2d points float dist(float x0, float y0, float x1, float y1) { float a = x1 - x0; float b = y1 - y0; return sqrt(a*a + b*b); } // compute the barycentric coordinates of a 2d point inside a 2d triangle // (x0, y0) (x1, y1) (x2, y2) are the vertices of a 2d triangle // (vx, vy) is a point inside the 2d triangle // u, v, w are the barycentric coordinates of (vx, vy) in the triangle void barycent(float x0, float y0, float x1, float y1, float x2, float y2, float vx, float vy, float u, float v, float w) { // compute the area of the big triangle float a = dist(x0, y0, x1, y1); float b = dist(x1, y1, x2, y2); float c = dist(x2, y2, x0, y0); float totalarea = triarea(a, b, c); // compute the distances from the outer vertices to the inner vertex float length0 = dist(x0, y0, vx, vy); float length1 = dist(x1, y1, vx, vy); float length2 = dist(x2, y2, vx, vy); // divide the area of each small triangle by the area of the big triangle u = triarea(b, length1, length2)/totalarea; v = triarea(c, length0, length2)/totalarea; w = triarea(a, length0, length1)/totalarea; printf("\nBarycentric coordinates:\n"); printf("u: %f\n", u); printf("v: %f\n", v); printf("w: %f", w); vector p0(x0,y0); vector p1(x1,y1); vector p2(x2,y2); vector result((p2 + (p0-p2)*u) + ((p1 - p2)*v)); printf("\nx(x,y) = p2 + u(p0 - p2) + v(p1 - p2)"); printf("\nx:%f, y:%f", result.x0, result.y0); } void main() { barycent(2,2,5,1,4,5,3.5,3.0,2.0,1.25,1.0); getch(); }
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!