Jump to content
  • Advertisement

Fulon

Member
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Fulon

  • Rank
    Newbie

Personal Information

  • Role
    Programmer
  • Interests
    Art
    Programming

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hello! I made Skinning Function. But that is CPU Skinning.(When I skin high polygon model, very slow) So, I'm making GPU Skinning. But My Program draw model strange! Here' s my code! This is Initalize Code ...//meshes,numjoints..etc else if (checkString == "joints") { Joint tempJoint; fileIn >> checkString; // Skip the "{" for (int i = 0; i < MD5Model.numJoints; i++) { fileIn >> tempJoint.name; if (tempJoint.name[tempJoint.name.size() - 1] != '"') { wchar_t checkChar; bool jointNameFound = false; while (!jointNameFound) { checkChar = fileIn.get(); if (checkChar == '"') jointNameFound = true; tempJoint.name += checkChar; } } fileIn >> tempJoint.parentID; // Store Parent joint's ID fileIn >> checkString; // Skip the "(" fileIn >> tempJoint.pos.x >> tempJoint.pos.z >> tempJoint.pos.y; fileIn >> checkString >> checkString; // Skip the ")" and "(" // Store orientation of this joint fileIn >> tempJoint.orientation.x >> tempJoint.orientation.z >> tempJoint.orientation.y; tempJoint.name.erase(0, 1); tempJoint.name.erase(tempJoint.name.size() - 1, 1); float t = 1.0f - (tempJoint.orientation.x * tempJoint.orientation.x) - (tempJoint.orientation.y * tempJoint.orientation.y) - (tempJoint.orientation.z * tempJoint.orientation.z); if (t < 0.0f) { tempJoint.orientation.w = 0.0f; } else { tempJoint.orientation.w = -sqrtf(t); } //ADDITION HERE! XMVECTOR quat = XMVectorSet(tempJoint.orientation.x, tempJoint.orientation.y, tempJoint.orientation.z, tempJoint.orientation.w); //const XMMATRIX rotation = XMMatrixRotationQuaternion(quat); MD5Model.invbindrots.resize(MD5Model.numJoints); MD5Model.invbindpos.resize(MD5Model.numJoints); XMStoreFloat4(&MD5Model.invbindrots[i], XMQuaternionInverse(quat)); MD5Model.invbindpos[i] = { -tempJoint.pos.x,-tempJoint.pos.y,-tempJoint.pos.z }; //ENDADDITION std::getline(fileIn, checkString); // Skip rest of this line MD5Model.joints.push_back(tempJoint); // Store the joint into this models joint vector } //calc indices...tris..weights..etc //And this code is calculate bone index and weights! for (int i = 0; i < subset.vertices.size(); i++) { VertexStruct_SkinGPU& vert = subset.vertices[i]; vert.boneIdx[0] = 0; vert.boneIdx[1] = 0; vert.boneIdx[2] = 0; vert.boneIdx[3] = 0; for (int j = 0; j < vert.WeightCount; j++) { if (j >= 4) break; Weight& weight = subset.weights[vert.StartWeight + j]; vert.boneIdx[j] = weight.jointID; vert.weight.x = weight.bias; vert.weight.y = weight.bias; vert.weight.z = weight.bias; } } And this code is update code. void Mesh_Skinned::UpdateMD5ModelGPU(Model3DGPU & MD5Model, float deltaTime, int animation) { MD5Model.animations[animation].currAnimTime += deltaTime; // Update the current animation time if (MD5Model.animations[animation].currAnimTime > MD5Model.animations[animation].totalAnimTime) MD5Model.animations[animation].currAnimTime = 0.0f; // Which frame are we on float currentFrame = MD5Model.animations[animation].currAnimTime * MD5Model.animations[animation].frameRate; int frame0 = floorf(currentFrame); int frame1 = frame0 + 1; // Make sure we don't go over the number of frames if (frame0 == MD5Model.animations[animation].numFrames - 1) frame1 = 0; float interpolation = currentFrame - frame0; // Get the remainder (in time) between frame0 and frame1 to use as interpolation factor //std::vector<XMMATRIX> interpolatedSkeleton; // Create a frame skeleton to store the interpolated skeletons in //interpolatedSkeleton.resize(MD5Model.animations[animation].numJoints); // Compute the interpolated skeleton std::vector<XMFLOAT3> animated_pos_arr; std::vector<XMFLOAT4> animated_rot_arr; std::vector<XMFLOAT3> skinned_pos_arr_; std::vector<XMFLOAT4> skinned_rot_arr_; for (int i = 0; i < MD5Model.animations[animation].numJoints; i++) { Joint tempJoint; Joint joint0 = MD5Model.animations[animation].frameSkeleton[frame0][i]; // Get the i'th joint of frame0's skeleton Joint joint1 = MD5Model.animations[animation].frameSkeleton[frame1][i]; // Get the i'th joint of frame1's skeleton tempJoint.parentID = joint0.parentID; // Set the tempJoints parent id // Turn the two quaternions into XMVECTORs for easy computations XMVECTOR joint0Orient = XMVectorSet(joint0.orientation.x, joint0.orientation.y, joint0.orientation.z, joint0.orientation.w); XMVECTOR joint1Orient = XMVectorSet(joint1.orientation.x, joint1.orientation.y, joint1.orientation.z, joint1.orientation.w); // Interpolate positions tempJoint.pos.x = joint0.pos.x + (interpolation * (joint1.pos.x - joint0.pos.x)); tempJoint.pos.y = joint0.pos.y + (interpolation * (joint1.pos.y - joint0.pos.y)); tempJoint.pos.z = joint0.pos.z + (interpolation * (joint1.pos.z - joint0.pos.z)); // Interpolate orientations using spherical interpolation (Slerp) XMStoreFloat4(&tempJoint.orientation, XMQuaternionSlerp(joint0Orient, joint1Orient, interpolation)); animated_pos_arr.push_back(tempJoint.pos); animated_rot_arr.push_back(tempJoint.orientation); XMVECTOR arotarr = XMVectorSet(animated_rot_arr[i].x, animated_rot_arr[i].y, animated_rot_arr[i].z, animated_rot_arr[i].w); XMVECTOR bindrot = XMVectorSet(MD5Model.invbindrots[i].x, MD5Model.invbindrots[i].y, MD5Model.invbindrots[i].z, MD5Model.invbindrots[i].w); XMFLOAT4 rot; XMVECTOR quat = XMQuaternionMultiply(arotarr, bindrot); XMStoreFloat4(&rot, quat); skinned_rot_arr_.push_back(rot); XMVECTOR bindpos = XMVectorSet(MD5Model.invbindpos[i].x, MD5Model.invbindpos[i].y, MD5Model.invbindpos[i].z, 0); XMVECTOR mul = XMVectorMultiply(quat, bindpos); XMVECTOR aposarr = XMVectorSet(animated_pos_arr[i].x, animated_pos_arr[i].y, animated_pos_arr[i].z, 0); XMVECTOR plus = aposarr + mul; XMFLOAT3 newpos; XMStoreFloat3(&newpos, plus); skinned_pos_arr_.push_back(newpos); } MD5Model.skinned_pos_arr = skinned_pos_arr_; MD5Model.skinned_rot_arr = skinned_rot_arr_; } And This is Shader(HLSL) /////////////////////////////////////////////// // // Skin Texture_Color Shader // Desc: Skin Texture + Vertex Color // /////////////////////////////////////////////// ///////////// // Globals // ///////////// cbuffer MatrixBuffer { matrix worldMat; matrix viewMat; matrix projMat; float3 skinPos[128]; float4 skinRot[128]; }; ////////////// // TypeDefs // ////////////// struct VertexInputType { float4 position : POSITION; float2 tex : TEXCOORD0; float4 color : COLOR; uint4 boneIdx : BONEID; float4 weight : WEIGHT; }; struct PixelInputType { float4 position : SV_POSITION; float2 tex : TEXCOORD0; float4 color : COLOR; }; float3 trans_for_f(float3 v, float3 pos, float4 rot) { return v + 2.0 * cross(rot.xyz,cross(rot.xyz,v) + rot.w * v) + pos; } PixelInputType SkinTextureColorVertexShader(VertexInputType input) { int id0 = int(input.boneIdx.x); int id1 = int(input.boneIdx.y); int id2 = int(input.boneIdx.z); int id3 = int(input.boneIdx.w); PixelInputType output; // Change the position vector to be 4 units for proper matrix calculations. input.position.w = 1.0f; float3 result = trans_for_f(input.position, skinPos[id0], skinRot[id0]) * input.weight.x; result += trans_for_f(input.position, skinPos[id1], skinRot[id1]) * input.weight.y; result += trans_for_f(input.position, skinPos[id2], skinRot[id2]) * input.weight.z; result += trans_for_f(input.position, skinPos[id3], skinRot[id3]) * input.weight.w; //output.position = mul(inputpos, boneTransform); // Calculate the position of the vertex against the world, view, and projection matrices. float4 finalresult; finalresult.x = result.x; finalresult.y = result.y; finalresult.z = result.z; finalresult.w = 1.0f; output.position = mul(finalresult, worldMat); output.position = mul(output.position, viewMat); output.position = mul(output.position, projMat); // Store the input color for the pixel shader to use. output.color = input.color; // Store the texture coordinates for the pixel shader. output.tex = input.tex; return output; } Thanks! and sorry for bad english skills....
  2. Hello! I'm making Mesh Collision Function. But It has a important bug. when two mesh's X Axis is same, they are not colliding but returns 'true' Here's the code! bool TriangleCollision(Transform * transA, VEC * t10, VEC * t11, VEC * t12, Transform * transB, VEC * t20, VEC * t21, VEC * t22) { VEC v0 = { t10->x,t10->y,t10->z }; VEC v1 = { t11->x,t11->y,t11->z }; VEC v2 = { t12->x,t12->y,t12->z }; VEC u0 = { t20->x,t20->y,t20->z }; VEC u1 = { t21->x,t21->y,t21->z }; VEC u2 = { t22->x,t22->y,t22->z }; VEC e1, e2; VEC n1, n2; VEC dd; //Vector2 VEC isect1 = { 0,0,0 }; VEC isect2 = { 0,0,0 }; float du0, du1, du2, dv0, dv1, dv2, d1, d2; float du0du1, du0du2, dv0dv1, dv0dv2; float vp0, vp1, vp2; float up0, up1, up2; float bb, cc, max; short index; VecMinusVec(&v1, &v0, &e1); VecMinusVec(&v2, &v0, &e2); VecCross(&e1, &e2, &n1); d1 = -VecDot(&n1, &v0); du0 = VecDot(&n1, &u0) + d1; du1 = VecDot(&n1, &u1) + d1; du2 = VecDot(&n1, &u2) + d1; if (abs(du0) < FEPSILON) { du0 = 0.0f; } if (abs(du1) < FEPSILON) { du1 = 0.0f; } if (abs(du2) < FEPSILON) { du2 = 0.0f; } du0du1 = du0 * du1; du0du2 = du0 * du2; if (du0du1 > 0.0f && du0du2 > 0.0f) return false; VecMinusVec(&u1, &u0, &e1); VecMinusVec(&u2, &u0, &e2); VecCross(&e1, &e2, &n2); d2 = -VecDot(&n2, &u0); dv0 = VecDot(&n2, &v0) + d2; dv1 = VecDot(&n2, &v1) + d2; dv2 = VecDot(&n2, &v2) + d2; if (abs(dv0) < FEPSILON) { dv0 = 0.0f; } if (abs(dv1) < FEPSILON) { dv1 = 0.0f; } if (abs(dv2) < FEPSILON) { dv2 = 0.0f; } dv0dv1 = dv0 * dv1; dv0dv2 = dv0 * dv2; if (dv0dv1 > 0.0f && dv0dv2 > 0.0f) return false; VecCross(&n1, &n2, &dd); max = (float)abs(dd.x); index = 0; bb = (float)abs(dd.y); cc = (float)abs(dd.z); if (bb > max) { max = bb; index = 1; } if (cc > max) { max = cc; index = 2; } switch (index) { case 0: vp0 = v0.x; vp1 = v1.x; vp2 = v2.x; up0 = u0.x; up1 = u1.x; up2 = u2.x; break; case 1: vp0 = v0.y; vp1 = v1.y; vp2 = v2.y; up0 = u0.y; up1 = u1.y; up2 = u2.y; break; case 2: vp0 = v0.z; vp1 = v1.z; vp2 = v2.z; up0 = u0.z; up1 = u1.z; up2 = u2.z; break; } float a = 0; float b = 0; float c = 0; float x0 = 0; float x1 = 0; if (ComputeIntervals(vp0, vp1, vp2, dv0, dv1, dv2, dv0dv1, dv0dv2, a, b, c, x0, x1)) { return TriTriCoplanar(n1, v0, v1, v2, u0, u1, u2); } float d = 0; float e = 0; float f = 0; float y0 = 0; float y1 = 0; if (ComputeIntervals(up0,up1,up2,du0,du1,du2,du0du1,du0du2,d,e,f,y0,y1)) { return TriTriCoplanar(n1, v0, v1, v2, u0, u1, u2); } float xx, yy, xxyy, tmp; xx = x0 * x1; yy = y0 * y1; xxyy = xx * yy; tmp = a * xxyy; isect1.x = tmp + b * x1 * yy; isect1.y = tmp + c * x0 * yy; tmp = d * xxyy; isect2.x = tmp + e * xx * y1; isect2.y = tmp + f * xx * y0; Sort(isect1); Sort(isect2); return !(isect1.y < isect2.x || isect2.y < isect1.x); } void Sort(VEC& v) { if (v.x > v.y) { float c; c = v.x; v.x = v.y; v.y = c; } } bool EdgeEdgeTest(VEC v0, VEC v1, VEC u0, VEC u1, int i0, int i1) { float ax, ay, bx, by, cx, cy, e, d, f; float v0i0; float v1i0; float u0i0; float u1i0; if (i0 == 0) { v0i0 = v0.x; v1i0 = v1.x; u0i0 = u0.x; u1i0 = u1.x; } else if (i0 == 1) { v0i0 = v0.y; v1i0 = v1.y; u0i0 = u0.y; u1i0 = u1.y; } else if (i0 == 2) { v0i0 = v0.z; v1i0 = v1.z; u0i0 = u0.z; u1i0 = u1.z; } float v0i1; float v1i1; float u0i1; float u1i1; if (i1 == 0) { v0i1 = v0.x; v1i1 = v1.x; u0i1 = u0.x; u1i1 = u1.x; } else if (i1 == 1) { v0i1 = v0.y; v1i1 = v1.y; u0i1 = u0.y; u1i1 = u1.y; } else if (i1 == 2) { v0i1 = v0.z; v1i1 = v1.z; u0i1 = u0.z; u1i1 = u1.z; } ax = v1i0 - v0i0; ay = v1i1 - v0i1; bx = u0i0 - u1i0; by = u0i1 - u1i1; cx = v0i0 - u0i0; cy = v0i1 - u0i1; f = ay * bx - ax * by; d = by * cx - bx * cy; if ((f > 0 && d >= 0 && d <= 5) || (f < 0 && d <= 0 && d >= f)) { e = ax * cy - ay * cx; if (f > 0) { if (e >= 0 && e <= f) return true; } else { if (e <= 0 && e >= f) return true; } } return false; } bool EdgeAgainstTriEdges(VEC v0, VEC v1, VEC u0, VEC u1, VEC u2, short i0, short i1) { if (EdgeEdgeTest(v0, v1, u0, u1, i0, i1)) return true; if (EdgeEdgeTest(v0, v1, u1, u2, i0, i1)) return true; if (EdgeEdgeTest(v0, v1, u2, u0, i0, i1)) return true; return false; } bool PtInTri(VEC v0, VEC u0, VEC u1, VEC u2, short i0, short i1) { float a, b, c, d0, d1, d2; float v0i0; float u0i0; float u1i0; float u2i0; if (i0 == 0) { v0i0 = v0.x; u0i0 = u0.x; u1i0 = u1.x; u2i0 = u2.x; } else if (i0 == 1) { v0i0 = v0.y; u0i0 = u0.y; u1i0 = u1.y; u2i0 = u2.y; } else if (i0 == 2) { v0i0 = v0.z; u0i0 = u0.z; u1i0 = u1.z; u2i0 = u2.z; } float v0i1; float u0i1; float u1i1; float u2i1; if (i1 == 0) { v0i1 = v0.x; u0i1 = u0.x; u1i1 = u1.x; u2i1 = u2.x; } else if (i1 == 1) { v0i1 = v0.y; u0i1 = u0.y; u1i1 = u1.y; u2i1 = u2.y; } else if (i1 == 2) { v0i1 = v0.z; u0i1 = u0.z; u1i1 = u1.z; u2i1 = u2.z; } a = u1i1 - u0i1; b = -(u1i0 - u0i0); c = -a * u0i0 - b * u0i1; d0 = a * v0i0 + b * v0i1 + c; a = u2i1 - u1i1; b = -(u2i0 - u1i0); c = -a * u1i0 - b * u1i1; d1 = a * v0i0 + b * v0i1 + c; a = u0i1 - u2i1; b = -(u0i0 - u2i0); c = -a * u2i0 - b * u2i1; d2 = a * v0i0 + b * v0i1 + c; if (d0 * d1 > 0.0f) { if (d0 * d2 > 0.0f) return true; } return false; } bool TriTriCoplanar(VEC n, VEC v0, VEC v1, VEC v2, VEC u0, VEC u1, VEC u2) { float a[3]; short i0, i1; a[0] = abs(n.x); a[1] = abs(n.y); a[2] = abs(n.z); if (a[0] > a[1]) { if (a[0] > a[2]) { i0 = 1; i1 = 2; } else { i0 = 0; i1 = 1; } } else { if (a[2] > a[1]) { i0 = 0; i1 = 1; } else { i0 = 0; i1 = 2; } } if (EdgeAgainstTriEdges(v0, v1, u0, u1, u2, i0, i1)) return true; if (EdgeAgainstTriEdges(v1, v2, u0, u1, u2, i0, i1)) return true; if (EdgeAgainstTriEdges(v2, v0, u0, u1, u2, i0, i1)) return true; if (PtInTri(v0, u0, u1, u2, i0, i1)) return true; if (PtInTri(u0, v0, v1, v2, i0, i1)) return true; return false; } bool ComputeIntervals(float vv0, float vv1, float vv2, float d0, float d1, float d2, float d0d1, float d0d2, float& a, float& b, float& c, float& x0, float& x1) { if (d0d1 > 0.0f) { a = vv2; b = (vv0 - vv2) * d2; c = (vv1 - vv2) * d2; x0 = d2 - d0; x1 = d2 - d1; } else if (d0d2 > 0.0f) { a = vv1; b = (vv0 - vv1) * d1; c = (vv2 - vv1) * d1; x0 = d1 - d0; x1 = d1 - d2; } else if (d1 * d2 > 0.0 || d0 != 0.0f) { a = vv0; b = (vv1 - vv0) * d0; c = (vv2 - vv0) * d0; x0 = d0 - d1; x1 = d0 - d2; } else if (d1 != 0.0f) { a = vv1; b = (vv0 - vv1) * d1; c = (vv2 - vv1) * d1; x0 = d1 - d0; x1 = d1 - d2; } else if (d2 != 0.0f) { a = vv2; b = (vv0 - vv2) * d2; c = (vv1 - vv2) * d2; x0 = d2 - d0; x1 = d2 - d1; } else return true; return false; }
  3. I'm porting dx6 game to dx9 I need to port D3DDP_DONOTUPDATEEXTENTS but I don't know about this. What is this? And how to port this?
  4. Hello. I'm modding a game code.(DX6 to DX9) But I have a problem http://i304.photobucket.com/albums/nn165/Fulon/a_zpsnhfugz2a.png Here is image. There are too many strange primitives. and they changed when I move cameras. What is the cause? Thanks.
  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!