コード例 #1
0
ファイル: CroquetPlugin.c プロジェクト: lsehub/ObjectLayers
EXPORT(sqInt) primitiveTransformDirection(void) {
    double rz;
    double z;
    double ry;
    sqInt v3Oop;
    double y;
    double rx;
    float *vertex;
    double x;
    float *matrix;

	if (!((interpreterProxy->methodArgumentCount()) == 1)) {
		return interpreterProxy->primitiveFail();
	}
	v3Oop = interpreterProxy->stackObjectValue(0);
	if (interpreterProxy->failed()) {
		return null;
	}
	if (!((interpreterProxy->isWords(v3Oop)) && ((interpreterProxy->slotSizeOf(v3Oop)) == 3))) {
		return interpreterProxy->primitiveFail();
	}
	vertex = interpreterProxy->firstIndexableField(v3Oop);
	matrix = stackMatrix(1);
	if (matrix == null) {
		return interpreterProxy->primitiveFail();
	}
	x = vertex[0];
	y = vertex[1];
	z = vertex[2];
	rx = ((x * (matrix[0])) + (y * (matrix[1]))) + (z * (matrix[2]));
	ry = ((x * (matrix[4])) + (y * (matrix[5]))) + (z * (matrix[6]));
	rz = ((x * (matrix[8])) + (y * (matrix[9]))) + (z * (matrix[10]));
	v3Oop = interpreterProxy->clone(v3Oop);
	vertex = interpreterProxy->firstIndexableField(v3Oop);
	vertex[0] = (((float) rx));
	vertex[1] = (((float) ry));
	vertex[2] = (((float) rz));
	interpreterProxy->pop(2);
	interpreterProxy->push(v3Oop);
}
コード例 #2
0
EXPORT(sqInt) primitiveInplaceHouseHolderInvert(void) {
    double sum;
    double beta;
    sqInt k;
    sqInt j;
    double d[4][4];
    sqInt i;
    double s;
    float *rcvr;
    double x[4][4] = { {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} };
    double m[4][4];
    sqInt r;
    double sigma;

    ;
    rcvr = stackMatrix(0);
    for (i = 0; i <= 3; i += 1) {
        for (j = 0; j <= 3; j += 1) {
            (m[i])[j] = (rcvr[(i * 4) + j]);
        }
    }
    for (j = 0; j <= 3; j += 1) {
        sigma = 0.0;
        for (i = j; i <= 3; i += 1) {
            sigma += ((m[i])[j]) * ((m[i])[j]);
        }
        if (sigma < 1.0e-10) {
            return interpreterProxy->primitiveFail();
        }
        if (((m[j])[j]) < 0.0) {
            s = sqrt(sigma);
        } else {
            s = 0.0 - (sqrt(sigma));
        }
        for (r = 0; r <= 3; r += 1) {
            (d[j])[r] = s;
        }
        beta = 1.0 / ((s * ((m[j])[j])) - sigma);
        (m[j])[j] = (((m[j])[j]) - s);
        for (k = (j + 1); k <= 3; k += 1) {
            sum = 0.0;
            for (i = j; i <= 3; i += 1) {
                sum += ((m[i])[j]) * ((m[i])[k]);
            }
            sum = sum * beta;
            for (i = j; i <= 3; i += 1) {
                (m[i])[k] = (((m[i])[k]) + (((m[i])[j]) * sum));
            }
        }
        for (r = 0; r <= 3; r += 1) {
            sum = 0.0;
            for (i = j; i <= 3; i += 1) {
                sum += ((x[i])[r]) * ((m[i])[j]);
            }
            sum = sum * beta;
            for (i = j; i <= 3; i += 1) {
                (x[i])[r] = (((x[i])[r]) + (sum * ((m[i])[j])));
            }
        }
    }
    for (r = 0; r <= 3; r += 1) {
        for (i = 3; i >= 0; i += -1) {
            for (j = (i + 1); j <= 3; j += 1) {
                (x[i])[r] = (((x[i])[r]) - (((x[j])[r]) * ((m[i])[j])));
            }
            (x[i])[r] = (((x[i])[r]) / ((d[i])[r]));
        }
    }
    for (i = 0; i <= 3; i += 1) {
        for (j = 0; j <= 3; j += 1) {
            rcvr[(i * 4) + j] = (((float) ((x[i])[j])));
        }
    }
}