예제 #1
0
static void makeCubes(std::vector<cube> &cubes, MString &name, MStatus *stat)
{
    MFnMesh fnMesh;
    MObject result;

    MFloatPointArray points;
    MIntArray faceCounts;
    MIntArray faceConnects;

    int index_offset = 0;
    for (std::vector<cube>::iterator cit = cubes.begin(); cit != cubes.end(); ++cit)
    {
        point3 diag = cit->diagonal();
        float scale = diag.x;
        point3 pos = cit->start + (diag * .5f);

        MFloatVector mpos(pos.x, pos.y, pos.z);

        addCube(scale, mpos, index_offset * (8), points, faceCounts, faceConnects);
        index_offset += 1;
    }

    unsigned int vtx_cnt = points.length();
    unsigned int face_cnt = faceCounts.length();

    MObject newMesh =
        fnMesh.create(
            /* numVertices */ vtx_cnt,
            /* numFaces */ face_cnt,
            points,
            faceCounts,
            faceConnects,
            MObject::kNullObj,
            stat);

    /* Harden all edges. */
    int n_edges = fnMesh.numEdges(stat);
    for (int i = 0; i < n_edges; ++i)
    {
        fnMesh.setEdgeSmoothing(i, false);
    }
    fnMesh.cleanupEdgeSmoothing(); /* Must be called after editing edges. */

    fnMesh.updateSurface();

    /* Assign Shader. */
    MSelectionList sel_list;
    if (!MFAIL(sel_list.add("initialShadingGroup")))
    {
        MObject set_obj;
        sel_list.getDependNode(0, set_obj);
        MFnSet set(set_obj);
        set.addMember(newMesh);
    }

    /* Give it a swanky name. */
    MFnDagNode parent(fnMesh.parent(0));
    name = parent.setName("polyMengerSponge", false, stat);
}
void MapTile::draw() const
{
    //gl::color ( this->color );
    
    Rectf mpos(0.0,0.0,image.getWidth(),image.getHeight());
    


    mpos.offsetCenterTo(Vec2f(maporigin.x,maporigin.y));
    mpos.scale(1.0 + (zoom - 0.5));
    
   
    gl::draw(image,mpos );
    
    
    if(  hands.first.is_present())
    {
        Vec2f hpos ;
        hpos.x = hand_pos_f.x;
        hpos.y = hand_pos_f.y; // horizontal
        
        if(track_mode == MODE_PAN)
        {
            gl::color( ColorA( 0.6,0.7,0.8,0.6));

            gl::drawSolidCircle( hpos, 20.0, 32 );
        }
        else if(track_mode == MODE_CURSOR)
        {
            gl::color( ColorA( 0.6,0.0,0.0,0.6));

            gl::drawSolidCircle( hpos, 20.0, 32 );
        }
        else if (track_mode == MODE_ZOOM)
        {
            gl::color( ColorA( 0.6,0.7,0.8,0.6));
            Rectf rect(0, 0, 40, 40);
            rect.offsetCenterTo(hpos);
            gl::drawSolidRoundedRect(rect, 6);
        }
        
        
    }
    
    
    
    for( auto it=sliders.begin(); it!=sliders.end(); ++it )
        it->draw();

    
}
예제 #3
0
/// Updates one speciefic edge
void TradeGraph::UpdateEdge(MapPoint pos, const unsigned char dir, const TradeGraph* const tg)
{
    if(tg)
        if(tg->GetNode(pos).dont_run_over_player_territory[dir])
        {
            GetNode(pos).dont_run_over_player_territory[dir] = true;
            GetNode(pos).dirs[dir] = tg->GetNode(pos).dirs[dir];
            return;
        }
    MapPoint other = GetNodeAround(pos, dir + 1);
    unsigned char other_dir = (dir + 4) % 8;
    if(GetNode(other).dont_run_over_player_territory[other_dir])
    {
        GetNode(pos).dont_run_over_player_territory[dir] = true;
        GetNode(pos).dirs[dir] = GetNode(other).dirs[other_dir];
        return;
    }


    unsigned length;
    std::vector<unsigned char> route;
    MapPoint mpos(GetNode(pos).main_pos);
    // Simply try to find a path from one main point to another
    if(gwg->FindTradePath(mpos, GetNode(other).main_pos,
                          player, TG_PF_LENGTH, false, &route, &length) == 0xff)
        length = NO_EDGE;
    GetNode(pos).dirs[dir] = static_cast<MapCoord>(length);

    bool hasOwner = false;
    for(unsigned i = 0; i < route.size(); ++i)
    {
        mpos = gwg->GetNeighbour(mpos, route[i]);
        if(gwg->GetNode(mpos).owner != 0)
            hasOwner = true;
    }

    if(!hasOwner)
        GetNode(pos).dont_run_over_player_territory[dir] = true;

}
예제 #4
0
파일: graph_edit.cpp 프로젝트: Scrik/godot
void GraphEdit::_top_layer_input(const InputEvent& p_ev) {

	if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index==BUTTON_LEFT && p_ev.mouse_button.pressed) {

		Ref<Texture> port =get_icon("port","GraphNode");
		Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y);
		float grab_r=port->get_width()*0.5;
		for(int i=get_child_count()-1;i>=0;i--) {

			GraphNode *gn=get_child(i)->cast_to<GraphNode>();
			if (!gn)
				continue;

			for(int j=0;j<gn->get_connection_output_count();j++) {

				Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos();
				if (pos.distance_to(mpos)<grab_r) {

					connecting=true;
					connecting_from=gn->get_name();
					connecting_index=j;
					connecting_out=true;
					connecting_type=gn->get_connection_output_type(j);
					connecting_color=gn->get_connection_output_color(j);
					connecting_target=false;
					connecting_to=pos;
					return;
				}


			}

			for(int j=0;j<gn->get_connection_input_count();j++) {

				Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos();

				if (pos.distance_to(mpos)<grab_r) {

					if (right_disconnects) {
						//check disconnect
						for (List<Connection>::Element*E=connections.front();E;E=E->next()) {

							if (E->get().to==gn->get_name() && E->get().to_port==j) {

								Node*fr = get_node(String(E->get().from));
								if (fr && fr->cast_to<GraphNode>()) {

									connecting_from=E->get().from;
									connecting_index=E->get().from_port;
									connecting_out=true;
									connecting_type=fr->cast_to<GraphNode>()->get_connection_output_type(E->get().from_port);
									connecting_color=fr->cast_to<GraphNode>()->get_connection_output_color(E->get().from_port);
									connecting_target=false;
									connecting_to=pos;

									emit_signal("disconnection_request",E->get().from,E->get().from_port,E->get().to,E->get().to_port);
									fr = get_node(String(connecting_from)); //maybe it was erased
									if (fr && fr->cast_to<GraphNode>()) {
										connecting=true;
									}
									return;
								}

							}
						}
					}


					connecting=true;
					connecting_from=gn->get_name();
					connecting_index=j;
					connecting_out=false;
					connecting_type=gn->get_connection_input_type(j);
					connecting_color=gn->get_connection_input_color(j);
					connecting_target=false;
					connecting_to=pos;
					return;
				}


			}
		}
	}

	if (p_ev.type==InputEvent::MOUSE_MOTION && connecting) {

		connecting_to=Vector2(p_ev.mouse_motion.x,p_ev.mouse_motion.y);
		connecting_target=false;
		top_layer->update();

		Ref<Texture> port =get_icon("port","GraphNode");
		Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y);
		float grab_r=port->get_width()*0.5;
		for(int i=get_child_count()-1;i>=0;i--) {

			GraphNode *gn=get_child(i)->cast_to<GraphNode>();
			if (!gn)
				continue;

			if (!connecting_out) {
				for(int j=0;j<gn->get_connection_output_count();j++) {

					Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos();
					int type =gn->get_connection_output_type(j);
					if (type==connecting_type && pos.distance_to(mpos)<grab_r) {

						connecting_target=true;
						connecting_to=pos;
						connecting_target_to=gn->get_name();
						connecting_target_index=j;
						return;
					}


				}
			} else {

				for(int j=0;j<gn->get_connection_input_count();j++) {

					Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos();
					int type =gn->get_connection_input_type(j);
					if (type==connecting_type && pos.distance_to(mpos)<grab_r) {
						connecting_target=true;
						connecting_to=pos;
						connecting_target_to=gn->get_name();
						connecting_target_index=j;
						return;
					}
				}
			}
		}
	}

	if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index==BUTTON_LEFT && !p_ev.mouse_button.pressed) {

		if (connecting && connecting_target) {

			String from = connecting_from;
			int from_slot = connecting_index;
			String to =connecting_target_to;
			int to_slot = connecting_target_index;

			if (!connecting_out) {
				SWAP(from,to);
				SWAP(from_slot,to_slot);
			}
			emit_signal("connection_request",from,from_slot,to,to_slot);

		}
		connecting=false;
		top_layer->update();

	}



}
예제 #5
0
void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {

	Ref<InputEventMouseButton> mb = p_ev;
	if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {

		Ref<Texture> port = get_icon("port", "GraphNode");
		Vector2 mpos(mb->get_position().x, mb->get_position().y);
		for (int i = get_child_count() - 1; i >= 0; i--) {

			GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
			if (!gn)
				continue;

			for (int j = 0; j < gn->get_connection_output_count(); j++) {

				Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
				if (is_in_hot_zone(pos, mpos)) {

					if (valid_left_disconnect_types.has(gn->get_connection_output_type(j))) {
						//check disconnect
						for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {

							if (E->get().from == gn->get_name() && E->get().from_port == j) {

								Node *to = get_node(String(E->get().to));
								if (Object::cast_to<GraphNode>(to)) {

									connecting_from = E->get().to;
									connecting_index = E->get().to_port;
									connecting_out = false;
									connecting_type = Object::cast_to<GraphNode>(to)->get_connection_input_type(E->get().to_port);
									connecting_color = Object::cast_to<GraphNode>(to)->get_connection_input_color(E->get().to_port);
									connecting_target = false;
									connecting_to = pos;
									just_disconnected = true;

									emit_signal("disconnection_request", E->get().from, E->get().from_port, E->get().to, E->get().to_port);
									to = get_node(String(connecting_from)); //maybe it was erased
									if (Object::cast_to<GraphNode>(to)) {
										connecting = true;
									}
									return;
								}
							}
						}
					}

					connecting = true;
					connecting_from = gn->get_name();
					connecting_index = j;
					connecting_out = true;
					connecting_type = gn->get_connection_output_type(j);
					connecting_color = gn->get_connection_output_color(j);
					connecting_target = false;
					connecting_to = pos;
					just_disconnected = false;
					return;
				}
			}

			for (int j = 0; j < gn->get_connection_input_count(); j++) {

				Vector2 pos = gn->get_connection_input_position(j) + gn->get_position();
				if (is_in_hot_zone(pos, mpos)) {

					if (right_disconnects || valid_right_disconnect_types.has(gn->get_connection_input_type(j))) {
						//check disconnect
						for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {

							if (E->get().to == gn->get_name() && E->get().to_port == j) {

								Node *fr = get_node(String(E->get().from));
								if (Object::cast_to<GraphNode>(fr)) {

									connecting_from = E->get().from;
									connecting_index = E->get().from_port;
									connecting_out = true;
									connecting_type = Object::cast_to<GraphNode>(fr)->get_connection_output_type(E->get().from_port);
									connecting_color = Object::cast_to<GraphNode>(fr)->get_connection_output_color(E->get().from_port);
									connecting_target = false;
									connecting_to = pos;
									just_disconnected = true;

									emit_signal("disconnection_request", E->get().from, E->get().from_port, E->get().to, E->get().to_port);
									fr = get_node(String(connecting_from)); //maybe it was erased
									if (Object::cast_to<GraphNode>(fr)) {
										connecting = true;
									}
									return;
								}
							}
						}
					}

					connecting = true;
					connecting_from = gn->get_name();
					connecting_index = j;
					connecting_out = false;
					connecting_type = gn->get_connection_input_type(j);
					connecting_color = gn->get_connection_input_color(j);
					connecting_target = false;
					connecting_to = pos;
					just_disconnected = true;

					return;
				}
			}
		}
	}

	Ref<InputEventMouseMotion> mm = p_ev;
	if (mm.is_valid() && connecting) {

		connecting_to = mm->get_position();
		connecting_target = false;
		top_layer->update();

		Ref<Texture> port = get_icon("port", "GraphNode");
		Vector2 mpos = mm->get_position();
		for (int i = get_child_count() - 1; i >= 0; i--) {

			GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
			if (!gn)
				continue;

			if (!connecting_out) {
				for (int j = 0; j < gn->get_connection_output_count(); j++) {

					Vector2 pos = gn->get_connection_output_position(j) + gn->get_position();
					int type = gn->get_connection_output_type(j);
					if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && is_in_hot_zone(pos, mpos)) {

						connecting_target = true;
						connecting_to = pos;
						connecting_target_to = gn->get_name();
						connecting_target_index = j;
						return;
					}
				}
			} else {

				for (int j = 0; j < gn->get_connection_input_count(); j++) {

					Vector2 pos = gn->get_connection_input_position(j) + gn->get_position();
					int type = gn->get_connection_input_type(j);
					if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && is_in_hot_zone(pos, mpos)) {
						connecting_target = true;
						connecting_to = pos;
						connecting_target_to = gn->get_name();
						connecting_target_index = j;
						return;
					}
				}
			}
		}
	}

	if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && !mb->is_pressed()) {

		if (connecting && connecting_target) {

			String from = connecting_from;
			int from_slot = connecting_index;
			String to = connecting_target_to;
			int to_slot = connecting_target_index;

			if (!connecting_out) {
				SWAP(from, to);
				SWAP(from_slot, to_slot);
			}
			emit_signal("connection_request", from, from_slot, to, to_slot);

		} else if (!just_disconnected) {
			String from = connecting_from;
			int from_slot = connecting_index;
			Vector2 ofs = Vector2(mb->get_position().x, mb->get_position().y);
			emit_signal("connection_to_empty", from, from_slot, ofs);
		}
		connecting = false;
		top_layer->update();
		update();
		connections_layer->update();
	}
}
예제 #6
0
파일: os_bb10.cpp 프로젝트: baekdahl/godot
void OSBB10::handle_screen_event(bps_event_t *event) {

	screen_event_t screen_event = screen_event_get_event(event);

	int screen_val;
	screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);

	int pos[2];

	switch (screen_val) {
	case SCREEN_EVENT_MTOUCH_TOUCH:
	case SCREEN_EVENT_MTOUCH_RELEASE: {

		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_POSITION, pos);

		InputEvent ievent;
		ievent.type = InputEvent::SCREEN_TOUCH;
		ievent.ID = ++last_id;
		ievent.device = 0;
		ievent.screen_touch.pressed = (screen_val == SCREEN_EVENT_MTOUCH_TOUCH);
		ievent.screen_touch.x = pos[0];
		ievent.screen_touch.y = pos[1];
		Point2 mpos(ievent.screen_touch.x, ievent.screen_touch.y);

		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TOUCH_ID, &pos[0]);
		ievent.screen_touch.index = pos[0];

		last_touch_x[pos[0]] = ievent.screen_touch.x;
		last_touch_y[pos[0]] = ievent.screen_touch.y;

		input->parse_input_event( ievent );

		if (ievent.screen_touch.index == 0) {

			InputEvent ievent;
			ievent.type = InputEvent::MOUSE_BUTTON;
			ievent.ID = ++last_id;
			ievent.device = 0;
			ievent.mouse_button.pressed = (screen_val == SCREEN_EVENT_MTOUCH_TOUCH);
			ievent.mouse_button.button_index = BUTTON_LEFT;
			ievent.mouse_button.doubleclick = 0;
			ievent.mouse_button.x = ievent.mouse_button.global_x = mpos.x;
			ievent.mouse_button.y = ievent.mouse_button.global_y = mpos.y;
			input->parse_input_event( ievent );
		};


	} break;
	case SCREEN_EVENT_MTOUCH_MOVE: {

		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_POSITION, pos);

		InputEvent ievent;
		ievent.type = InputEvent::SCREEN_DRAG;
		ievent.ID = ++last_id;
		ievent.device = 0;
		ievent.screen_drag.x = pos[0];
		ievent.screen_drag.y = pos[1];

		/*
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION, pos);
		ievent.screen_drag.relative_x = ievent.screen_drag.x - pos[0];
		ievent.screen_drag.relative_y = ievent.screen_drag.y - pos[1];
		*/

		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TOUCH_ID, &pos[0]);
		ievent.screen_drag.index = pos[0];


		ievent.screen_drag.relative_x = ievent.screen_drag.x - last_touch_x[ievent.screen_drag.index];
		ievent.screen_drag.relative_y = ievent.screen_drag.y - last_touch_y[ievent.screen_drag.index];

		last_touch_x[ievent.screen_drag.index] = ievent.screen_drag.x;
		last_touch_y[ievent.screen_drag.index] = ievent.screen_drag.y;

		Point2 mpos(ievent.screen_drag.x, ievent.screen_drag.y);
		Point2 mrel(ievent.screen_drag.relative_x, ievent.screen_drag.relative_y);

		input->parse_input_event( ievent );

		if (ievent.screen_touch.index == 0) {

			InputEvent ievent;
			ievent.type = InputEvent::MOUSE_MOTION;
			ievent.ID = ++last_id;
			ievent.device = 0;
			ievent.mouse_motion.x = ievent.mouse_motion.global_x = mpos.x;
			ievent.mouse_motion.y = ievent.mouse_motion.global_y = mpos.y;
			input->set_mouse_pos(Point2(ievent.mouse_motion.x,ievent.mouse_motion.y));
			ievent.mouse_motion.speed_x=input->get_last_mouse_speed().x;
			ievent.mouse_motion.speed_y=input->get_last_mouse_speed().y;
			ievent.mouse_motion.relative_x = mrel.x;
			ievent.mouse_motion.relative_y = mrel.y;
			ievent.mouse_motion.button_mask = 1; // pressed

			input->parse_input_event( ievent );
		};
	} break;

	case SCREEN_EVENT_KEYBOARD: {

		InputEvent ievent;
		ievent.type = InputEvent::KEY;
		ievent.ID = ++last_id;
		ievent.device = 0;
		int val = 0;
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SCAN, &val);
		ievent.key.scancode = val;
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM, &val);
		ievent.key.unicode = val;
		if (val == 61448) {
			ievent.key.scancode = KEY_BACKSPACE;
			ievent.key.unicode = KEY_BACKSPACE;
		};
		if (val == 61453) {
			ievent.key.scancode = KEY_ENTER;
			ievent.key.unicode = KEY_ENTER;
		};

		int flags;
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_FLAGS, &flags);
		ievent.key.pressed = flags & 1; // bit 1 is pressed apparently

		int mod;
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_MODIFIERS, &mod);

		input->parse_input_event( ievent );
	} break;

	default:
		break;

	}
};
예제 #7
0
//------------------------------------------------------------------------------
//!
void
CameraManipulator::render( const RCP<Gfx::RenderNode>& /*rn*/ )
{
#if GFX
   if(  camera().isNull() )
   {
      return;
   }

   const Mat4f& m = camera()->cameraMatrix();

   // 3d pos for referential.
   Vec3f pos = camera()->position() -
      camera()->referential().orientation().getAxisZ();

   // Compute scaling factor.
   Vec3f csPos = camera()->viewingMatrix() * pos;
   float sf = ( -50 * csPos.z ) /
      ( viewport()->size().y *
        camera()->projectionMatrix()._11 );

   // Compute vertices position.
   Vec3f o = m | pos;
   Vec3f x = m | ( pos + Vec3f( sf,   0,   0 ) );
   Vec3f y = m | ( pos + Vec3f(   0, sf,   0 ) );
   Vec3f z = m | ( pos + Vec3f(   0,   0, sf ) );

   // Manip pos.
   Vec3f mpos(
      viewport()->position().x +
      viewport()->size().x - 40,
      viewport()->position().y + 40,
      0
   );
   Vec3f d = o - mpos;

   o -= d;
   x -= d;
   y -= d;
   z -= d;

   // Draw
   GfxState::set( TextureObject() );

   float c1 = 0.5f;
   float c2 = 0.2f;

   GL::lineWidth( 5 );
   GL::begin( GL::LINES );
   {
      GL::color3f( c1, c2, c2 );
      GL::vertex2fv( o.ptr() );
      GL::vertex2fv( x.ptr() );

      GL::color3f( c2, c1, c2 );
      GL::vertex2fv( o.ptr() );
      GL::vertex2fv( y.ptr() );

      GL::color3f( c2, c2, c1 );
      GL::vertex2fv( o.ptr() );
      GL::vertex2fv( z.ptr() );
   }
   GL::end();

   GL::lineWidth( 1 );
   GL::begin( GL::LINES );
   {
      GL::color3f( 1, 0, 0 );
      GL::vertex2fv( o.ptr() );
      GL::vertex2fv( x.ptr() );

      GL::color3f( 0, 1, 0 );
      GL::vertex2fv( o.ptr() );
      GL::vertex2fv( y.ptr() );

      GL::color3f( 0, 0, 1 );
      GL::vertex2fv( o.ptr() );
      GL::vertex2fv( z.ptr() );
   }
   GL::end();
#endif
}
예제 #8
0
/**
**  Mark the sight of unit. (Explore and make visible.)
**
**  @param player  player to mark the sight for (not unit owner)
**  @param pos     location to mark
**  @param w       width to mark, in square
**  @param h       height to mark, in square
**  @param range   Radius to mark.
**  @param marker  Function to mark or unmark sight
*/
void MapSight(const CPlayer &player, const Vec2i &pos, int w, int h, int range, MapMarkerFunc *marker)
{
	// Units under construction have no sight range.
	if (!range) {
		return;
	}
	// Up hemi-cyle
	const int miny = std::max(-range, 0 - pos.y);
	for (int offsety = miny; offsety != 0; ++offsety) {
		const int offsetx = isqrt(square(range + 1) - square(-offsety) - 1);
		const int minx = std::max(0, pos.x - offsetx);
		const int maxx = std::min(Map.Info.MapWidth, pos.x + w + offsetx);
		Vec2i mpos(minx, pos.y + offsety);
#ifdef MARKER_ON_INDEX
		const unsigned int index = mpos.y * Map.Info.MapWidth;
#endif

		for (mpos.x = minx; mpos.x < maxx; ++mpos.x) {
#ifdef MARKER_ON_INDEX
			marker(player, mpos.x + index);
#else
			marker(player, mpos);
#endif
		}
	}
	for (int offsety = 0; offsety < h; ++offsety) {
		const int minx = std::max(0, pos.x - range);
		const int maxx = std::min(Map.Info.MapWidth, pos.x + w + range);
		Vec2i mpos(minx, pos.y + offsety);
#ifdef MARKER_ON_INDEX
		const unsigned int index = mpos.y * Map.Info.MapWidth;
#endif

		for (mpos.x = minx; mpos.x < maxx; ++mpos.x) {
#ifdef MARKER_ON_INDEX
			marker(player, mpos.x + index);
#else
			marker(player, mpos);
#endif
		}
	}
	// bottom hemi-cycle
	const int maxy = std::min(range, Map.Info.MapHeight - pos.y - h);
	for (int offsety = 0; offsety < maxy; ++offsety) {
		const int offsetx = isqrt(square(range + 1) - square(offsety + 1) - 1);
		const int minx = std::max(0, pos.x - offsetx);
		const int maxx = std::min(Map.Info.MapWidth, pos.x + w + offsetx);
		Vec2i mpos(minx, pos.y + h + offsety);
#ifdef MARKER_ON_INDEX
		const unsigned int index = mpos.y * Map.Info.MapWidth;
#endif

		for (mpos.x = minx; mpos.x < maxx; ++mpos.x) {
#ifdef MARKER_ON_INDEX
			marker(player, mpos.x + index);
#else
			marker(player, mpos);
#endif
		}
	}
}
예제 #9
0
//Wyrmgus start
//void MapSight(const CPlayer &player, const Vec2i &pos, int w, int h, int range, MapMarkerFunc *marker)
void MapSight(const CPlayer &player, const Vec2i &pos, int w, int h, int range, MapMarkerFunc *marker, int z)
//Wyrmgus end
{
	// Units under construction have no sight range.
	if (!range) {
		return;
	}
	
	// Up hemi-cyle
	const int miny = std::max(-range, 0 - pos.y);
	
	for (int offsety = miny; offsety != 0; ++offsety) {
		const int offsetx = isqrt(square(range + 1) - square(-offsety) - 1);
		const int minx = std::max(0, pos.x - offsetx);
		//Wyrmgus start
//		const int maxx = std::min(Map.Info.MapWidth, pos.x + w + offsetx);
		const int maxx = std::min(Map.Info.MapWidths[z], pos.x + w + offsetx);
		//Wyrmgus end
		Vec2i mpos(minx, pos.y + offsety);
#ifdef MARKER_ON_INDEX
		//Wyrmgus start
//		const unsigned int index = mpos.y * Map.Info.MapWidth;
		const unsigned int index = mpos.y * Map.Info.MapWidths[z];
		//Wyrmgus end
#endif

		for (mpos.x = minx; mpos.x < maxx; ++mpos.x) {
			//Wyrmgus start
			if (Map.IsLayerUnderground(z) && CheckObstaclesBetweenTiles(pos, mpos, MapFieldAirUnpassable, z, 1) == false) {
				continue;
			}
			//Wyrmgus end
#ifdef MARKER_ON_INDEX
			//Wyrmgus start
//			marker(player, mpos.x + index);
			marker(player, mpos.x + index, z);
			//Wyrmgus end
#else
			//Wyrmgus start
//			marker(player, mpos);
			marker(player, mpos, z);
			//Wyrmgus end
#endif
		}
	}
	for (int offsety = 0; offsety < h; ++offsety) {
		const int minx = std::max(0, pos.x - range);
		//Wyrmgus start
//		const int maxx = std::min(Map.Info.MapWidth, pos.x + w + range);
		const int maxx = std::min(Map.Info.MapWidths[z], pos.x + w + range);
		//Wyrmgus end
		Vec2i mpos(minx, pos.y + offsety);
#ifdef MARKER_ON_INDEX
		//Wyrmgus start
//		const unsigned int index = mpos.y * Map.Info.MapWidth;
		const unsigned int index = mpos.y * Map.Info.MapWidths[z];
		//Wyrmgus end
#endif

		for (mpos.x = minx; mpos.x < maxx; ++mpos.x) {
			//Wyrmgus start
			if (Map.IsLayerUnderground(z) && CheckObstaclesBetweenTiles(pos, mpos, MapFieldAirUnpassable, z, 1) == false) {
				continue;
			}
			//Wyrmgus end
#ifdef MARKER_ON_INDEX
			//Wyrmgus start
//			marker(player, mpos.x + index);
			marker(player, mpos.x + index, z);
			//Wyrmgus end
#else
			//Wyrmgus start
//			marker(player, mpos);
			marker(player, mpos, z);
			//Wyrmgus end
#endif
		}
	}
	// bottom hemi-cycle
	//Wyrmgus start
//	const int maxy = std::min(range, Map.Info.MapHeight - pos.y - h);
	const int maxy = std::min(range, Map.Info.MapHeights[z] - pos.y - h);
	//Wyrmgus end
	for (int offsety = 0; offsety < maxy; ++offsety) {
		const int offsetx = isqrt(square(range + 1) - square(offsety + 1) - 1);
		const int minx = std::max(0, pos.x - offsetx);
		//Wyrmgus start
//		const int maxx = std::min(Map.Info.MapWidth, pos.x + w + offsetx);
		const int maxx = std::min(Map.Info.MapWidths[z], pos.x + w + offsetx);
		//Wyrmgus end
		Vec2i mpos(minx, pos.y + h + offsety);
#ifdef MARKER_ON_INDEX
		//Wyrmgus start
//		const unsigned int index = mpos.y * Map.Info.MapWidth;
		const unsigned int index = mpos.y * Map.Info.MapWidths[z];
		//Wyrmgus end
#endif

		for (mpos.x = minx; mpos.x < maxx; ++mpos.x) {
			//Wyrmgus start
			if (Map.IsLayerUnderground(z) && CheckObstaclesBetweenTiles(pos, mpos, MapFieldAirUnpassable, z, 1) == false) {
				continue;
			}
			//Wyrmgus end
#ifdef MARKER_ON_INDEX
			//Wyrmgus start
//			marker(player, mpos.x + index);
			marker(player, mpos.x + index, z);
			//Wyrmgus end
#else
			//Wyrmgus start
//			marker(player, mpos);
			marker(player, mpos, z);
			//Wyrmgus end
#endif
		}
	}
}
예제 #10
0
//gather previous and current frame transformations for substep interpolation
void dSolverNode::gatherPassiveTransforms(MPlugArray &rbConnections, std::vector<xforms_t> &xforms)
{
    xforms.resize(0);
    xforms_t xform;


    for(size_t i = 0; i < rbConnections.length(); ++i) {
        MObject node = rbConnections[i].node();
        MFnDagNode fnDagNode(node);
        if(fnDagNode.typeId() == rigidBodyNode::typeId) {
            rigidBodyNode *rbNode = static_cast<rigidBodyNode*>(fnDagNode.userNode()); 
            rigid_body_t::pointer rb = rbNode->rigid_body();

            if(fnDagNode.parentCount() == 0) {
                std::cout << "No transform found!" << std::endl;
                continue;
            }

            MFnTransform fnTransform(fnDagNode.parent(0));

            MPlug plgMass(node, rigidBodyNode::ia_mass);
            float mass = 0.f;
            plgMass.getValue(mass);
			bool active = (mass>0.f);
            if(!active) {
                MQuaternion mquat;
                fnTransform.getRotation(mquat);
                MVector mpos(fnTransform.getTranslation(MSpace::kTransform));
                rb->get_transform(xform.m_x0, xform.m_q0); 
                
                xform.m_x1 = vec3f(mpos.x, mpos.y, mpos.z);
                xform.m_q1 = quatf(mquat.w, mquat.x, mquat.y, mquat.z); 
                xforms.push_back(xform);
            }
        } else if(fnDagNode.typeId() == rigidBodyArrayNode::typeId) {
            rigidBodyArrayNode *rbNode = static_cast<rigidBodyArrayNode*>(fnDagNode.userNode()); 
            std::vector<rigid_body_t::pointer>& rbs = rbNode->rigid_bodies();
        
            if(fnDagNode.parentCount() == 0) {
                std::cout << "No transform found!" << std::endl;
                return;
            }

            MPlug plgMass(node, rigidBodyArrayNode::ia_mass);
            float mass = 0.f;
            plgMass.getValue(mass);
			bool active = (mass>0.f);
            if(!active) {
                MPlug plgPosition(node, rigidBodyArrayNode::io_position);
                MPlug plgRotation(node, rigidBodyArrayNode::io_rotation);

                MPlug plgElement;
                for(size_t j = 0; j < rbs.size(); ++j) {
                    rbs[j]->get_transform(xform.m_x0, xform.m_q0); 

                    plgElement = plgPosition.elementByLogicalIndex(j);
                    plgElement.child(0).getValue(xform.m_x1[0]);
                    plgElement.child(1).getValue(xform.m_x1[1]);
                    plgElement.child(2).getValue(xform.m_x1[2]);

                    vec3f rot;
                    plgElement = plgRotation.elementByLogicalIndex(j);
                    plgElement.child(0).getValue(rot[0]);
                    plgElement.child(1).getValue(rot[1]);
                    plgElement.child(2).getValue(rot[2]);

                    MEulerRotation meuler(deg2rad(rot[0]), deg2rad(rot[1]), deg2rad(rot[2]));
                    MQuaternion mquat = meuler.asQuaternion();
                    xform.m_q1 = quatf(mquat.w, mquat.x, mquat.y, mquat.z); 
                    xforms.push_back(xform);
                }
            }
        }
    }
}
예제 #11
0
void initRigidBody(MObject &node)
{
    MFnDagNode fnDagNode(node);

    rigidBodyNode *rbNode = static_cast<rigidBodyNode*>(fnDagNode.userNode()); 
    rigid_body_t::pointer rb = rbNode->rigid_body();

    if(fnDagNode.parentCount() == 0) {
        std::cout << "No transform found!" << std::endl;
        return;
    }

    MFnTransform fnTransform(fnDagNode.parent(0));

    MPlug plgMass(node, rigidBodyNode::ia_mass);
    float mass = 0.f;
    plgMass.getValue(mass);
    if(mass>0.f) {
        //active rigid body, set the world transform from the initial* attributes
        MObject obj;

        vec3f pos;
        MPlug plgInitialValue(node, rigidBodyNode::ia_initialPosition);
        plgInitialValue.child(0).getValue(pos[0]);
        plgInitialValue.child(1).getValue(pos[1]);
        plgInitialValue.child(2).getValue(pos[2]);

        vec3f rot;
        plgInitialValue.setAttribute(rigidBodyNode::ia_initialRotation);
        plgInitialValue.child(0).getValue(rot[0]);
        plgInitialValue.child(1).getValue(rot[1]);
        plgInitialValue.child(2).getValue(rot[2]);

        vec3f vel;
        plgInitialValue.setAttribute(rigidBodyNode::ia_initialVelocity);
        plgInitialValue.child(0).getValue(vel[0]);
        plgInitialValue.child(1).getValue(vel[1]);
        plgInitialValue.child(2).getValue(vel[2]);

        vec3f spin;
        plgInitialValue.setAttribute(rigidBodyNode::ia_initialSpin);
        plgInitialValue.child(0).getValue(spin[0]);
        plgInitialValue.child(1).getValue(spin[1]);
        plgInitialValue.child(2).getValue(spin[2]);

        MEulerRotation meuler(deg2rad(rot[0]), deg2rad(rot[1]), deg2rad(rot[2]));
        MQuaternion mquat = meuler.asQuaternion();
        rb->set_transform(pos, quatf(mquat.w, mquat.x, mquat.y, mquat.z)); 
        rb->set_linear_velocity(vel);
        rb->set_angular_velocity(spin);
        rb->set_kinematic(false);

        fnTransform.setRotation(meuler);
        fnTransform.setTranslation(MVector(pos[0], pos[1], pos[2]), MSpace::kTransform);
    } else {
        //passive rigid body, get the world trasform from from the shape node
        MQuaternion mquat;
        fnTransform.getRotation(mquat);
        MVector mpos(fnTransform.getTranslation(MSpace::kTransform));
        rb->set_transform(vec3f(mpos.x, mpos.y, mpos.z), quatf(mquat.w, mquat.x, mquat.y, mquat.z));
        rb->set_kinematic(true);
    }
}