void CPlane::Set(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3) { SFloat3 side1, side2; *mpsPosition = SFloat3(x1, y1, z1); side1 = SFloat3(x2, y2, z2) - *mpsPosition; side2 = SFloat3(x3, y3, z3) - *mpsPosition; CHalfSpace::Set2(mpsPosition, &side1, &side2); }
void FORCE_ALIGN_ARG_POINTER _ray_plane_cross_base(sfloat3* r_dir, sfloat3* r_ori, sfloat3* p_o, sfloat3* p_n, sfloat3* cross_point) { sfloat3 temp3 = SFloat3_sub(*p_o, *r_ori); temp3 = SFloat3_mul(temp3, *p_n); float a, b; a = SFloat3_dot(temp3, *p_n); sfloat3 temp1 = SFloat3(a, a, a); b = SFloat3_dot(*r_dir, *p_n); sfloat3 temp2 = SFloat3(b, b, b); temp1 = SFloat3_div(temp1, temp2); temp1 = SFloat3_mul(temp1, *r_dir); *cross_point = SFloat3_add(*r_ori, temp1); }
////////////////////////////////////////////////////////////////////////// // Directed Position ////////////////////////////////////////////////////////////////////////// // // ////////////////////////////////////////////////////////////////////////// void CDirectedInterpolator::Init(void) { PrivateInit(); msDir1 = msDir2 = SFloat3(0,0,0); mfDir1Length = 1.0f; mfDir2Length = -1.0f; }
/** result[0] = makePoint(x , y , z); result[1] = makePoint(x + width, y , z); result[2] = makePoint(x + width, y + height, z); result[3] = makePoint(x , y + height, z); make_plane_points<EFloat3, MakeEFloat3>(x, y, z, width, height, pos); **/ void SpriteRenderer::get_four_borders(float _x, float _y, float _width, float _height, FourBorders& fourBorder) { sfloat3 points[4]; float half_width = (float)width * 0.5f; float half_height = (float)height * 0.5f; _x -= half_width; _y -= half_height; make_plane_points<sfloat3, MakeSFloat3>(_x, _y, 0.0f, _width, _height, points); fourBorder.leftBorder.origin = SFloat3_cale_mid_point(points[0], points[3]); fourBorder.leftBorder.normal = SFloat3(1.0f, 0.0f, 0.0f); fourBorder.topBorder.origin = SFloat3_cale_mid_point(points[0], points[1]); fourBorder.topBorder.normal = SFloat3(0.0f, 1.0f, 0.0f); fourBorder.rightBorder.origin = SFloat3_cale_mid_point(points[1], points[2]); fourBorder.rightBorder.normal = SFloat3(-1.0f, 0.0f, 0.0f); fourBorder.bottomBorder.origin = SFloat3_cale_mid_point(points[2], points[3]); fourBorder.bottomBorder.normal = SFloat3(0.0f, -1.0f, 0.0f); }
void PositionHelperMakeQuarterCircle(CPosition* pcPosition, SFloat3* psCenter, float fRadius, int iQuadrant) { CDirectedInterpolator* pcInterpolator; SFloat3 cDir1, cDir2; SFloat3 cPos1, cPos2; pcPosition->Kill(); pcPosition->Init(); pcInterpolator = (CDirectedInterpolator*)pcPosition->Set(PT_DirectedPosition); cPos1 = *psCenter; cPos2 = *psCenter; cDir1 = SFloat3(0, 0, 0); cDir2 = cDir1; if (iQuadrant == 0) { cPos1.x -= fRadius; cPos2.y -= fRadius; cDir1.y -= fRadius; cDir2.x -= fRadius; } else if (iQuadrant == 1) { cPos1.y -= fRadius; cPos2.x += fRadius; cDir1.x += fRadius; cDir2.y -= fRadius; } else if (iQuadrant == 2) { cPos1.x += fRadius; cPos2.y += fRadius; cDir1.y += fRadius; cDir2.x += fRadius; } else if (iQuadrant == 3) { cPos1.y += fRadius; cPos2.x -= fRadius; cDir1.x -= fRadius; cDir2.y += fRadius; } pcInterpolator->SetEndpoints(&cPos1, &cPos2); pcInterpolator->SetDirections(&cDir1, &cDir2); }
void PositionHelperMakeHalfCos(CPosition* pcPosition, SFloat3* psStart, SFloat3* psEnd, float fAmplitude) { CDirectedInterpolator* pcInterpolator; SFloat3 cDir1; SFloat3 cDir3; SFloat3 cPerp; SFloat3 cNormal; pcPosition->Kill(); pcPosition->Init(); pcInterpolator = (CDirectedInterpolator*)pcPosition->Set(PT_DirectedPosition); cDir3 = *psEnd - *psStart; Float3Normalize(&cDir3, &cDir3); cPerp = SFloat3(0, 0, 1); Float3Cross(&cNormal, &cDir3, &cPerp); cDir1 = cNormal * (fAmplitude * 2.0f); pcInterpolator->SetEndpoints(psStart, psEnd); pcInterpolator->SetDirections(&cDir1, &cDir1); }
void version_0004_tangent_calculate(struct version_0004_data* data) { data->vtx_tgt = (float*)SMalloc(sizeof(float) * 3 * data->vtx_count); float* pos_end = data->vtx_pos + data->vtx_count * 3; float* tex_end = data->vtx_uv + data->vtx_count * 2; ///float* nor_end = data->vtx_nor + data->vtx_count * 3; float* tgt_end = data->vtx_tgt + data->vtx_count * 3; euint32* idx_end = data->indexs + data->indexed_vtx_count; euint32 i0, i1, i2; float x0, x1, y0, y1, z0, z1, s0, s1, t0, t1; for (euint a = 0; a < data->face_count; a++) { if ( &data->indexs[a * 3 + 2] >= idx_end ) return; i0 = data->indexs[a * 3 + 0]; i1 = data->indexs[a * 3 + 1]; i2 = data->indexs[a * 3 + 2]; float* v0 = &data->vtx_pos[i0 * 3]; float* v1 = &data->vtx_pos[i1 * 3]; float* v2 = &data->vtx_pos[i2 * 3]; if ( v0 + 2 >= pos_end || v1 + 2 >= pos_end || v2 + 2 >= pos_end ) return; float* w0 = &data->vtx_uv[i0 * 2]; float* w1 = &data->vtx_uv[i1 * 2]; float* w2 = &data->vtx_uv[i2 * 2]; if ( w0 + 1 >= tex_end || w1 + 1 >= tex_end ) return; x0 = v1[0] - v0[0]; x1 = v2[0] - v0[0]; y0 = v1[1] - v0[1]; y1 = v2[1] - v0[1]; z0 = v1[2] - v0[2]; z1 = v2[2] - v0[2]; s0 = w1[0] - w0[0]; s1 = w2[0] - w0[0]; t0 = w1[1] - w0[1]; t1 = w2[1] - w0[1]; float r = 1.0f / (s0 * t1 - s1 * t0); if ( &data->vtx_tgt[i0 * 3 + 2] >= tgt_end || &data->vtx_tgt[i1 * 3 + 2] >= tgt_end || &data->vtx_tgt[i2 * 3 + 2] >= tgt_end ) return; data->vtx_tgt[i0 * 3 ] += (s0 * x1 - s1 * x0) * r; data->vtx_tgt[i0 * 3 + 1] += (s0 * y1 - s1 * y0) * r; data->vtx_tgt[i0 * 3 + 2] += (s0 * z1 - s1 * z0) * r; data->vtx_tgt[i1 * 3 ] += (s0 * x1 - s1 * x0) * r; data->vtx_tgt[i1 * 3 + 1] += (s0 * y1 - s1 * y0) * r; data->vtx_tgt[i1 * 3 + 2] += (s0 * z1 - s1 * z0) * r; data->vtx_tgt[i2 * 3 ] += (s0 * x1 - s1 * x0) * r; data->vtx_tgt[i2 * 3 + 1] += (s0 * y1 - s1 * y0) * r; data->vtx_tgt[i2 * 3 + 2] += (s0 * z1 - s1 * z0) * r; } ///Float_Init(); data->vtx_binor = (float*)SMalloc(sizeof(float) * 3 * data->vtx_count); for (euint a = 0; a < data->vtx_count; a++) { float x = data->vtx_tgt[a * 3]; float y = data->vtx_tgt[a * 3 + 1]; float z = data->vtx_tgt[a * 3 + 2]; sfloat3 tgt = SFloat3(x, y, z); tgt = SFloat3_normalize(tgt); x = data->vtx_nor[a * 3]; y = data->vtx_nor[a * 3 + 1]; z = data->vtx_nor[a * 3 + 2]; sfloat3 nor = SFloat3(x, y, z); sfloat3 binor = SFloat3_cross(tgt, nor); tgt = SFloat3_cross(nor, binor); SFloat3_export(binor, &data->vtx_binor[a * 3]); SFloat3_export(tgt, &data->vtx_tgt[a * 3]); } }