예제 #1
0
bool SimpleProblemMaker::procExistDic()
{
    int num_ex, num_real;
    bool bOrigin =  false;
	///////////////////// 문제생성
	Problem prob;
    
    num_ex = std::rand() % tokenizer->word_cnt_exist_dic;
    num_real = tokenizer->atWordExistDBToken(num_ex);
    
    std::string solution = tokenizer->tokens[num_real].getToken();
    if (!dic->exsistWord(solution))
        bOrigin = true;
    
	tokenizer->tokens[num_real].setProbNum((char)1);
    
	problem_content = tokenizer->cascadeData();
    
	prob.pcontent = "빈칸에 알맞은 단어를 고르시오.";
	
	int sol = std::rand() % 4;
    std::string simstr[3];
    
    if (!dic->getRandomSimItems(solution, simstr, 3))
    {
        return false;
    }
    
    int simcnt = 0;
	for (int i=0; i<4; i++)
	{
        std::string tmp;
        
		if (sol == i)
		{
            tmp = solution;
            
            if (bOrigin)
            {
                tmp = tokenizer->tokens[num_real].getOrigin();
            }
            
			prob.addItems(solution, 1);
		} else {
            tmp = simstr[simcnt++];
			prob.addItems(tmp, 0);
		}
        
        std::string res = dic->getWordInfo(tmp).mean;
        if (res == "")
            res = getTranslate(res);
        
        prob.feedback += "(" + tmp + "): " + res + "\r";
	}
    
	problem.push_back(prob);
    
    return true;
}
예제 #2
0
void
SVGTransformable::dtranslate(double dtx, double dty)
{
	SVGTranslateTransform * translate = getTranslate(true);
	translate->tx += dtx;
	translate->ty += dty;
	translate->updateMatrix();
	SVGElement* meAsSVGElement = dynamic_cast<SVGElement*>(this);
	if(meAsSVGElement) meAsSVGElement->setDamaged(true);
}
예제 #3
0
void MobileEntity::placeAtEdge(const GameEntity& g)
{

		///@todo implement
	// collision detection for walls - so that the player can "land" on them and run into them
	// perhaps abstract it to the Mobileentity level because other mobile entities will need hit detection for walls as well


	CollisionBox b1=getHitBox();
	CollisionBox b2=g.getHitBox();

	//Tells whether or not the midpoint is at all within the mid point of the other box
	vec3 d1=b1.getTranslate()-getVel()-b1.getDimensions()/3-b2.getPoint1();
	vec3 d2=b1.getTranslate()-getVel()+b1.getDimensions()/3-b2.getPoint2();
	vec3 midDist=b1.getTranslate()-b2.getTranslate();

	bool midInX=(d1.x>0)!=(d2.x>0);
	bool midInY=(d1.y>0)!=(d2.y>0);
	bool midInZ=(d1.z>0)!=(d2.z>0);

	if(!midInX&&!midInY&&getVel().z==0||
		!midInX&&!midInZ&&getVel().y==0||
		!midInZ&&!midInY&&getVel().x==0
		)
		return;
	


	vec3 newPos;

	//within the "x prism"
	float dir=0;
	float EASE_VAL=.05;
	float EASE_SCALE_VAL=3.0;
	if(midInY&&midInZ||!midInX){
		if(midDist.x!=0)dir=midDist.x/abs(midDist.x);
		else dir=0;

		if(abs(d1.x)>b1.getDimensions().x/EASE_SCALE_VAL||abs(d2.x)>b1.getDimensions().x/EASE_SCALE_VAL)dir=0;

		if(abs(d1.x)<abs(d2.x)){
			if(getVel().x<0)
			{
				newPos.x=b2.getPoint1().x+b1.getDimensions().x/2;
			}
		}else{
			if(getVel().x>0)
			{
				newPos.x=b2.getPoint2().x-b1.getDimensions().x/2;
			}
		}
		if(newPos.x!=0){
			setTranslateX(newPos.x);
			setVelX(0);
		}
		translate(EASE_VAL*dir,0,0);
	}
	//within the "y prism"
	if(midInX&&midInZ||!midInY){
		if(midDist.y!=0)dir=midDist.y/abs(midDist.y);
		else dir=0;

		if(abs(d1.y)>b1.getDimensions().y/EASE_SCALE_VAL||abs(d2.y)>b1.getDimensions().y/EASE_SCALE_VAL)dir=0;

		if(abs(d1.y)<abs(d2.y)){
			if(getVel().y<0)
			{
				newPos.y=b2.getPoint1().y+b1.getDimensions().y/2;
				_jumpCount=1;
			}
		}else{
			if(getVel().y>0)
			{
				newPos.y=b2.getPoint2().y-b1.getDimensions().y/2;
			}
		}

		if(newPos.y!=0){
			setTranslateY(newPos.y);
			setVelY(0);
		}
		setVel(getVel()*.85);
		if(dot(getVel(),getVel())<.01){
			setVel(0,0,0);
		}
		translate(0,EASE_VAL*dir,0);
	}
	
	//within the "z prism"
	if(midInX&&midInY||!midInZ){
		if(midDist.y!=0)dir=midDist.y/abs(midDist.y);
		else dir=0;

		if(abs(d1.z)>b1.getDimensions().z/EASE_SCALE_VAL||abs(d2.z)>b1.getDimensions().z/EASE_SCALE_VAL)dir=0;

		if(abs(d1.z)<abs(d2.z)){
			if(getVel().z<0)
			{
				newPos.z=b2.getPoint1().z+b1.getDimensions().z/2;
			}
		}else{
			if(getVel().z>0)
			{
				newPos.z=b2.getPoint2().z-b1.getDimensions().z/2;
			}
		}
		
		if(newPos.z!=0){
			setTranslateZ(newPos.z);
			setVelZ(0);
		}
		translate(0,0,EASE_VAL*dir);
	}

	vec3 v=getTranslate()-newPos;
}
Action::ResultE
SkeletonOgreJoint::jointUpdateEnter(JointTraverser *jt)
{
    Action::ResultE  res  = Action::Continue;
    Skeleton        *skel = getSkeleton();

#ifdef OSG_DEBUG
    if(_sfJointId.getValue() == INVALID_JOINT_ID)
    {
        SWARNING << "SkeletonOgreJoint::jointUpdateEnter: "
                 << "Joint has invalid jointId. Ignoring." << std::endl;
        return res;
    }
    
    if(skel == NULL)
    {
        SWARNING << "SkeletonOgreJoint::jointUpdateEnter: "
                 << "Joint has no skeleton. Ignoring." << std::endl;
        return res;
    }
#endif

    Int16                          jointId     = getJointId();
    Skeleton::MFJointMatricesType *jointMats   =
        skel->editMFJointMatrices();
    SkeletonOgreJoint             *parentJoint =
        dynamic_cast<SkeletonOgreJoint *>(skel->getParentJoints(jointId));

    if(parentJoint != NULL)
    {
        _accumRotate = parentJoint->_accumRotate;
        _accumRotate.mult(getRotate      ());
        _accumRotate.mult(getOffsetRotate());

        _accumScale = parentJoint->_accumScale;
        _accumScale[0] *= getScale()[0] * getOffsetScale()[0];
        _accumScale[1] *= getScale()[1] * getOffsetScale()[1];
        _accumScale[2] *= getScale()[2] * getOffsetScale()[2];

        _accumTranslate = getTranslate() + getOffsetTranslate();
        _accumTranslate[0] *= parentJoint->_accumScale[0];
        _accumTranslate[1] *= parentJoint->_accumScale[1];
        _accumTranslate[2] *= parentJoint->_accumScale[2];

        parentJoint->_accumRotate.multVec(_accumTranslate, _accumTranslate);
        _accumTranslate += parentJoint->_accumTranslate;   
    }
    else
    {
        _accumRotate    = getRotate();
        _accumRotate.mult(getOffsetRotate());

        _accumScale     = getScale();
        _accumScale[0] *= getOffsetScale()[0];
        _accumScale[1] *= getOffsetScale()[1];
        _accumScale[2] *= getOffsetScale()[2];

        _accumTranslate = getTranslate() + getOffsetTranslate();
    }

    Quaternion jointRotate   (_accumRotate   );
    Vec3f      jointTranslate(_accumTranslate);
    Vec3f      jointScale    (_accumScale    );

    if(skel->getUseInvBindMatrix() == true)
    {
        jointRotate.mult(getInvBindRotate());
        jointScale[0]  *= getInvBindScale()[0];
        jointScale[1]  *= getInvBindScale()[1];
        jointScale[2]  *= getInvBindScale()[2];

        jointTranslate[0] = jointScale[0] * getInvBindTranslate()[0];
        jointTranslate[1] = jointScale[1] * getInvBindTranslate()[1];
        jointTranslate[2] = jointScale[2] * getInvBindTranslate()[2];

        jointRotate.multVec(jointTranslate, jointTranslate);

        jointTranslate += _accumTranslate;
    }

    Matrix matJoint;
    matJoint.setTransform(jointTranslate, jointRotate, jointScale);

    (*jointMats)[jointId] = matJoint;

    return res;
}
예제 #5
0
bool MMSLabelWidget::prepareText(int *width, int *height, bool recalc) {
    // check if we have to (re)load the font
    this->surface->lock();

    loadFont();

    if (!this->font) {
        this->surface->unlock();
        return false;
    }

    // font available, use it for this surface
    this->surface->setFont(this->font);

    this->surface->unlock();

    if (!this->translated) {
        // text changed and have to be translated
        if ((this->rootwindow)&&(this->rootwindow->windowmanager)&&(getTranslate())) {
            // translate text
            string source;
            getText(source);
            this->rootwindow->windowmanager->getTranslator()->translate(source, this->translated_text);
        }
        else {
            // text can not or should not translated
            getText(this->translated_text);
        }

        // reset swap flag
        this->swap_left_right = false;

        // language specific conversions
        MMSLanguage targetlang = this->rootwindow->windowmanager->getTranslator()->getTargetLang();
        if ((targetlang == MMSLANG_IL) || (targetlang == MMSLANG_AR)) {
            if (convBidiString(this->translated_text, this->translated_text), (targetlang == MMSLANG_AR) ? true : false) {
                // bidirectional conversion successful, swap alignment horizontal
                this->swap_left_right = true;
            }
        }

        // mark as translated
        this->translated = true;
    }

    // get width and height of the string to be drawn
    int realWidth, realHeight;
    this->font->getStringWidth(this->translated_text, -1, &realWidth);
    this->font->getHeight(&realHeight);

    if (!this->minmax_set) {
        if (width)  *width = realWidth;
        if (height) *height = realHeight;
    }
    else {
        if (recalc) {
            // calculate dynamic label size

            // get maximum width and height of the label
            int maxWidth = getMaxWidthPix();
            if (maxWidth <= 0) maxWidth = getInnerGeometry().w;
            int maxHeight = getMaxHeightPix();
            if (maxHeight <= 0) maxHeight = getInnerGeometry().h;

            // get minimum width and height of the label
            int minWidth = getMinWidthPix();
            int minHeight = getMinHeightPix();

            if (width)  {
                if (realWidth < minWidth)
                    *width = minWidth;
                else if (realWidth > maxWidth)
                    *width = maxWidth;
                else
                    *width = realWidth;

                if (*width <= 0) *width = 1;
            }

            if (height) {
                if (realHeight < minHeight)
                    *height = minHeight;
                else if (realHeight > maxHeight)
                    *height = maxHeight;
                else
                    *height = realHeight;

                if (*height <= 0) *height = 1;
            }
        }
        else {
            if (width)  *width = realWidth;
            if (height) *height = realHeight;
        }
    }

    return true;
}
vec3 CollisionBox::getPoint2() const
{
	//get the negative side point
	return getTranslate()-(_dimensions/2)*getScale() ;
}
vec3 CollisionBox::getPoint1() const
{
	//get the positive side point
	return getTranslate()+(_dimensions/2)*getScale() ;
}