Exemplo n.º 1
0
float AngleBetween(const vec2 &a, const vec2 &b)
{
    float dotProd = a.dotProduct(b);
    float cosine = dotProd / (a.length() * b.length());

    return RadToDeg(acos(cosine));
}
Exemplo n.º 2
0
 void
 draw_pt(const vec2 &pt, float size, const vec4 &color)
 {
   gl::Uniform(m_pts_pos_loc, vec3(pt.x(), pt.y(), size));
   gl::Uniform(m_pts_color_loc, color);
   glDrawArrays(GL_POINTS, 0, 1);
 }
Exemplo n.º 3
0
inline static qreal globalAngle( const vec2 &v )
{
  //assuming v is normalized
  qreal cosa = v.x();
  qreal sina = -v.y();
  return sina >= 0.0 ? acosf(cosa) : 2.0*PI - acosf(cosa);
}
Exemplo n.º 4
0
float angle (const vec2& arg1, const vec2& arg2)
{
			
			float skal = il_skal(arg1, arg2)/(arg1.length()*arg2.length());
			skal = abs(acos(skal))*sgn(arg1, arg2);
			return skal;
}
Exemplo n.º 5
0
inline vec2 operator*(const vec2& v, const mat2& m)
{
    vec2 t;
    t.x() = v.x()*m.e(0,0) + v.y()*m.e(0,1);
    t.y() = v.x()*m.e(1,0) + v.y()*m.e(1,1);
    return t;
}
Exemplo n.º 6
0
void Automan::OnTick() {
	Parent::OnTick();

	cure::ContextObject* car = manager_->GetObject(car_id_, true);
	if (!car) {
		manager_->PostKillObject(GetInstanceId());
		return;
	}
	if (!car->IsLoaded()) {
		return;
	}
	car->SetEnginePower(0, 1);
	const vec2 wanted_direction(direction_.x, direction_.y);
	const vec3 car_direction3d = car->GetOrientation()*vec3(0,1,0);
	const vec2 car_direction(car_direction3d.x, car_direction3d.y);
	const float angle = wanted_direction.GetAngle(car_direction);
	car->SetEnginePower(1, angle);

	if (car->GetVelocity().GetLengthSquared() < 1.0f) {
		still_timer_.TryStart();
		if (still_timer_.QueryTimeDiff() > 4.0f) {
			cure::Health::Set(car, 0);
		}
	} else {
		still_timer_.Stop();
	}
}
Exemplo n.º 7
0
void KDTree::build(const vec2& iLats, const vec2& iLons) {
    mLats = iLats;
    mLons = iLons;
    if(iLats.size() != iLons.size())
        Util::error("Cannot initialize KDTree, lats and lons not the same size");

    size_t nLat = iLats.size();
    if(nLat == 0)
        Util::error("Cannot initialize KDTree, no valid locations");

    size_t nLon = iLats[0].size();
    if(nLon == 0)
        Util::error("Cannot initialize KDTree, no valid locations");

    indexdVec lons(nLon*nLat);

    indexdVec::iterator currLon = lons.begin();
    size_t to = -1;
    for(size_t i = 0; i < iLats.size(); ++i) {
        for(size_t j = 0; j < iLats[0].size(); ++j) {
            if(Util::isValid(iLons[i][j]) && Util::isValid(iLats[i][j])) {
                *(currLon++) = Indexed(iLons[i][j], iLats[i][j], i, j);
                ++to;
            }
        }
    }

    if(to == -1) {
        Util::error("Cannot initialize KDTree, no valid locations");
    }
    if(to >= 0) subTree(lons, 0, to, true, NULL, mRoot);
}
Exemplo n.º 8
0
 bool operator<(const vec2& v) const
 {
   if (x() != v.x())
     return x() < v.x();
   else
     return y() < v.y();
 }
