void LLHUDEffectBeam::unpackData(LLMessageSystem *mesgsys, S32 blocknum)
{
	llerrs << "Got beam!" << llendl;
	BOOL use_target_object;
	LLVector3d new_target;
	U8 packed_data[41];

	LLHUDEffect::unpackData(mesgsys, blocknum);
	LLUUID source_id;
	LLUUID target_id;
	S32 size = mesgsys->getSizeFast(_PREHASH_Effect, blocknum, _PREHASH_TypeData);
	if (size != 41)
	{
		llwarns << "Beam effect with bad size " << size << llendl;
		return;
	}
	mesgsys->getBinaryDataFast(_PREHASH_Effect, _PREHASH_TypeData, packed_data, 41, blocknum);
	
	htonmemcpy(source_id.mData, packed_data, MVT_LLUUID, 16);

	LLViewerObject *objp = gObjectList.findObject(source_id);
	if (objp)
	{
		setSourceObject(objp);
	}

	use_target_object = packed_data[16];

	if (use_target_object)
	{
		htonmemcpy(target_id.mData, &packed_data[17], MVT_LLUUID, 16);

		LLViewerObject *objp = gObjectList.findObject(target_id);
		if (objp)
		{
			setTargetObject(objp);
		}
	}
	else
	{
		htonmemcpy(new_target.mdV, &(packed_data[17]), MVT_LLVector3d, 24);
		setTargetPos(new_target);
	}

	// We've received an update for the effect, update the various timeouts
	// and fade animations.
	mKillTime = mTimer.getElapsedTimeF32() + mDuration;
	F32 fade_length;
	fade_length = llmin(0.5f, mDuration);
	mFadeInterp.setStartTime(mKillTime - fade_length);
	mFadeInterp.setEndTime(mKillTime);
	mFadeInterp.setStartVal(1.f);
	mFadeInterp.setEndVal(0.f);
}
Beispiel #2
0
static PyObject *
dmcc_setTargetPos(PyObject *self, PyObject *args)
{
    unsigned int nBoard;
    unsigned int nMotor;
    unsigned int nPosition;
    // Make sure szErrorMsg is not on the stack
    // -- downside is that we could have concurrency issues with different
    // threads, but you know what, there should only be one error message
    // at a time.  If you have it from multiple threads, your code is fubar'ed 
    // anyways!
    static char szErrorMsg[80];

    // DMCC.setTargetPos takes 3 arguments: board number, motor number, Position
    if (!PyArg_ParseTuple(args, "III:setMotor", &nBoard, &nMotor, &nPosition)) {
        return NULL;
    }
    // validate the board number
    if (nBoard > 3) {
        sprintf(szErrorMsg, "Board number %d is invalid.  Board number must be between 0 and 3.",
                nBoard);
        PyErr_SetString(PyExc_IndexError,szErrorMsg);
        return NULL;
    }
    // validate the motor number
    if ((nMotor < 1) || (nMotor > 2)) {
        sprintf(szErrorMsg, "Motor number %d is invalid.  Motor number must be 1 or 2.",
                nMotor);
        PyErr_SetString(PyExc_IndexError,szErrorMsg);
        return NULL;
    }

    int session;
    session = DMCCstart(nBoard);
    setTargetPos(session, nMotor, nPosition);
    DMCCend(session);

    return Py_BuildValue("i", 0);
}
Beispiel #3
0
AttackObject* HeroBow::createAttackObject()
{
    std::string strAttID=getArmature()->getAnimation()->getCurrentMovementID();
    auto actionMode=getActionFileMode();
    //获取方向
    bool facing=getFacing();
    float attackDist=getHeroModel()->AttackDist;      //攻击距离

    //创建子弹
    auto bullet=BulletObject::create();
    bullet->setAttackType(1);
    bullet->setAttackObject(this);
    
    if (strAttID==actionMode->ActionAttackName1 || strAttID==actionMode->ActionAttackName2 || strAttID==actionMode->ActionAttackName3 || strAttID==actionMode->ActionAttackName4)
    {
        bullet->setRepelPower(8.0);
        float bulletX=GameBLL::instance()->getMaxMapWidth();
        if(!facing){
            bulletX*=-1;
        }
        auto b=Sprite::createWithSpriteFrameName("v_arrow_1.png");
        b->setFlippedX(!facing);
        bullet->setSprite(b);
        bullet->setPosition(getPosition()+vShootPos);
        bullet->setTargetPos(getPosition()+Vec2(bulletX,vShootPos.y), 3000);
        bullet->setAttack(getHeroModel()->Attack);
        BulletBLL::getInstance()->addBullet(bullet);
    }
    //技能1
    if (strAttID==actionMode->SkillName1) {
        bullet->setPenetrateAttack(true);
        bullet->setRepelPower(32);
        attackDist=skills[0].AttackDist;
        
        float width=1280.0;
        float rota=21.24;   //旋转角度
        if(!facing){
            attackDist*=-1;
            rota*=-1;
            width*=-1;
        }
        auto bulletStartPos=getPosition() + Vec2(0, 255);
        auto b=Sprite::createWithSpriteFrameName("v_arrow_2.png");
        b->setFlippedX(!facing);
        bullet->setSprite(b);
        bullet->setPosition(bulletStartPos);
        //bullet->setTargetPos(pos+Vec2(attackDist,0), 2000);
        bullet->setIsDone(true);
        bullet->setRotation(rota);
        int attack=skills[0].CurrAttack + getHeroModel()->Attack / 4;
        bullet->setAttack(attack);
        BulletBLL::getInstance()->addBullet(bullet);
        
        auto call=CallFunc::create(CC_CALLBACK_0(HeroBow::bulletCallback, this, bullet));
        ccBezierConfig bc;
        bc.endPosition=Vec2(bulletStartPos.x + width, bulletStartPos.y);
        
        if(!facing){
            bc.controlPoint_1 = Vec2(bulletStartPos.x - width * 0.2, bulletStartPos.y - 300);
            bc.controlPoint_2 = Vec2(bc.endPosition.x + width * 0.2, bulletStartPos.y - 300);
        }else{
            bc.controlPoint_1 = Vec2(bulletStartPos.x + width * 0.2, bulletStartPos.y - 300);
            bc.controlPoint_2 = Vec2(bc.endPosition.x - width * 0.2, bulletStartPos.y - 300);
        }
        //子弹动作
        auto bez=BezierTo::create(0.5, bc);
        auto seq=Sequence::create(bez,call, NULL);
        bullet->runAction(APRotateWithAction::create(seq));
        
    }else if (strAttID==actionMode->SkillName2){
        float bAngle=345;
        if(!facing){
            bAngle=215;
        }
        auto bulletPos=getPosition() + Vec2(0, 272);
        int attack=skills[1].CurrAttack + getHeroModel()->Attack / 4;
        for (int i=0; i<3; i++) {
            auto targetPos=APTools::getRoundPoint(bulletPos, bAngle - (i * 10), 1700);
            float rotation=APTools::getAngle(bulletPos, targetPos);
            auto b=Sprite::createWithSpriteFrameName("v_arrow_3.png");
            b->setFlippedX(!facing);
            
            //创建子弹
            auto newbullet=BulletObject::create();
            newbullet->setRepelPower(8.0);
            newbullet->setAttackType(1);
            newbullet->setPenetrateAttack(true);
            newbullet->setAttackObject(this);
            newbullet->setSprite(b);
            newbullet->setPosition(bulletPos);
            newbullet->setTargetPos(targetPos, 2000);
            newbullet->setRotation(rotation);
            newbullet->setAttack(attack);
            BulletBLL::getInstance()->addBullet(newbullet);

        }
    }else if (strAttID==actionMode->SkillName3){
        attackDist=skills[2].AttackDist;
        //创建攻击对象
        int attack=skills[2].CurrAttack + getHeroModel()->Attack / 4;
        auto att=AttackObject::create();
        att->setAttack(attack);
        att->setRepelPower(280);
        att->setAttackObject(this);
        //是否被击倒
        att->setIsHitDown(true);
        //攻击范围
        Vec2 pos=this->getPosition();
        float attStartPosX=getPositionX();
        if (!facing) {
            attStartPosX-=attackDist;
        }
        
        Rect attRect=Rect(attStartPosX,getPositionY(),attackDist, 100);
        att->setAttRange(attRect);
        return att;
        
    }else if (strAttID==actionMode->SkillName4){
        attackDist=skills[3].AttackDist;
        //创建攻击对象
        int attack=skills[3].CurrAttack + getHeroModel()->Attack / 4;
        auto att=AttackObject::create();
        att->setAttack(attack);
        att->setRepelPower(120);
        att->setAttackObject(this);
        //是否被击倒
        att->setIsHitDown(false);
        //攻击范围
        Vec2 pos=this->getPosition();
        auto worldPos=this->getParent()->convertToWorldSpace(pos);
        float attDist=1280-worldPos.x;
        float attStartPosX=pos.x;
        if (!facing) {
            attDist=worldPos.x;
            attStartPosX-=attDist;
        }
        
        Rect attRect=Rect(attStartPosX,getPositionY(),attDist, 100);
        att->setAttRange(attRect);
        
        return att;
    }
    
    return nullptr;
}
Beispiel #4
0
/**
*@brief 更新
* @param st 刻み幅
*/
void RobotArm::update(double st)
{
	
	if(pauseFalg || stopFalg || !serbo)
		return;
	//std::cout << targetPoint.end_time << "\t" << targetPoint.time << std::endl;
	if(targetPoint.end_time < targetPoint.time)
	{
		if(targetPoint.type == Point)
		{
			Vector3d pos = calcKinematics(theta);

			double dPx = Kp*(targetPoint.target_pos(0)-pos(0));
			double dPy = Kp*(targetPoint.target_pos(1)-pos(1));
			double dPz = Kp*(targetPoint.target_pos(2)-pos(2));

			Vector3d dthe = calcJointVel(Vector3d(dPx, dPy, dPz));

			updatePos(dthe(0), dthe(1), dthe(2), 0);
			theta[3] = targetPoint.target_theta;
			
			
		}
		else
		{
			for(int i=0;i < 4;i++)
			{
				theta[i] = targetPoint.target_joint_pos[i];
			}
			if (!judgeSoftLimitJoint(theta))stop();
		}

		
		setTargetPos();

		

		return;
	}
	else
	{
		if(targetPoint.type == Point)
		{
			double td = calcVel(targetPoint.target_theta, targetPoint.start_theta, targetPoint.end_time, targetPoint.time, theta[3]);

			dt = st;
			MinTime = dt;

			double dx = targetPoint.target_pos(0)-targetPoint.start_pos(0);
			double dy = targetPoint.target_pos(1)-targetPoint.start_pos(1);
			double dz = targetPoint.target_pos(2)-targetPoint.start_pos(2);

			double ST = sqrt(dx*dx+dy*dy+dz*dz);
			if(ST < 0.001)
			{
				updatePos(0, 0, 0, td);
				targetPoint.time += dt;
				return;
			}

			double A = 2*M_PI*ST/(targetPoint.end_time*targetPoint.end_time);

			double s = A*targetPoint.end_time/(2*M_PI)*(targetPoint.time - targetPoint.end_time/(2*M_PI)*sin(2*M_PI/targetPoint.end_time*targetPoint.time));

			double Px = s*dx/ST + targetPoint.start_pos(0);
			double Py = s*dy/ST + targetPoint.start_pos(1);
			double Pz = s*dz/ST + targetPoint.start_pos(2);


			double ds = A*targetPoint.end_time/(2*M_PI)*(1 - cos(2*M_PI/targetPoint.end_time*targetPoint.time));

			Vector3d pos = calcKinematics(theta);

			double dPx = ds*dx/ST + Kp*(Px-pos(0));
			double dPy = ds*dy/ST + Kp*(Py-pos(1));
			double dPz = ds*dz/ST + Kp*(Pz-pos(2));

		
			//ofs << ds << "\t" << s << std::endl;
			//std::cout << pos << std::endl;

			

			Vector3d dthe = calcJointVel(Vector3d(dPx, dPy, dPz));


			
			

			updatePos(dthe(0), dthe(1), dthe(2), td);
		}
		else
		{
			double dthe[4];
			
			for(int i=0;i < 4;i++)
			{
				
				dthe[i] = calcVel(targetPoint.target_joint_pos[i], targetPoint.start_joint_pos[i], targetPoint.end_time, targetPoint.time, theta[i]);


				
			}

			updatePos(dthe[0], dthe[1], dthe[2], dthe[3]);

			
			
		}
		targetPoint.time += dt;
	}
	
}