本文整理汇总了C++中Vector2类的典型用法代码示例。如果您正苦于以下问题:C++ Vector2类的具体用法?C++ Vector2怎么用?C++ Vector2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vector2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Subtract
Vector2 Subtract( Vector2 c_lhs, Vector2 const& i_rhs )
{
c_lhs.Subtract( i_rhs );
return c_lhs;
}
示例2: GetLocalScale
/**
* Gets the absolute scale of the object in local space
* @param result Storage for the position
*/
void Transform::GetLocalScale (Vector2& result)
{
result.setX(localTransform.mat[0][0]);
result.setY(localTransform.mat[1][1]);
}
示例3: GetScale
/**
* Gets the absolute scale of the object in world space
* @param result Storage for the position
*/
void Transform::GetScale (Vector2& result)
{
result.setX(finalTransform.mat[0][0]);
result.setY(finalTransform.mat[1][1]);
}
示例4:
Real DistRay2Ray2<Real>::GetSquared ()
{
Vector2<Real> diff = mRay0->Origin - mRay1->Origin;
Real a01 = -mRay0->Direction.Dot(mRay1->Direction);
Real b0 = diff.Dot(mRay0->Direction);
Real c = diff.SquaredLength();
Real det = Math<Real>::FAbs((Real)1 - a01*a01);
Real b1, s0, s1, sqrDist;
if (det >= Math<Real>::ZERO_TOLERANCE)
{
// Rays are not parallel.
b1 = -diff.Dot(mRay1->Direction);
s0 = a01*b1 - b0;
s1 = a01*b0 - b1;
if (s0 >= (Real)0)
{
if (s1 >= (Real)0) // region 0 (interior)
{
// Minimum at two interior points of rays.
Real invDet = ((Real)1)/det;
s0 *= invDet;
s1 *= invDet;
sqrDist = (Real)0;
}
else // region 3 (side)
{
s1 = (Real)0;
if (b0 >= (Real)0)
{
s0 = (Real)0;
sqrDist = c;
}
else
{
s0 = -b0;
sqrDist = b0*s0 + c;
}
}
}
else
{
if (s1 >= (Real)0) // region 1 (side)
{
s0 = (Real)0;
if (b1 >= (Real)0)
{
s1 = (Real)0;
sqrDist = c;
}
else
{
s1 = -b1;
sqrDist = b1*s1 + c;
}
}
else // region 2 (corner)
{
if (b0 < (Real)0)
{
s0 = -b0;
s1 = (Real)0;
sqrDist = b0*s0 + c;
}
else
{
s0 = (Real)0;
if (b1 >= (Real)0)
{
s1 = (Real)0;
sqrDist = c;
}
else
{
s1 = -b1;
sqrDist = b1*s1 + c;
}
}
}
}
}
else
{
// Rays are parallel.
if (a01 > (Real)0.0)
{
// Opposite direction vectors.
s1 = (Real)0;
if (b0 >= (Real)0)
{
s0 = (Real)0;
sqrDist = c;
}
else
{
s0 = -b0;
sqrDist = b0*s0 + c;
}
}
//.........这里部分代码省略.........
示例5: Circle
void Flower::drawPedals(PNG* canvas, const Vector2& center, int x, int y) const
{
Shape *pedal;
pedal = new Circle (center, PEDAL_COLOR, PEDAL_RADIUS);
pedal->set_center(Vector2(center.x()+x, center.y()+y));
pedal->draw(canvas);
pedal->set_center(Vector2(center.x()+x, center.y()-y));
pedal->draw(canvas);
pedal->set_center(Vector2(center.x()-x, center.y()+y));
pedal->draw(canvas);
pedal->set_center(Vector2(center.x()-x, center.y()-y));
pedal->draw(canvas);
pedal->set_center(Vector2(center.x()+y, center.y()+x));
pedal->draw(canvas);
pedal->set_center(Vector2(center.x()+y, center.y()-x));
pedal->draw(canvas);
pedal->set_center(Vector2(center.x()-y, center.y()+x));
pedal->draw(canvas);
pedal->set_center(Vector2(center.x()-y, center.y()-x));
pedal->draw(canvas);
delete pedal;
}
示例6: AddString
void JSONValue::AddVector2(const Vector2& value)
{
AddString(value.ToString());
}
示例7: switch
bool Path2DEditor::forward_input_event(const InputEvent& p_event) {
if (!node)
return false;
if (!node->is_visible())
return false;
if (!node->get_curve().is_valid())
return false;
switch(p_event.type) {
case InputEvent::MOUSE_BUTTON: {
const InputEventMouseButton &mb=p_event.mouse_button;
Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
Vector2 gpoint = Point2(mb.x,mb.y);
Vector2 cpoint = !mb.mod.alt? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint))
: node->get_global_transform().affine_inverse().xform( canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) );
//first check if a point is to be added (segment split)
real_t grab_treshold=EDITOR_DEF("poly_editor/point_grab_radius",8);
// Test move point!!
if ( mb.pressed && action==ACTION_NONE ) {
Ref<Curve2D> curve = node->get_curve();
for(int i=0;i<curve->get_point_count();i++) {
bool pointunder=false;
{
Point2 p = xform.xform( curve->get_point_pos(i) );
if (gpoint.distance_to(p) < grab_treshold ) {
if (mb.button_index==BUTTON_LEFT && !mb.mod.shift && mode==MODE_EDIT) {
action=ACTION_MOVING_POINT;
action_point=i;
moving_from=curve->get_point_pos(i);
moving_screen_from=gpoint;
return true;
} else if ((mb.button_index==BUTTON_RIGHT && mode==MODE_EDIT) || (mb.button_index==BUTTON_LEFT && mode==MODE_DELETE)) {
undo_redo->create_action(TTR("Remove Point from Curve"));
undo_redo->add_do_method(curve.ptr(),"remove_point",i);
undo_redo->add_undo_method(curve.ptr(),"add_point",curve->get_point_pos(i),curve->get_point_in(i),curve->get_point_out(i),i);
undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update");
undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update");
undo_redo->commit_action();
return true;
} else
pointunder=true;
}
}
if (mb.button_index==BUTTON_LEFT && i<(curve->get_point_count()-1)) {
Point2 p = xform.xform( curve->get_point_pos(i)+curve->get_point_out(i) );
if (gpoint.distance_to(p) < grab_treshold && (mode == MODE_EDIT || mode==MODE_EDIT_CURVE) ) {
action=ACTION_MOVING_OUT;
action_point=i;
moving_from=curve->get_point_out(i);
moving_screen_from=gpoint;
return true;
}
}
if (mb.button_index==BUTTON_LEFT && i>0) {
Point2 p = xform.xform( curve->get_point_pos(i)+curve->get_point_in(i) );
if (gpoint.distance_to(p) < grab_treshold && (mode == MODE_EDIT || mode==MODE_EDIT_CURVE)) {
action=ACTION_MOVING_IN;
action_point=i;
moving_from=curve->get_point_in(i);
moving_screen_from=gpoint;
return true;
}
}
if (pointunder)
return true;
}
}
// Test add point in empty space!
if ( mb.pressed && mb.button_index==BUTTON_LEFT && ((mb.mod.command && mode == MODE_EDIT) || mode == MODE_CREATE)) {
Ref<Curve2D> curve = node->get_curve();
//.........这里部分代码省略.........
示例8: return
bool NavigationPolygonEditor::forward_input_event(const InputEvent& p_event) {
if (!node)
return false;
if (node->get_navigation_polygon().is_null()) {
if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) {
create_nav->set_text("No NavigationPolygon resource on this node.\nCreate and assign one?");
create_nav->popup_centered_minsize();
}
return (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1);;
}
switch(p_event.type) {
case InputEvent::MOUSE_BUTTON: {
const InputEventMouseButton &mb=p_event.mouse_button;
Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
Vector2 gpoint = Point2(mb.x,mb.y);
Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
cpoint=canvas_item_editor->snap_point(cpoint);
cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
//first check if a point is to be added (segment split)
real_t grab_treshold=EDITOR_DEF("poly_editor/point_grab_radius",8);
switch(mode) {
case MODE_CREATE: {
if (mb.button_index==BUTTON_LEFT && mb.pressed) {
if (!wip_active) {
wip.clear();
wip.push_back( cpoint );
wip_active=true;
edited_point_pos=cpoint;
edited_outline=-1;
canvas_item_editor->get_viewport_control()->update();
edited_point=1;
return true;
} else {
if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint)<grab_treshold) {
//wip closed
_wip_close();
return true;
} else {
wip.push_back( cpoint );
edited_point=wip.size();
canvas_item_editor->get_viewport_control()->update();
return true;
//add wip point
}
}
} else if (mb.button_index==BUTTON_RIGHT && mb.pressed && wip_active) {
_wip_close();
}
} break;
case MODE_EDIT: {
if (mb.button_index==BUTTON_LEFT) {
if (mb.pressed) {
if (mb.mod.control) {
//search edges
int closest_outline=-1;
int closest_idx=-1;
Vector2 closest_pos;
real_t closest_dist=1e10;
for(int j=0;j<node->get_navigation_polygon()->get_outline_count();j++) {
DVector<Vector2> points=node->get_navigation_polygon()->get_outline(j);
int pc=points.size();
DVector<Vector2>::Read poly=points.read();
//.........这里部分代码省略.........
示例9: Normalize
Vector2 Normalize( Vector2 c_vector )
{
c_vector.Normalize();
return c_vector;
}
示例10: abs
float Obstacle::circleIntersection(const Vector2& dir, const Vector2& start, float radius) const {
const float radSqd = radius * radius;
const float SPEED = abs(dir);
Vector2 forward(dir / SPEED);
// Find the end points relative to the start position
Vector2 a = getP0() - start;
Vector2 b = getP1() - start;
// rotate the segment so that the direction is aligned with the x-axis
// TODO: Where is this exploited???
float x = a.x() * forward.x() + a.y() * forward.y();
float y = a.y() * forward.x() - a.x() * forward.y();
a.set(x, y);
x = b.x() * forward.x() + b.y() * forward.y();
y = b.y() * forward.x() - b.x() * forward.y();
b.set(x, y);
// compute the implicit equation of the obstacle line
Vector2 disp = b - a;
float dist = abs(disp);
Vector2 D = disp / dist;
Vector2 N(D.y(), -D.x());
float C = -(N * a); // Ax + By + C = 0 --> implicit equation
// Test for collision
if (C < 0.f) {
// the agent lies on the "wrong" side of the obstacle and can't see it.
return INFTY;
} else if (C < radius) { // the circle overlaps the line on the visible side
float t = D * (-a); // projection of origin on the line
if (t >= -radius && t <= dist + radius) {
// The projection of the circle center lies within the projection of
// the minkowski sum on the line (i.e. extends past the points by
// a distance equal to the radius).
if ((t >= 0 && t <= dist) || (t < 0 && absSq(a) < radSqd) ||
(t > dist && absSq(b) < radSqd)) {
return 0.f;
}
}
}
// Not currently colliding -- now compute potential collision in the future
// M points to the side of the line on which the origin (aka agent) lies
// This creates the leading edge of the minkowski sum (defined by (a2, b2)).
Vector2 M(C < 0.f ? -N : N);
Vector2 a2(a + M * radius);
Vector2 b2(b + M * radius);
// I use this to do quick and dirty floating-point SIGN tests
// This may not be particularly portable
union {
float f;
unsigned int u;
} w1, w2;
w1.f = a2.y();
w2.f = b2.y();
if ((w1.u ^ w2.u) & 0x80000000) {
// signs of the y-values are different; the segment crosses the line
float t = -a2.y() / D.y();
float x = a2.x() + D.x() * t;
if (x > 0) {
// The time it takes to travel distance x
return x / SPEED;
}
} else {
// both end points are on the same side of the line
// Note: Both of these are possible if the obstacle is near parallel
// to the forward direction
float minT = INFTY;
float aDist2 = a.y() * a.y();
if (aDist2 < radSqd) {
// collision with a
// dx < radius
float dx = sqrtf(radSqd - aDist2);
float x = a.x() - dx; // collision point candidate
// This is a bit tricky - I don't have to consider a.x() + dx
// 1) the direction is in the positive x-axis direction, so I know
// the earliest collision must have a lesser x-value.
// 2) It's POSSIBLE for x to have a negative value, but if that's
// true, then a.x() + dx must ALSO be negative, otherwise
// the point is inside the circle and it would be detected
// as a collision. So, it's enough to just test one value
if (x > 0.f) {
float t = x / (dist * D.x());
if (t < minT) {
minT = t;
}
}
}
float bDist2 = b.y() * b.y();
if (bDist2 < radSqd) {
// collision with a
// dx < radius
float dx = sqrtf(radSqd - bDist2);
float x = b.x() - dx; // collision point candidate
if (x > 0.f) {
float t = x / dir.x();
if (t < minT) {
minT = t;
}
}
}
//.........这里部分代码省略.........
示例11: DotProduct
double DotProduct( Vector2 const& i_lhs, Vector2 const& i_rhs )
{
return i_lhs.DotProduct( i_rhs );
}
示例12: Magnitude
double Magnitude( Vector2 const& i_vector )
{
return i_vector.Magnitude();
}
示例13: Scale
Vector2 Scale( Vector2 c_lhs, double const& i_rhs )
{
c_lhs.Scale( i_rhs );
return c_lhs;
}
示例14: Normalized
Vector2 Normalized() const {
Vector2 v = *this;
v.Normalize();
return v;
}
示例15: GameControllerMovement
bool SpecialMonsterController::GameControllerMovement(Vector2 &obj)
{
obj.x(obj.x() - (rand() % 3));
return true;
}