Exemplo n.º 9
0
void Launcher::GetBallisticData(const vec3& position1, const vec3& position2,
	float pitch, float& guide_pitch, float& guide_yaw, float &time) const {
	const vec3 delta = position1 - position2;
	const vec2 yaw_vector(delta.x, delta.y);
	guide_yaw = vec2(0, 1).GetAngle(yaw_vector);

	const float h = delta.z;
	const float v = game_->GetMuzzleVelocity();
	const float vup = v * ::cos(pitch);
	// g*t^2/2 - vup*t + h = 0
	//
	// Quaderatic formula:
	// ax^2 + bx + c = 0
	// =>
	//     -b +- sqrt(b^2 - 4ac)
	// x = ---------------------
	//             2a
	const float a = +9.82f/2;
	const float b = -vup;
	const float c = +h;
	const float b2 = b*b;
	const float _4ac = 4*a*c;
	if (b2 < _4ac) {	// Does not compute.
		guide_pitch = -PIF/4;
	} else {
		const float t = (-b + sqrt(b2 - _4ac)) / (2*a);
		//deb_assert(t > 0);
		time = t;
		const float vfwd = yaw_vector.GetLength() / t;
		guide_pitch = -::atan(vfwd/vup);
		if (guide_pitch < pitch) {	// Aiming downwards?
			guide_pitch += (guide_pitch-pitch);	// Tss! Homebrew... seems to be working somewhat! :)
		}
	}
}
Exemplo n.º 10
0
bool esvg::Polyline::parseXML(const exml::Element& _element, mat2& _parentTrans, vec2& _sizeMax) {
	// line must have a minimum size...
	m_paint.strokeWidth = 1;
	if (_element.exist() == false) {
		return false;
	}
	parseTransform(_element);
	parsePaintAttr(_element);
	
	// add the property of the parrent modifications ...
	m_transformMatrix *= _parentTrans;
	
	std::string sss1 = _element.attributes["points"];
	if (sss1.size() == 0) {
		ESVG_ERROR("(l "<<_element.getPos()<<") polyline: missing points attribute");
		return false;
	}
	_sizeMax.setValue(0,0);
	ESVG_VERBOSE("Parse polyline : \"" << sss1 << "\"");
	const char* sss = sss1.c_str();
	while ('\0' != sss[0]) {
		vec2 pos;
		int32_t n;
		if (sscanf(sss, "%f,%f %n", &pos.m_floats[0], &pos.m_floats[1], &n) == 2) {
			m_listPoint.push_back(pos);
			_sizeMax.setValue(std::max(_sizeMax.x(), pos.x()),
			                  std::max(_sizeMax.y(), pos.y()));
			sss += n;
		} else {
			break;
		}
	}
	return true;
}
Exemplo n.º 11
0
	CTrackBall() {
		radius = 106;
		saferadius = radius -1;
		reset();
        touch1.clear();
        touch2.clear();
        nFingers = 0;
	}
Exemplo n.º 12
0
 bool Rectangle::contains(const vec2 &pt){
     if(pt.x() > pts[0].x() &&pt.x() < pts[1].x()
             && pt.y() > pts[0].y() && pt.y()< pts[3].y()){
         return true;
     }
     return false;

 }
Exemplo n.º 13
0
void etk::Matrix2::scale(const vec2& _vect) {
	m_mat[0] *= _vect.x();
	m_mat[1] *= _vect.x();
	m_mat[2] *= _vect.x();
	m_mat[4] *= _vect.y();
	m_mat[3] *= _vect.y();
	m_mat[5] *= _vect.y();
}
Exemplo n.º 14
0
void SetCamera ( vec2 corner1, vec2 corner2, float rotation )
{
	matrix2x3 projection ( matrix2x3::Ortho(corner1.X(), corner2.X(), corner1.Y(), corner2.Y()) );
	if (fabs(rotation) > 0.00004f)
		projection *= matrix2x3::Rotation(rotation);
	Matrices::SetProjectionMatrix(projection);
	cameraCorner1 = corner1;
	cameraCorner2 = corner2;
}
Exemplo n.º 15
0
void cmdUIDrawTexturedQuad(struct Cmd* pCmd, UIManager* pUIManager, const vec2& position, const vec2& size, Texture* pTexture)
{
	UNREF_PARAM(pCmd);
	// the last variable can be used to create a border
	TexVertex pVertices[] = { MAKETEXQUAD(position.getX(), position.getY(), position.getX() + size.getX(), position.getY() + size.getY(), 0) };
	int nVertices = sizeof(pVertices) / sizeof(pVertices[0]);
	float4 color = { 1.0f, 1.0f, 1.0f, 1.0f };
	pUIManager->pUIRenderer->drawTextured(PRIMITIVE_TOPO_TRI_STRIP, pVertices, nVertices, pTexture, &color);
}
Exemplo n.º 16
0
vec2 matrix2x3::operator* ( const vec2& srcv2 ) const
{
	float ix, iy, ox, oy;
	ix = srcv2.X();
	iy = srcv2.Y();
	ox = (ix * _m11) + (iy * _m12) + _tX;
	oy = (ix * _m21) + (iy * _m22) + _tY;
	return vec2(ox, oy);
}
Exemplo n.º 17
0
 explicit unit_vec2(const vec2<T>& r) {
     T mag = r.magnitude();
     if(mag == T(0)) {
         x() = 0;
         y() = 0;
     } else {
         x() = r.x()/mag;
         y() = r.y()/mag;
     }
 }
