Esempio n. 1
0
static PyObject * vec3_operator_mul(PyObject *left, PyObject *right)
{
	if(PyObject_TypeCheck(left, &vec3_type))
	{
		const vec3 & a = *(pybind_convertptr<vec3_wrapper>(left)->obj);

		if(PyObject_TypeCheck(right, &vec3_type))
		{
			const vec3 & b = *(pybind_convertptr<vec3_wrapper>(right)->obj);
			return vec3_make(a*b);
		}
		else if(PyFloat_Check(right))
		{
			const float b = (float)PyFloat_AsDouble(right);
			return vec3_make(a*b);
		}
	}
	else if(PyObject_TypeCheck(left, &PyFloat_Type))
	{
		const float a = (float)PyFloat_AsDouble(left);

		if(PyObject_TypeCheck(right, &vec3_type))
		{
			const vec3 & b = *(pybind_convertptr<vec3_wrapper>(right)->obj);
			return vec3_make(a*b);
		}
	}

	Py_RETURN_NOTIMPLEMENTED;
}
Esempio n. 2
0
void Frustum::build_box_frustum( const float* mtx, float left, float right, float bottom, float top, float front, float back )
{
    // Get points on front plane
    vec3_make(m_corners[0].m_vec, left, bottom, front);
    vec3_make(m_corners[1].m_vec, right, bottom, front);
    vec3_make(m_corners[2].m_vec, right, top, front);
    vec3_make(m_corners[3].m_vec, left, top, front);

    // Get points on far plane
    vec3_make(m_corners[4].m_vec, left, bottom, back);
    vec3_make(m_corners[5].m_vec, right, bottom, back);
    vec3_make(m_corners[6].m_vec, right, top, back);
    vec3_make(m_corners[7].m_vec, left, top, back);

    // Transform points to fit camera position and rotation
    vec3_make(m_origin, mtx[12], mtx[13], mtx[14]);
    for( uint32_t i = 0; i < 8; ++i )
    {
        float corner[3] = {m_corners[i].m_vec[0], m_corners[i].m_vec[1], m_corners[i].m_vec[2]};
        bx::vec3MulMtx(m_corners[i].m_vec, mtx, corner);
    }

    // Build planes
    bx::calcPlane(m_planes[0].m_data, m_corners[0].m_vec, m_corners[3].m_vec, m_corners[7].m_vec);//Left
    bx::calcPlane(m_planes[1].m_data, m_corners[2].m_vec, m_corners[1].m_vec, m_corners[6].m_vec);//Right
    bx::calcPlane(m_planes[2].m_data, m_corners[0].m_vec, m_corners[4].m_vec, m_corners[5].m_vec);//Bottom
    bx::calcPlane(m_planes[3].m_data, m_corners[3].m_vec, m_corners[2].m_vec, m_corners[6].m_vec);//Top
    bx::calcPlane(m_planes[4].m_data, m_corners[0].m_vec, m_corners[1].m_vec, m_corners[2].m_vec);//Front
    bx::calcPlane(m_planes[5].m_data, m_corners[4].m_vec, m_corners[7].m_vec, m_corners[6].m_vec);//Back
}
bool ShadingEnviromentCompiler::readJSON(const jsonxx::Object& root)
{
    BaseCompiler::readJSON(root);
    ShadingEnviroment shading;
    memset(&shading, 0x00, sizeof(shading));

    //init shading variables
    float fogParams[] = {10, 40, 0, 0};
    memcpy(shading.m_fog_params, fogParams, sizeof(fogParams));

    vec3_make(shading.m_ambient_sky_color, 0.37f, 0.55f, 0.66f);

    shading.m_shadow_area_size = 30.0f;
    shading.m_shadow_far = 100;
    vec3_make(shading.m_shadow_params, 0.01f, 0.001f, 0.0f);

    if(root.has<jsonxx::Object>("fog"))
    {
        const jsonxx::Object& o = root.get<jsonxx::Object>("fog");
        shading.m_fog_params[0] = json_to_float(o, "near", 10.0f);
        shading.m_fog_params[1] = json_to_float(o, "far", 40.0f);
        shading.m_fog_params[2] = json_to_float(o, "density", 0.0f);
        shading.m_fog_params[3] = json_to_float(o, "density", 0.0f);
    }

    json_to_floats(root, "ambient_sky_color", shading.m_ambient_sky_color, 3);
    json_to_floats(root, "ambient_ground_color", shading.m_ambient_ground_color, 3);

    if(root.has<jsonxx::Object>("shadow"))
    {
        const jsonxx::Object& o = root.get<jsonxx::Object>("shadow");
        shading.m_shadow_area_size = json_to_float(o, "area", 1.0f);
        shading.m_shadow_far = json_to_float(o, "far", 1.0f);
        shading.m_shadow_params[0] = json_to_float(o, "offset", 1.0f);
        shading.m_shadow_params[1] = json_to_float(o, "bias", 1.0f);
    }

    if(root.has<jsonxx::Object>("color_grading"))
    {
        const jsonxx::Object& o = root.get<jsonxx::Object>("color_grading");
        const jsonxx::Array& texturesValue = o.get<jsonxx::Array>("textures");
        shading.m_num_colorgrading_textures = texturesValue.size();
        for (uint32_t i=0; i<shading.m_num_colorgrading_textures; ++i)
        {
            const std::string& lutTexture = texturesValue.get<std::string>(i);
            shading.m_color_grading_texturenames[i] = stringid_caculate(lutTexture.c_str());
            addDependency("color_grading_texture", name_to_file_path(lutTexture.c_str(), EngineNames::TEXTURE_3D));
        }
        shading.m_colorgrading_index = json_to_int(o, "grading_index");
    }

    return write_file(m_output, &shading, sizeof(shading));
}
Esempio n. 4
0
void Frustum::build_view_frustum( const float* viewmtx, const float* projmtx )
{
    // This routine works with the OpenGL projection matrix
    // The view matrix is the inverse camera transformation matrix
    // Note: Frustum corners are not updated!
    float m[16];
    bx::mtxMul(m, viewmtx, projmtx);
    build_plane(m_planes[0].m_data, -(m[3] + m[0]), -(m[7] + m[4]), -(m[11] + m[8]), -(m[15] + m[12]));//Left
    build_plane(m_planes[1].m_data,  -(m[3] - m[0]), -(m[7] - m[4]), -(m[11] - m[8]), -(m[15] - m[12]) );//Right
    build_plane(m_planes[2].m_data,  -(m[3] + m[1]), -(m[7] + m[5]), -(m[11] + m[9]), -(m[15] + m[13]) );//Bottom
    build_plane(m_planes[3].m_data, -(m[3] - m[1]), -(m[7] - m[5]), -(m[11] - m[9]), -(m[15] - m[13]) );//Top
    build_plane(m_planes[4].m_data, -(m[3] + m[2]), -(m[7] + m[6]), -(m[11] + m[10]), -(m[15] + m[14]) );//Near
    build_plane(m_planes[5].m_data, -(m[3] - m[2]), -(m[7] - m[6]), -(m[11] - m[10]), -(m[15] - m[14]) );//Far

    float invview[16];
    bx::mtxInverse(invview, viewmtx);
    vec3_make(m_origin, invview[12], invview[13], invview[14]);

    float mm[16];
    bx::mtxInverse(mm, m);

    float corner[4];
    float mv[4];
    // 0.
    mv[0] = -1; mv[1] = -1; mv[2] = -1; mv[3] = 1;
    bx::vec4MulMtx(corner, mv, mm);
    vec3_make(m_corners[0].m_vec, corner[0]/corner[3], corner[1]/corner[3], corner[2]/corner[3]);
    // 1.
    mv[0] = 1; mv[1] = -1; mv[2] = -1; mv[3] = 1;
    bx::vec4MulMtx(corner, mv, mm);
    vec3_make(m_corners[1].m_vec, corner[0]/corner[3], corner[1]/corner[3], corner[2]/corner[3]);
    // 2.
    mv[0] = 1; mv[1] = 1; mv[2] = -1; mv[3] = 1;
    bx::vec4MulMtx(corner, mv, mm);
    vec3_make(m_corners[2].m_vec, corner[0]/corner[3], corner[1]/corner[3], corner[2]/corner[3]);
    //3.
    mv[0] = -1; mv[1] = 1; mv[2] = -1; mv[3] = 1;
    bx::vec4MulMtx(corner, mv, mm);
    vec3_make(m_corners[3].m_vec, corner[0]/corner[3], corner[1]/corner[3], corner[2]/corner[3]);
    //4.
    mv[0] = -1; mv[1] = -1; mv[2] = 1; mv[3] = 1;
    bx::vec4MulMtx(corner, mv, mm);
    vec3_make(m_corners[4].m_vec, corner[0]/corner[3], corner[1]/corner[3], corner[2]/corner[3]);
    //5.
    mv[0] = 1; mv[1] = -1; mv[2] = 1; mv[3] = 1;
    bx::vec4MulMtx(corner, mv, mm);
    vec3_make(m_corners[5].m_vec, corner[0]/corner[3], corner[1]/corner[3], corner[2]/corner[3]);
    //6.
    mv[0] = 1; mv[1] = 1; mv[2] = 1; mv[3] = 1;
    bx::vec4MulMtx(corner, mv, mm);
    vec3_make(m_corners[6].m_vec, corner[0]/corner[3], corner[1]/corner[3], corner[2]/corner[3]);
    //7.
    mv[0] = -1; mv[1] = 1; mv[2] = 1; mv[3] = 1;
    bx::vec4MulMtx(corner, mv, mm);
    vec3_make(m_corners[7].m_vec, corner[0]/corner[3], corner[1]/corner[3], corner[2]/corner[3]);
}
Esempio n. 5
0
bool ReachIKCompiler::readJSON( const jsonxx::Object& root )
{
    BaseCompiler::readJSON(root);
    ReachResource reach;
    memset(&reach, 0x00, sizeof(reach));

    vec3_make(reach.m_elbowAxis, 0, 1, 0);
    json_to_floats(root, "elbow_axis", reach.m_elbowAxis, 3);

    reach.m_hingeLimitAngle[0] = 0;
    reach.m_hingeLimitAngle[1] = 180;

    json_to_floats(root, "hinge_limit_angle", reach.m_hingeLimitAngle, 2);

    reach.m_reachGain = json_to_float(root, "reach_gain", 0.3f);
    reach.m_leaveGain = json_to_float(root, "leave_gain", 0.19f);
    reach.m_moveGain = json_to_float(root, "move_gain", 0.085f);
    reach.m_targetGain = json_to_float(root, "target_gain", 0.2f);
    reach.m_index = json_to_enum(root, "hand", left_right_names);

    const std::string& rigFile = root.get<std::string>("rig");
    reach.m_rigName = stringid_caculate(rigFile.c_str());
    addDependency("rig", name_to_file_path(rigFile, EngineNames::ANIMATION_RIG));

    return write_file(m_output, &reach, sizeof(reach));
}
Esempio n. 6
0
void scene_init(Scene *scene, size_t width, size_t height) {
    array_init(&scene->surfaces, INIT_CAPACITY, sizeof(Surface));
    array_init(&scene->lights, INIT_CAPACITY, sizeof(Light));
    camera_init(&scene->camera, VEC3_ZERO, vec3_make(0, 0, 1), 430.0, width, height);
    scene->ambientCoefficient = 0.6;
    scene->backgroundColor = COLOR_WHITE;
}
Esempio n. 7
0
bool FootIKCompiler::readJSON( const jsonxx::Object& root )
{
    BaseCompiler::readJSON(root);
    FootResource foot;
    memset(&foot, 0x00, sizeof(foot));

    vec3_make(foot.m_leftKneeAxisLS, 0, 0, 1);
    vec3_make(foot.m_rightKneeAxisLS, 0, 0, 1);
    vec3_make(foot.m_footEndLS, 0, 0, 0.2f);

    json_to_floats(root, "left_knee_axis", foot.m_leftKneeAxisLS, 3);
    json_to_floats(root, "right_knee_axis", foot.m_rightKneeAxisLS, 3);
    json_to_floats(root, "foot_end_ls", foot.m_footEndLS, 3);

    foot.m_orignalGroundHeightMS = json_to_float(root, "orignal_ground_height_ms");
    foot.m_minAnkleHeightMS = json_to_float(root, "min_ankle_height_ms");
    foot.m_maxAnkleHeightMS = json_to_float(root, "max_ankle_height_ms");
    foot.m_footPlantedAnkleHeightMS = json_to_float(root, "foot_planted_ankle_height_ms");
    foot.m_footRaisedAnkleHeightMS = json_to_float(root, "foot_raised_ankle_height_ms");
    foot.m_cosineMaxKneeAngle = json_to_float(root, "max_consine_knee_angle", 180);
    foot.m_cosineMinKneeAngle = json_to_float(root, "min_consine_knee_angle", 0);
    foot.m_raycastDistanceUp = json_to_float(root, "raycast_dis_up", 0.5f);
    foot.m_raycastDistanceDown = json_to_float(root, "raycast_dis_down", 0.8f);
    foot.m_raycastCollisionLayer = json_to_stringid(root, "raycast_layer");
    foot.m_groundAscendingGain =  json_to_float(root, "ground_ascending_gain", 0.35f);
    foot.m_groundDescendingGain =  json_to_float(root, "ground_descending_gain", 0.6f);
    foot.m_standAscendingGain =  json_to_float(root, "ground_ascending_gain", 0.6f);
    foot.m_footPlantedGain =  json_to_float(root, "foot_planted_gain", 1.0f);
    foot.m_footRaisedGain =  json_to_float(root, "foot_raised_gain", 0.85f);
    foot.m_footOnOffGain =  json_to_float(root, "foot_onoff_gain", 0.2f);
    foot.m_footUnLockGain =  json_to_float(root, "foot_unlock_gain", 0.85f);
    foot.m_pelvisFeedback =  json_to_float(root, "pelvis_feedback", 0.1f);
    foot.m_pelvisUpDownBias =  json_to_float(root, "pelvis_updown_bias", 0.95f);
    foot.m_raycastType = json_to_enum(root, "raycast_type", raycast_type_names, 0);

    const std::string& rigFile = root.get<std::string>("rig");
    foot.m_rigName = stringid_caculate(rigFile.c_str());
    addDependency("rig", name_to_file_path(rigFile, EngineNames::ANIMATION_RIG));

    return write_file(m_output, &foot, sizeof(foot));
}
Esempio n. 8
0
void Frustum::build_view_frustum( const float* mtx, float left, float right, float bottom, float top, float nearPlane, float farPlane )
{
    // Use intercept theorem to get params for far plane
    float left_f = left * farPlane / nearPlane;
    float right_f = right * farPlane / nearPlane;
    float bottom_f = bottom * farPlane / nearPlane;
    float top_f = top * farPlane / nearPlane;

    // Get points on near plane
    vec3_make(m_corners[0].m_vec, left, bottom, -nearPlane);
    vec3_make(m_corners[1].m_vec, right, bottom, -nearPlane);
    vec3_make(m_corners[2].m_vec, right, top, -nearPlane);
    vec3_make(m_corners[3].m_vec, left, top, -nearPlane);

    // Get points on far plane
    vec3_make(m_corners[4].m_vec, left_f, bottom_f, -farPlane);
    vec3_make(m_corners[5].m_vec, right_f, bottom_f, -farPlane);
    vec3_make(m_corners[6].m_vec, right_f, top_f, -farPlane);
    vec3_make(m_corners[7].m_vec, left_f, top_f, -farPlane);

    // Transform points to fit camera position and rotation
    vec3_make(m_origin, mtx[12], mtx[13], mtx[14]);
    for( uint32_t i = 0; i < 8; ++i )
    {
        float corner[3] = {m_corners[i].m_vec[0], m_corners[i].m_vec[1], m_corners[i].m_vec[2]};
        bx::vec3MulMtx(m_corners[i].m_vec, mtx, corner);
    }

    // Build planes
    bx::calcPlane(m_planes[0].m_data, m_origin, m_corners[3].m_vec, m_corners[0].m_vec); // Left
    bx::calcPlane(m_planes[1].m_data, m_origin, m_corners[1].m_vec, m_corners[2].m_vec); // Right
    bx::calcPlane(m_planes[2].m_data, m_origin, m_corners[0].m_vec, m_corners[1].m_vec); // Bottom
    bx::calcPlane(m_planes[3].m_data, m_origin, m_corners[2].m_vec, m_corners[3].m_vec); // Top
    bx::calcPlane(m_planes[4].m_data, m_corners[0].m_vec, m_corners[1].m_vec, m_corners[2].m_vec); // Near
    bx::calcPlane(m_planes[5].m_data, m_corners[5].m_vec, m_corners[4].m_vec, m_corners[7].m_vec); // Far
}
Esempio n. 9
0
bool LookIKCompiler::readJSON( const jsonxx::Object& root )
{
    BaseCompiler::readJSON(root);
    LookAtResource lookat;
    memset(&lookat, 0x00, sizeof(lookat));

    vec3_make(lookat.m_fwdLS, 0, 0, 1);
    json_to_floats(root, "forward_ls", lookat.m_fwdLS, 3);

    lookat.m_lookAtLimit = json_to_float(root, "lookat_limit", 3.1415926f/4.0f);
    lookat.m_gain = json_to_float(root, "gain", 0.05f);
    lookat.m_targetGain =  json_to_float(root, "target_gain", 0.2f);

    const std::string& rigFile = root.get<std::string>("rig");
    lookat.m_rigName = stringid_caculate(rigFile.c_str());
    addDependency("rig", name_to_file_path(rigFile, EngineNames::ANIMATION_RIG));

    return write_file(m_output, &lookat, sizeof(lookat));
}
Esempio n. 10
0
void scene_loadTeapotDemo(Scene *scene) {
    Material teapotMaterial = material_make(COLOR_WHITE, 0.2, 0, 20);
    scene_loadMesh(scene, "teapot.txt", teapotMaterial);
    
    scene->backgroundColor = COLORS1_BLUE;
    Light light = light_make(vec3_make(10, 10, -20), 1.0);
    scene_AddLight(scene, &light);
    scene->ambientCoefficient = 0.6;
    camera_init(&scene->camera, vec3_make(0, 5, -10), vec3_make(0, -0.4, 1), 800.0,
                scene->camera.width, scene->camera.height);
    
    Material screenMaterial = material_make(COLORS1_BLUE, 0, 0, 200);
    Vector3 vs[8];
    vs[0] = vec3_make(-500, -500, -30);
    vs[1] = vec3_make(-500, 500, -30);
    vs[2] = vec3_make(500, 500, -30);
    vs[3] = vec3_make(500, -500, -30);
    
    vs[4] = vec3_make(-500, -500, 5);
    vs[5] = vec3_make(-500, 500, 5);
    vs[6] = vec3_make(500, 500, 5);
    vs[7] = vec3_make(500, -500, 5);
    Surface triangles[2]; // Back wall
    triangles[0] = surface_initTriangle(vs[6], vs[5], vs[4], screenMaterial);
    triangles[1] = surface_initTriangle(vs[7], vs[6], vs[4], screenMaterial);
    scene_addSurfaceRange(scene, triangles, 2);
}
Esempio n. 11
0
void scene_loadSpheresDemo(Scene *scene) {
    Surface spheres[5];
    Surface triangles[12];
    Vector3 vs[12];
    Light lights[4];
    scene->ambientCoefficient = 0.7;
    camera_init(&scene->camera, vec3_make(0, 35, -70), vec3_make(0, 0, 1), 500.0,
                scene->camera.width, scene->camera.height);
    lights[0] = light_make(vec3_make(60, 80, -30), 1.0);
    lights[1] = light_make(vec3_make(-30, 65, -300), 0.3);
    spheres[1] = surface_initSphere(vec3_make(45, -20, 70), 20,
                                   material_make(COLOR_GREEN, 0.5, 0.05, 20.2));
    spheres[2] = surface_initSphere(vec3_make(-35, -25, 80), 15,
                                   material_make(COLOR_BLUE, 0.5, 0.02, 100));
    spheres[0] = surface_initSphere(vec3_make(10, -10, 110), 30,
                                   material_make(COLOR_RED, 0.5, 0.01, 40.0));
    spheres[3] = surface_initSphere(vec3_make(10, 40, 110), 25,
                                   material_make(COLOR_BLUE, 0.5, 0, 40));
    spheres[4] = surface_initSphere(vec3_make(10, 80, 110), 20,
                                   material_make(COLOR_GREEN, 0.5, 0, 40));
    Material sideWallMaterial1 = material_make(COLOR_WHITE, 0.0, 0, 40);
    Material sideWallMaterial2 = material_make(COLOR_WHITE, 0.0, 0, 40);
    Material ceilingMaterial = material_make(COLOR_WHITE, 0.4, 0.15, 40);
    Material floorMaterial = material_make(COLOR_WHITE, 0.4, 0.15, 40);
    vs[0] = vec3_make(-75, -40, 0);
    vs[1] = vec3_make(-75, -40, 150);
    vs[2] = vec3_make(75, -40, 0);
    vs[3] = vec3_make(75, -40, 150);
    vs[4] = vec3_make(-75, 110, 0);
    vs[5] = vec3_make(-75, 110, 150);
    vs[6] = vec3_make(75, 110, 0);
    vs[7] = vec3_make(75, 110, 150);
    vs[8] = vec3_make(-75, -40, -700);
    vs[9] = vec3_make(75, -40, -700);
    vs[10] = vec3_make(75, 110, -700);
    vs[11] = vec3_make(-75, 110, -700);
    //Floor
    triangles[0] = surface_initTriangle(vs[2], vs[1], vs[0], floorMaterial);
    triangles[1] = surface_initTriangle(vs[2], vs[3], vs[1], floorMaterial);
    //Left wall
    triangles[2] = surface_initTriangle(vs[0], vs[1], vs[4], sideWallMaterial1);
    triangles[3] = surface_initTriangle(vs[1], vs[5], vs[4], sideWallMaterial1);
    //Right wall
    triangles[4] = surface_initTriangle(vs[6], vs[3], vs[2], sideWallMaterial1);
    triangles[5] = surface_initTriangle(vs[6], vs[7], vs[3], sideWallMaterial1);
    //Ceiling
    triangles[6] = surface_initTriangle(vs[4], vs[5], vs[6], ceilingMaterial);
    triangles[7] = surface_initTriangle(vs[5], vs[7], vs[6], ceilingMaterial);
    //Back
    triangles[8] = surface_initTriangle(vs[3], vs[7], vs[5], sideWallMaterial2);
    triangles[9] = surface_initTriangle(vs[5], vs[1], vs[3], sideWallMaterial2);
    triangles[10] = surface_initTriangle(vs[8], vs[9], vs[10], sideWallMaterial1);
    triangles[11] = surface_initTriangle(vs[8], vs[10], vs[11], sideWallMaterial1);
    scene_addSurfaceRange(scene, spheres, 5);
    scene_addSurfaceRange(scene, triangles, 12);
    scene_AddLightRange(scene, lights, 2);
}
Esempio n. 12
0
static vec3_wrapper * vec3_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
	printf("type new\n");
	return vec3_make();
}