コード例 #1
0
static int global_physics_sweep_col_mesh (lua_State *L)
{
TRY_START
        int base_line = 7;
        check_args_min(L, base_line);

        std::string col_mesh_name = check_path(L, 1);
        DiskResource *col_mesh_ = disk_resource_get_or_make(col_mesh_name);
        CollisionMesh *col_mesh = dynamic_cast<CollisionMesh*>(col_mesh_);
        Quaternion q = check_quat(L, 2);
        Vector3 start = check_v3(L, 3);
        Vector3 ray = check_v3(L, 4);
        bool nearest_only = check_bool(L, 5);
        unsigned long flags = check_t<unsigned long>(L, 6);
        if (lua_type(L, 7) != LUA_TFUNCTION)
                my_lua_error(L, "Parameter 5 should be a function.");

        LuaSweepCallback lcb(nearest_only, flags);
        init_cast_blacklist(L, base_line, lcb);

        physics_sweep_col_mesh(start, q, start + ray, q, lcb, col_mesh);

        push_cfunction(L, my_lua_error_handler);
        int error_handler = lua_gettop(L);

        lcb.pushResults(L, 7, error_handler);
        return 0;
TRY_END
}
コード例 #2
0
static int global_physics_cast_ray (lua_State *L)
{
TRY_START
        int base_line = 4;
        check_args_min(L, base_line);

        Vector3 start = check_v3(L, 1);
        Vector3 ray = check_v3(L, 2);
        bool nearest_only = check_bool(L, 3);
        unsigned long flags = check_t<unsigned long>(L, 4);

        LuaSweepCallback lcb(nearest_only, flags);
        init_cast_blacklist(L, base_line, lcb);

        physics_ray(start, start+ray, lcb);

        return lcb.pushResults(L);

TRY_END
}
コード例 #3
0
static int global_physics_sweep_cylinder (lua_State *L)
{
TRY_START
        int base_line = 7;
        check_args_min(L, base_line);

        float radius = check_float(L, 1);
        float height = check_float(L, 2);
        Quaternion q = check_quat(L, 3);
        Vector3 start = check_v3(L, 4);
        Vector3 ray = check_v3(L, 5);
        bool nearest_only = check_bool(L, 6);
        unsigned long flags = check_t<unsigned long>(L, 7);

        LuaSweepCallback lcb(nearest_only, flags);
        init_cast_blacklist(L, base_line, lcb);

        physics_sweep_cylinder(start, q, start+ray, lcb, radius, height);

        return lcb.pushResults(L);

TRY_END
}
コード例 #4
0
void Ship::output(){
	ofstream file;
	file.open("Report.txt");
	file << "[table]" << endl;

	cout << fixed << setprecision(2) << "Length: \t\t\t\t" << v.Lpp << " m" << endl;
	file << fixed << setprecision(2) << "[tr][td]Length: \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t[/td][td]" << v.Lpp << " m[/td][/tr]" << endl;
	cout << "Beam: \t\t\t\t\t" << v.B << " m" << endl;
	file << "[tr][td]Beam: [/td][td]" << v.B << " m[/td][/tr]" << endl;
	cout << "Draft: \t\t\t\t\t" << v.D << " m" << endl;
	file << "[tr][td]Draft: [/td][td]" << v.D << " m[/td][/tr]" << endl;
	cout << "Freeboard: \t\t\t\t" << v.fB << " m" << endl;
	file << "[tr][td]Freeboard: [/td][td]" << v.fB << " m[/td][/tr]" << endl;
	cout << setprecision(3) << "Block Coefficient: \t\t\t" << Cb() << endl;
	file << setprecision(3) << "[tr][td]Block Coefficient: [/td][td]" << Cb() << "[/td][/tr]" << endl;
	cout << setprecision(0) << "Displacement: \t\t\t\t" << Vol() << " t" << endl;
	file << setprecision(0) << "[tr][td]Displacement: [/td][td]" << Vol() << " t[/td][/tr]" << endl;
	cout << "Lightship: \t\t\t\t" << Wh() + Wwo() + Wm() + We() + Wspus() + Bunker() << " t" << endl;
	file << "[tr][td]Lightship: [/td][td]" << Lightship() << " t[/td][/tr]" << endl;

	cout << setprecision(1) << "\nMax Speed: \t\t\t\t" << v.Vk << " kn" << endl;
	file << setprecision(1) << "\n[tr][td]Max Speed: [/td][td]" << v.Vk << " kn[/td][/tr]" << endl;
	cout << "Cruise Speed: \t\t\t\t" << v.Vc << " kn / " << v.Range << " nm" << endl;
	file << "[tr][td]Cruise Speed: [/td][td]" << v.Vc << " kn / " << v.Range << " nm[/td][/tr]" << endl;

	cout << "Engine: \t\t\t\t";
	file << "[tr][td]Engine: [/td][td]";
	switch(e.Gear){
		case Direct:
            cout << "Direct ";
            file << "Direct ";
            break;
		case Geared:
		    cout << "Geared ";
		    file << "Geared ";
		    break;
		case Turbo_Electric:
		    cout << "Turbo-Electric ";
		    file << "Turbo-Electric ";
            break;
		default:
            cout << "Unknown";
            file << "Unknown";
	}
	switch(e.Eng){
		case Diesel2stk:
		    cout << "Two Stroke Diesel" << endl;
		    file << "Two Stroke Diesel";
		    break;
		case Diesel4stk:
		    cout << "Four Stroke Diesel" << endl;
		    file << "Four Stroke Diesel" << endl;
		    break;
		case QuadExp:
		    cout << "Quadruple Expansion Reciprocating Engine" << endl;
		    file << "Quadruple Expansion Reciprocating Engine";
		    break;
		case TripExp:
		    cout << "Triple Expansion Reciprocating Engine" << endl;
		    file << "Triple Expansion Reciprocating Engine";
		    break;
		case SimExp:
		    cout << "Simple Reciprocating Engine" << endl;
		    file << "Simple Reciprocating Engine";
		    break;
		case SteamTur:
		    cout << "Steam Turbine" << endl;
		    file << "Steam Turbine";
		    break;
		default:
            cout << endl;
	}
	file << "[/td][/tr]" << endl;

	cout << setprecision(0) << "Power Delivered: \t\t\t" << Pd(v.Vk) << " hp" << endl;
	file << setprecision(0) << "[tr][td]Power Delivered: [/td][td]" << Pd(v.Vk) << " hp[/td][/tr]" << endl;
	cout << setprecision(2) << "Total Efficiency: \t\t\t" << NUt()*100 << "%" << endl;
	file << setprecision(2) << "[tr][td]Total Efficiency: [/td][td]" << NUt()*100 << "%[/td][/tr]" << endl;
	cout << setprecision(3) << "Froude Number: \t\t\t\t" << Fn() << endl;
	file << setprecision(3) << "[tr][td]Froude Number: [/td][td]" << Fn()  << "[/td][/tr]" << endl;
	cout << setprecision(0) << "Bunker Size: \t\t\t\t" << Bunker() << " t" << endl;
	file << setprecision(0) << "[tr][td]Bunker Size: [/td][td]" << Bunker() << " t[/td][/tr]" << endl;
	cout << "Service Allowance: \t\t\t" << e.SA << "%" << endl;
	file << "[tr][td]Service Allowance: [/td][td]" << e.SA << "%[/td][/tr]" << endl;

	cout << setprecision(2);
	file << setprecision(2);
	cout << "Length of Superstructure: \t\t" << v.Lspus << " m" << endl;
	file << "[tr][td]Length of Superstructure: [/td][td]" << v.Lspus << " m[/td][/tr]" << endl;

	cout << "Aftbody Shape: \t\t\t\t";
	file << "[tr][td]Aftbody Shape: [/td][td]";
	switch(e.Faa){
		case V:
		    cout << "V" << endl;
		    file << "V";
		    break;
		case U:
		    cout << "U" << endl;
		    file << "U";
		    break;
		case N:
		    cout << "N" << endl;
		    file << "N";
		    break;
		default:
		    cout << "N" << endl;
		    file << "N";
	}
	file << "[/td][/tr]";

	cout << "\nLongitudinal Center of Buoyancy: \t" << lcb() << "%" << endl;
	file << "\n[tr][td]Longitudinal Center of Buoyancy: [/td][td]" << lcb() << "% / " << lcb()*v.Lpp << " m from midpoint[/td][/tr]" << endl;
	cout << "Longitudinal Center of Gravity: \t" << lcg() << "%" << endl;
	file << "[tr][td]Longitudinal Center of Gravity: [/td][td]" << lcg() << "% / " << lcg()*v.Lpp << " m from midpoint[/td][/tr]" << endl;

	cout << "Vertical Center of Gravity: \t\t" << KGh() << " m" << endl;
	file << "[tr][td]Vertical Center of Gravity: [/td][td]" << KGh() << " m[/td][/tr]" << endl;
	cout << "Metacentric Height: \t\t\t" << GM() << " m" << endl;
	file << "[tr][td]Metacentric Height: [/td][td]" << GM() << " m[/td][/tr]" << endl;
	cout << "Roll Period: \t\t\t\t" << TR() << " s" << endl;
	file << "[tr][td]Roll Period: [/td][td]" << TR() << " s[/td][/tr]" << endl;

	cout << "\nBow Entrance Angle: \t\t\t" << iE() << " deg" << endl;
	file << "\n[tr][td]Bow Entrance Angle: [/td][td]" << iE() << " deg[/td][/tr]" << endl;
	cout << "Length of Engine Room: \t\t\t" << Lcm() << " m" << endl;
	file << "[tr][td]Length of Engine Room: [/td][td]" << Lcm() << " m[/td][/tr]" << endl;

	cout << setprecision(0) << "\nMain Belt: \t\t\t\t" << arm.mb_Ttop << " / " << arm.mb_Tbot << " mm at " << arm.b_deg << " degrees, " << arm.b_L << " m long with " << arm.b_H << " m above and " << arm.b_Db << " m below water" << endl;
	file << setprecision(0) << "\n[tr][td]Main Belt: [/td][td]" << arm.mb_Ttop << " / " << arm.mb_Tbot << " mm, " << arm.b_L << " m long with " << arm.b_H << " m above and " << arm.b_Db << " m below water[/td][/tr]" << endl;

	cout << "End Belt: \t\t\t\t" << arm.eb_Ttop << " / " << arm.eb_Tbot << " mm" << endl;
	file << "[tr][td]End Belt: [/td][td]" << arm.eb_Ttop << " / " << arm.eb_Tbot << " mm[/td][/tr]" << endl;

	cout << "Upper Belt: \t\t\t\t" << arm.ub_Ttop << " / " << arm.ub_Tbot << " mm, " << arm.b_uL << " m long" << endl;
	file << "[tr][td]Upper Belt: [/td][td]" << arm.ub_Ttop << " / " << arm.ub_Tbot << " mm, " << arm.b_uL << " m long[/td][/tr]" << endl;

	cout << "Main Deck: \t\t\t\t" << arm.md_T << " mm covering " << arm.md_P << "% / " << arm.md_P * v.Lpp << " m of deck" << endl;
	file << "[tr][td]Main Deck: [/td][td]" << arm.md_T << " m covering " << arm.md_P << "% / " << arm.md_P * v.Lpp << " m of deck[/td][/tr]" << endl;
	cout << "Weather Deck: \t\t\t\t" << arm.wd_T << " mm covering " << arm.wd_P << "% / " << arm.wd_P * v.Lpp << " m of deck" << endl;
	file << "[tr][td]Weather Deck: [/td][td]" << arm.wd_T << " m covering " << arm.wd_P << "% / " << arm.wd_P * v.Lpp << " m of deck[/td][/tr]" << endl;
	cout << "Splinter Deck: \t\t\t\t" << arm.sd_T << " mm covering " << arm.sd_P << "% / " << arm.sd_P * v.Lpp << " m of deck" << endl;
	file << "[tr][td]Splinter Deck: [/td][td]" << arm.sd_T << " m covering " << arm.sd_P << "% / " << arm.sd_P * v.Lpp << " m of deck[/td][/tr]" << endl;
	cout << "Ends Deck: \t\t\t\t" << arm.ed_T << " mm" << endl;
	file << "[tr][td]Ends Deck: [/td][td]" << arm.ed_T << " mm[/td][/tr]" << endl;

	cout << "Bulkhead: \t\t\t\t" << arm.blk_T << " mm in " << arm.blk_Lct << "x" << arm.blk_D << " m layers, " << arm.blk_L << " m long, " << arm.blk_H << " m tall" << endl;
	file << "[tr][td]Bulkhead: [/td][td]" << arm.blk_T << " mm in " << arm.blk_Lct << "x" << arm.blk_D << " m layers, " << arm.blk_L << " m long, " << arm.blk_H << " m tall[/td][/tr]" << endl;

	file << "[/table]" << endl;

    file.close();
}
コード例 #5
0
float Ship::iE(){
	float c1 = - pow(v.Lpp / v.B, 0.80856) * pow(1 - Cw(), 0.30484) * pow(1 - Cp() - 0.0225 * lcb(), 0.6367) * pow(lr() / v.B, 0.34574) * pow(100 * Vol() / pow(v.Lpp, 3.), 0.16302);
	return 1 + 89 * exp(c1);
}
コード例 #6
0
float Ship::lr(){
	return v.Lpp * (1 - Cp() + 0.06 * Cp() * lcb()) / (4 * Cp() - 1);
}
コード例 #7
0
float Ship::AeAo(){
	return (NUr - 0.9922 - 0.07424 * (Cp() - 0.0225 * lcb())) / -0.05908;
}
コード例 #8
0
ファイル: th_lua_anims.cpp プロジェクト: CorsixTH/CorsixTH
void lua_register_anims(const lua_register_state *pState)
{
    // Anims
    {
        lua_class_binding<animation_manager> lcb(pState, "anims", l_anims_new, lua_metatable::anims);
        lcb.add_function(l_anims_load, "load");
        lcb.add_function(l_anims_loadcustom, "loadCustom");
        lcb.add_function(l_anims_set_spritesheet, "setSheet", lua_metatable::sheet);
        lcb.add_function(l_anims_set_canvas, "setCanvas", lua_metatable::surface);
        lcb.add_function(l_anims_getanims, "getAnimations");
        lcb.add_function(l_anims_getfirst, "getFirstFrame");
        lcb.add_function(l_anims_getnext, "getNextFrame");
        lcb.add_function(l_anims_set_alt_pal, "setAnimationGhostPalette");
        lcb.add_function(l_anims_set_marker, "setFrameMarker");
        lcb.add_function(l_anims_set_secondary_marker, "setFrameSecondaryMarker");
        lcb.add_function(l_anims_draw, "draw", lua_metatable::surface, lua_metatable::layers);
        lcb.add_constant("Alt32_GreyScale",   thdf_alt32_grey_scale);
        lcb.add_constant("Alt32_BlueRedSwap", thdf_alt32_blue_red_swap);
    }

    // Weak table at AnimMetatable[1] for light UD -> object lookup
    // For hitTest / setHitTestResult
    lua_newtable(pState->L);
    lua_createtable(pState->L, 0, 1);
    lua_pushliteral(pState->L, "v");
    lua_setfield(pState->L, -2, "__mode");
    lua_setmetatable(pState->L, -2);
    lua_rawseti(pState->L, pState->metatables[static_cast<size_t>(lua_metatable::anim)], 1);

    // Weak table at AnimMetatable[2] for light UD -> full UD lookup
    // For persisting Map
    lua_newtable(pState->L);
    lua_createtable(pState->L, 0, 1);
    lua_pushliteral(pState->L, "v");
    lua_setfield(pState->L, -2, "__mode");
    lua_setmetatable(pState->L, -2);
    lua_rawseti(pState->L, pState->metatables[static_cast<size_t>(lua_metatable::anim)], 2);

    // Anim
    {
        lua_class_binding<animation> lcb(pState, "animation", l_anim_new<animation>, lua_metatable::anim);
        lcb.add_metamethod(l_anim_persist<animation>, "persist");
        lcb.add_metamethod(l_anim_pre_depersist<animation>, "pre_depersist");
        lcb.add_metamethod(l_anim_depersist<animation>, "depersist");
        lcb.add_function(l_anim_set_anim, "setAnimation", lua_metatable::anims);
        lcb.add_function(l_anim_set_crop, "setCrop");
        lcb.add_function(l_anim_get_crop, "getCrop");
        lcb.add_function(l_anim_set_morph, "setMorph");
        lcb.add_function(l_anim_set_frame, "setFrame");
        lcb.add_function(l_anim_get_frame, "getFrame");
        lcb.add_function(l_anim_get_anim, "getAnimation");
        lcb.add_function(l_anim_set_tile<animation>, "setTile", lua_metatable::map);
        lcb.add_function(l_anim_get_tile, "getTile");
        lcb.add_function(l_anim_set_parent, "setParent");
        lcb.add_function(l_anim_set_flag<animation>, "setFlag");
        lcb.add_function(l_anim_set_flag_partial<animation>, "setPartialFlag");
        lcb.add_function(l_anim_get_flag<animation>, "getFlag");
        lcb.add_function(l_anim_make_visible<animation>, "makeVisible");
        lcb.add_function(l_anim_make_invisible<animation>, "makeInvisible");
        lcb.add_function(l_anim_set_tag, "setTag");
        lcb.add_function(l_anim_get_tag, "getTag");
        lcb.add_function(l_anim_set_position<animation>, "setPosition");
        lcb.add_function(l_anim_get_position, "getPosition");
        lcb.add_function(l_anim_set_speed<animation>, "setSpeed");
        lcb.add_function(l_anim_set_layer<animation>, "setLayer");
        lcb.add_function(l_anim_set_layers_from, "setLayersFrom");
        lcb.add_function(l_anim_set_hitresult, "setHitTestResult");
        lcb.add_function(l_anim_get_marker, "getMarker");
        lcb.add_function(l_anim_get_secondary_marker, "getSecondaryMarker");
        lcb.add_function(l_anim_tick<animation>, "tick");
        lcb.add_function(l_anim_draw<animation>, "draw", lua_metatable::surface);
        lcb.add_function(l_anim_set_drawable_layer, "setDrawingLayer");
    }

    // Duplicate AnimMetatable[1,2] to SpriteListMetatable[1,2]
    lua_rawgeti(pState->L, pState->metatables[static_cast<size_t>(lua_metatable::anim)], 1);
    lua_rawseti(pState->L, pState->metatables[static_cast<size_t>(lua_metatable::sprite_list)], 1);
    lua_rawgeti(pState->L, pState->metatables[static_cast<size_t>(lua_metatable::anim)], 2);
    lua_rawseti(pState->L, pState->metatables[static_cast<size_t>(lua_metatable::sprite_list)], 2);

    // SpriteList
    {
        lua_class_binding<sprite_render_list> lcb(pState, "spriteList", l_anim_new<sprite_render_list>, lua_metatable::sprite_list);
        lcb.add_metamethod(l_anim_persist<sprite_render_list>, "persist");
        lcb.add_metamethod(l_anim_pre_depersist<sprite_render_list>, "pre_depersist");
        lcb.add_metamethod(l_anim_depersist<sprite_render_list>, "depersist");
        lcb.add_function(l_srl_set_sheet, "setSheet", lua_metatable::sheet);
        lcb.add_function(l_srl_append, "append");
        lcb.add_function(l_srl_set_lifetime, "setLifetime");
        lcb.add_function(l_srl_is_dead, "isDead");
        lcb.add_function(l_anim_set_tile<sprite_render_list>, "setTile", lua_metatable::map);
        lcb.add_function(l_anim_set_flag<sprite_render_list>, "setFlag");
        lcb.add_function(l_anim_set_flag_partial<sprite_render_list>, "setPartialFlag");
        lcb.add_function(l_anim_get_flag<sprite_render_list>, "getFlag");
        lcb.add_function(l_anim_make_visible<sprite_render_list>, "makeVisible");
        lcb.add_function(l_anim_make_invisible<sprite_render_list>, "makeInvisible");
        lcb.add_function(l_anim_set_position<sprite_render_list>, "setPosition");
        lcb.add_function(l_anim_set_speed<sprite_render_list>, "setSpeed");
        lcb.add_function(l_anim_set_layer<sprite_render_list>, "setLayer");
        lcb.add_function(l_anim_tick<sprite_render_list>, "tick");
        lcb.add_function(l_anim_draw<sprite_render_list>, "draw", lua_metatable::surface);
    }
}