Exemplo n.º 18
0
float TerrainRenderer::Patch::height(vec2 v) const
{
    v -= _param.offset.to<2>();
    v /= _param.size;

    std::swap(v.x(), v.y());

    v *= vec2(_gpuHeightData.size().x()-1, _gpuHeightData.size().y()-1);
    return _gpuHeightData.getLinear(v).z() * _param.zscale;
}
Exemplo n.º 19
0
	void draw(const vec2& where, char offsetz) const
	{
		vec2 end = get_end();
		glColor3f(1.,1.,1.);
		glLoadIdentity();
		glBegin(GL_LINES);
		glVertex3f(where.get_x(),where.get_y(), (offsetz)*OFFSET_SIZE);
		glVertex3f(end.get_x()+where.get_x(), end.get_y()+where.get_y(), (offset+offsetz)*OFFSET_SIZE);
		glEnd();
	}
Exemplo n.º 20
0
plane_angle signed_angle_between(const vec2<L>& lhs, const vec2<R>& rhs) {
    dimensionless sgn;
    // TODO: isn't there a better way to compute this?
    if(angle_difference(lhs.angle(), rhs.angle()) < plane_angle(0)) {
        sgn = -1;
    } else {
        sgn = 1;
    }
    return sgn*acos(unit_vec2(lhs).dot(unit_vec2(rhs)));
}
Exemplo n.º 21
0
void
JellyfishPrivate::update_viewport(const vec2& vp)
{
    if (viewport_.x() == vp.x() && viewport_.y() == vp.y())
    {
        return;
    }
    viewport_ = vp;
    projection_.loadIdentity();
    projection_.perspective(30.0, viewport_.x()/viewport_.y(), 20.0, 120.0);    
}
Exemplo n.º 22
0
void cmdUIDrawText(struct Cmd* pCmd, UIManager* pUIManager, const vec2& position, const char* pText, const TextDrawDesc* pTextDrawDesc /*= NULL*/)
{
	UNREF_PARAM(pCmd);
	const TextDrawDesc* drawDesc = pTextDrawDesc ? pTextDrawDesc : &pUIManager->mSettings.mDefaultTextDrawDesc;
	//Fontstash* pFont = pUIManager->pUIRenderer->getFontstash(drawDesc->mFontID);
	Fontstash* pFont = pUIManager->pUIRenderer->getFontstash(0);
	ASSERT(pFont);

	pFont->drawText(pText, position.getX(), position.getY(), drawDesc->mFontID, drawDesc->mFontColor, drawDesc->mFontSize, drawDesc->mFontSpacing, drawDesc->mFontBlur);
	
}
Exemplo n.º 23
0
    static double waixin(vec2& p1,vec2& p2,vec2& p3)                    //求外接圆半径
    {
		double a,b,c,s;
		a = p1.Distance(p2);
		b = p2.Distance(p3);
		c = p3.Distance(p1);
        
        s=(a+b+c)/2;
        s=sqrt(s*(s-a)*(s-b)*(s-c));
        double circler=a*b*c/(4*s);
        return circler;
    }
Exemplo n.º 24
0
bool TouchscreenButton::WillCapturePointer(const fplbase::InputPointer& pointer,
        vec2 window_size) {
    if (is_visible_ &&
            pointer.mousepos.x() / window_size.x() >= button_def_->top_left()->x() &&
            pointer.mousepos.y() / window_size.y() >= button_def_->top_left()->y() &&
            pointer.mousepos.x() / window_size.x() <=
            button_def_->bottom_right()->x() &&
            pointer.mousepos.y() / window_size.y() <=
            button_def_->bottom_right()->y()) {
        return true;
    }
    return false;
}
Exemplo n.º 25
0
void SetListener(vec2 pos, vec2 vel)
{
	ALfloat fpos[] = {pos.X(), pos.Y(), 0.0f};
	ALfloat fvel[] = {vel.X(), vel.Y(), 0.0f};
	alListenerfv(AL_POSITION, fpos);
	alListenerfv(AL_VELOCITY, fvel);
	if (vel.ModulusSquared() > 0.2f)
	{
		forientation[0] = fvel[0];
		forientation[1] = fvel[1];
	}
	alListenerfv(AL_ORIENTATION, forientation);
}
Exemplo n.º 26
0
void
ClipExample::
animate_ring(int i,
             float delta_t, 
             vec2 &velocity,
             float &inner_radius,
             float &outer_radius,
             vec2 &position,
             float &out_phase, float &out_freq, float &out_amplitude)
{
  float cycle, radius, phase;
  uint32_t modulas, total_time;
  uint32_t period_in_ms(1500);
  float freq( 2.0f*M_PI/ static_cast<float>(period_in_ms));

  phase= static_cast<float>(i) * M_PI/12.0f;
  /*
    we want it cyclic; first we take the modulas in integer
    arithmatic.
   */
  total_time=m_total_time.elapsed();
  modulas=total_time%period_in_ms;
  cycle=std::sin( freq*static_cast<float>(modulas) + phase);
  cycle = (cycle + 1.0)/2.0;


  radius = cycle*5.0*(i%10 + 1) + 5.0*(i%10 + 1);
  outer_radius=radius + 2.0*(i%20);
  inner_radius=radius - 2.0*(i%20);

  //set phase, freq and amplitide of wobble:
  int phase_offset(30*i);
  period_in_ms=1000;
  modulas=(total_time+phase_offset) % period_in_ms;
  cycle=static_cast<float>(modulas)/static_cast<float>(period_in_ms);

  out_phase=cycle*M_PI*2.0f;
  out_amplitude= radius/2.0f;
  out_freq=0.5f/outer_radius;

   
  bound_and_v(position.x(), 
              velocity.x(), 
              delta_t, 
              range_type<float>(0.0f, static_cast<float>(width()) ) );

  bound_and_v(position.y(), 
              velocity.y(), 
              delta_t, 
              range_type<float>(0.0f, static_cast<float>(height()) ) );
}
Exemplo n.º 27
0
void TouchscreenButton::Render(fplbase::Renderer& renderer) {
    static const float kButtonZDepth = 0.0f;

    if (!is_visible_) {
        return;
    }
    renderer.set_color(vec4(color_));

    auto mat = (button_.is_down() && down_material_ != nullptr)
               ? down_material_
               : up_current_ < up_materials_.size()
               ? up_materials_[up_current_]
               : nullptr;
    if (!mat) return;  // This is an invisible button.

    const vec2 window_size = vec2(renderer.window_size());
    const float texture_scale =
        window_size.y() * one_over_cannonical_window_height_;

    vec2 base_size = LoadVec2(
                         is_highlighted_ ? button_def_->draw_scale_highlighted()
                         : (button_.is_down() ? button_def_->draw_scale_pressed()
                            : button_def_->draw_scale_normal()));

    auto pulse = sinf(static_cast<float>(elapsed_time_) / 100.0f);
    if (is_highlighted_) {
        base_size += mathfu::kOnes2f * pulse * 0.05f;
    }

    vec3 texture_size =
        texture_scale * vec3(mat->textures()[0]->size().x() * base_size.x(),
                             -mat->textures()[0]->size().y() * base_size.y(), 0);

    vec3 position = vec3(button_def()->texture_position()->x() * window_size.x(),
                         button_def()->texture_position()->y() * window_size.y(),
                         kButtonZDepth);

    renderer.set_color(mathfu::kOnes4f);
    if (is_active_ || inactive_shader_ == nullptr) {
        shader_->Set(renderer);
    } else {
        inactive_shader_->Set(renderer);
    }
    mat->Set(renderer);
    fplbase::Mesh::RenderAAQuadAlongX(position - (texture_size / 2.0f),
                                      position + (texture_size / 2.0f), vec2(0, 1),
                                      vec2(1, 0));
#if defined(DEBUG_RENDER_BOUNDS)
    DebugRender(position, texture_size, renderer);
#endif  // DEBUG_RENDER_BOUNDS
}
Exemplo n.º 28
0
void Lieutenant::CheckEngaged()
{
	engaged = false;
	for (size_t i(0); i < marines.size(); ++i)
	{
		const Unit & marine(marines[i]);
		// Cache the unit's position and the range of its weapon
		const vec2	position(marine.GetPosition());
		const sint4 range(marine.GetWeaponRange());
		const sint4 rangeSq(range*range);
		//Quick Check
		if (marine.InCombat() && marine.IsAlive())
		{
			engaged = true;
			return;
		}
		for(size_t j(0); j<enemies.size(); ++j)
		{
			const Unit & enemy(enemies[j]);
			if(position.GetDistanceSqTo(enemy.GetPosition()) <= rangeSq)
			{
				engaged = true;
				return;
			}
		}
	}

	for (size_t i(0); i < tanks.size(); ++i)
	{
		const Unit & tank(tanks[i]);
		// Cache the unit's position and the range of its weapon
		const vec2	position(tank.GetPosition());
		const sint4 range(tank.GetWeaponRange());
		const sint4 rangeSq(range*range);
		//Quick Check
		if (tank.InCombat() && tank.IsAlive())
		{
			engaged = true;
			return;
		}
		for(size_t j(0); j<enemies.size(); ++j)
		{
			const Unit & enemy(enemies[j]);
			if(position.GetDistanceSqTo(enemy.GetPosition()) <= rangeSq)
			{
				engaged = true;
				return;
			}
		}
	}
}
Exemplo n.º 29
0
void PlaySoundPositional(const std::string& name, vec2 pos, vec2 vel, float gain)
{
	ALfloat fpos[] = {pos.X(), pos.Y(), 0.0f};
	ALfloat fvel[] = {vel.X(), vel.Y(), 0.0f};
	ALuint buf    = GetSound(name);
	ALuint source = GetFreeSource();
	alSourcei(source, AL_BUFFER, buf);
	alSourcei(source, AL_SOURCE_RELATIVE, AL_FALSE);
	alSourcefv(source, AL_POSITION, fpos);
	alSourcefv(source, AL_VELOCITY, fvel);
	alSourcef(source, AL_REFERENCE_DISTANCE, 50.0);
	alSourcef(source, AL_GAIN, gain);
	alSourcePlay(source);
}
Exemplo n.º 30
0
void TouchscreenButton::DebugRender(const vec3& position,
                                    const vec3& texture_size,
                                    fplbase::Renderer& renderer) const {
#if defined(DEBUG_RENDER_BOUNDS)
    if (debug_shader_ && draw_bounds_) {
        const vec2 window_size = vec2(renderer.window_size());
        static const float kButtonZDepth = 0.0f;
        static const fplbase::Attribute kFormat[] = {fplbase::kPosition3f,
                                                     fplbase::kEND
                                                    };
        static const unsigned short kIndices[] = {0, 1, 1, 3, 2, 3, 2, 0};
        const vec3 bottom_left = position - (texture_size / 2.0f);
        const vec3 top_right = position + (texture_size / 2.0f);

        // vertex format is [x, y, z]
        float vertices[] = {
            bottom_left.x(), bottom_left.y(), bottom_left.z(), top_right.x(),
            bottom_left.y(), bottom_left.z(), bottom_left.x(), top_right.y(),
            top_right.z(),   top_right.x(),   top_right.y(),   top_right.z(),
        };
        renderer.set_color(vec4(1.0f, 0.0f, 1.0f, 1.0f));
        debug_shader_->Set(renderer);
        fplbase::Mesh::RenderArray(fplbase::Mesh::kLines, 8,
                                   kFormat, sizeof(float) * 3,
                                   reinterpret_cast<const char*>(vertices),
                                   kIndices);

        renderer.set_color(vec4(1.0f, 1.0f, 0.0f, 1.0f));
        debug_shader_->Set(renderer);
        static unsigned short indicesButtonDef[] = {1, 0, 1, 2, 2, 3, 3, 0};
        float verticesButtonDef[] = {
            button_def()->top_left()->x() * window_size.x(),
            button_def()->top_left()->y() * window_size.y(),
            kButtonZDepth,
            button_def()->top_left()->x() * window_size.x(),
            button_def()->bottom_right()->y() * window_size.y(),
            kButtonZDepth,
            button_def()->bottom_right()->x() * window_size.x(),
            button_def()->bottom_right()->y() * window_size.y(),
            kButtonZDepth,
            button_def()->bottom_right()->x() * window_size.x(),
            button_def()->top_left()->y() * window_size.y(),
            kButtonZDepth,
        };
        fplbase::Mesh::RenderArray(fplbase::Mesh::kLines, 8, kFormat,
                                   sizeof(float) * 3,
                                   reinterpret_cast<const char*>(verticesButtonDef),
                                   indicesButtonDef);
    }
#else
    (void)position;
    (void)texture_size;
    (void)renderer;
#endif  // DEBUG_RENDER_BOUNDS
}