JVector
JXMesaCamera::ScreenToModel
	(
	const JVector& pt
	)
{
	if (!PrepareMesa())
		{
		return pt;
		}

	PrepareTransforms();

	GLdouble modelMatrix[16], projMatrix[16];
	GLint viewport[4];

	glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
	glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
	glGetIntegerv(GL_VIEWPORT, viewport);

	JFloat x,y,z;
	gluUnProject(pt.GetElement(1), pt.GetElement(2), pt.GetElement(3),
				 modelMatrix, projMatrix, viewport, &x, &y, &z);

	return JVector(3, x, y, z);
}
Example #2
0
File: Peer.cpp Project: kaznog/t09
		OperationRequestParameters Peer::opCreateRoomImplementation(const JString& gameID, bool isVisible, bool isOpen, nByte maxPlayers, const Hashtable& customRoomProperties, const Hashtable& customLocalPlayerProperties, const JVector<JString>& propsListedInLobby)
		{
			OperationRequestParameters op;
			if(gameID.length())
				op.put(ParameterCode::ROOM_NAME, ValueObject<JString>(gameID));

			Hashtable roomProps(Utils::stripToCustomProperties(customRoomProperties));
			if(!isOpen)
				roomProps.put(Properties::Room::IS_OPEN, isOpen);
			if(!isVisible)
				roomProps.put(Properties::Room::IS_VISIBLE, isVisible);
			if(maxPlayers)
				roomProps.put(Properties::Room::MAX_PLAYERS, maxPlayers);
			JString* propsListedInLobbyArr = allocateArray<JString>(propsListedInLobby.getSize());
			for(unsigned int i=0; i<propsListedInLobby.getSize(); ++i)
				propsListedInLobbyArr[i] = propsListedInLobby[i];
			roomProps.put(Properties::Room::PROPS_LISTED_IN_LOBBY, propsListedInLobbyArr, propsListedInLobby.getSize());
			deallocateArray(propsListedInLobbyArr);
			op.put(ParameterCode::ROOM_PROPERTIES, ValueObject<Hashtable>(roomProps));

			Hashtable playerProperties = Utils::stripToCustomProperties(customLocalPlayerProperties);
			if(playerProperties.getSize())
				op.put(ParameterCode::PLAYER_PROPERTIES, ValueObject<Hashtable>(playerProperties));
			op.put(ParameterCode::BROADCAST, ValueObject<bool>(true));
			op.put(ParameterCode::CLEANUP_CACHE_ON_LEAVE, ValueObject<bool>(true));
			return op;
		}
void
JPlotFitQuad2::SetErrors
	(
	const JVector& p
	)
{
	itsAErrParameter	= p.GetElement(1);
	itsBErrParameter	= p.GetElement(2);
	itsCErrParameter	= p.GetElement(3);
}
void
JPlotFitQuad2::SetCurrentParameters
	(
	const JVector& p
	)
{
	itsAParameter	= p.GetElement(1);
	itsBParameter	= p.GetElement(2);
	itsCParameter	= p.GetElement(3);
}
void
JX3DWidget::ContinueDrag
	(
	const JPoint& pt
	)
{
	if (itsDragType == kRotateDrag)
		{
		const JVector delta(3, - pt.x + itsStartPt.x, pt.y - itsStartPt.y, 0.0);

		const JVector& o = itsCamera->GetAttentionPt();
		JVector v        = itsStartPos - o;
		const JFloat r   = v.GetLength();
		const JFloat lat = asin(v.GetElement(3) / r);
		const JFloat lon = atan2(v.GetElement(2), v.GetElement(1));

		// direction of drag relative to screen x-axis

		const JFloat alpha = atan2(delta.GetElement(2), delta.GetElement(1));

		// delta along the sphere in drag direction

		const JFloat phi = delta.GetLength() / (r * 50);
		JVector p(3, r*cos(phi), r*sin(phi), 0.0);

		// inverse: rotate around z-axis for partial alignment of x-axis

		JMatrix r1(3, 3);
		r1.SetElements(
			cos(lon), -sin(lon), 0.0,
			sin(lon),  cos(lon), 0.0,
				 0.0,       0.0, 1.0);

		// inverse: rotate around y-axis for complete alignment of x-axis towards viewer

		JMatrix r2(3, 3);
		r2.SetElements(
			cos(lat), 0.0, -sin(lat),
				 0.0, 1.0,       0.0,
			sin(lat), 0.0,  cos(lat));

		// inverse: rotate around x-axis to align y-axis with drag direction

		JMatrix r3(3, 3);
		r3.SetElements(
			1.0,        0.0,         0.0,
			0.0, cos(alpha), -sin(alpha),
			0.0, sin(alpha),  cos(alpha));

		// transform delta long the sphere to our coordinate system

		p = (r1 * r2 * r3 * p).GetColVector(1);

		itsCamera->SetPosition(p + o);
		}
}
		void MutableRoom::setPropsListedInLobby(const JVector<JString>& propsListedInLobby)
		{
			if(mPropsListedInLobby != propsListedInLobby)
			{
				mPropsListedInLobby = propsListedInLobby;
				JString* propsListedInLobbyArr = allocateArray<JString>(propsListedInLobby.getSize());
				for(unsigned int i=0; i<propsListedInLobby.getSize(); ++i)
					propsListedInLobbyArr[i] = propsListedInLobby[i];
				Hashtable properties;
				properties.put(static_cast<nByte>(Properties::Room::PROPS_LISTED_IN_LOBBY), propsListedInLobbyArr, propsListedInLobby.getSize());
				deallocateArray(propsListedInLobbyArr);
				mLoadBalancingPeer->opSetPropertiesOfRoom(properties);
			}
		}
void
JPlotFitExp::SetErrors
	(
	const JVector& p
	)
{
	itsAErr	= p.GetElement(1);
	itsBErr	= p.GetElement(2);
}
void
JPlotFitExp::SetCurrentParameters
	(
	const JVector& p
	)
{
	itsAParm	= p.GetElement(1);
	itsBParm	= p.GetElement(2);
}
JVector
TanhLinNetwork::g
	(
	const JIndex	layerIndex,
	const JVector&	h
	)
	const
{
	const JSize dimCount = h.GetDimensionCount();

	JVector result(dimCount);

	for (JIndex i=1;i<=dimCount;i++)
		{
		const JFloat value = h.GetElement(i);
		result.SetElement(i, g(layerIndex, value));
		}

	return result;
}
Example #10
0
void classifier_hyperrect_list::initiateEval()
{
	int i;
	JVector<int> discrete;
	JVector<int> real;

	for(i=0;i<numAtt;i++) {
		int att=whichAtt[i];
		if (ai.getTypeOfAttribute(att) == REAL) {
			real.addElement(i);
		} else {
			discrete.addElement(i);
		}
	}

	numReal=real.size();
	listRealPos = new int[numReal];
	listRealAtt = new int[numReal];
	for(i=0;i<numReal;i++) {
		listRealPos[i]=real[i];
		listRealAtt[i]=whichAtt[listRealPos[i]];
	}

	numDiscrete=discrete.size();
	listDiscretePos = new int[numDiscrete];
	listDiscreteAtt = new int[numDiscrete];
	for(i=0;i<numDiscrete;i++) {
		listDiscretePos[i]=discrete[i];
		listDiscreteAtt[i]=whichAtt[listDiscretePos[i]];
	}
}
Example #11
0
void JBotSimulator::updatePos()
{
    //Rotation berechnen
    if(speedMode)
    {
        currrot += 0.0141176*rotspeed;
    }
    else
    {
        currrot += 0.00141176*rotspeed;
    }

    while(currrot > 360) currrot -= 360;
    while(currrot < 0) currrot += 360;

    //Movement berechnen
    JVector movement = movvect;

    if(!speedMode)
    {
        movement /= 10;
    }

    int newmoveangle = currrot + movement.getAngle();
    newmoveangle = newmoveangle % 360;
    newmoveangle = 360 - newmoveangle;

    movement.setAngle(newmoveangle);

    JVector newpos = currpos;
    newpos += movement;

    bool ok = true;

    if(newpos.getX() < 0) ok = false;
    else if(newpos.getX() > size.getX()) ok = false;
    else if(newpos.getY() < 0) ok = false;
    else if(newpos.getY() > size.getY()) ok = false;


    if(ok) currpos += movement;

    emit positionChanged(currrot, currpos);
}
void LoadBalancingListener::onLobbyStatsUpdate(const JVector<LobbyStatsResponse>& res)
{
	mpView->info("===================== lobby stats update");
	for(unsigned int i=0; i<res.getSize(); ++i) 
		mpView->info(res[i].toString().UTF8Representation().cstr());

	// lobby stats request test
	JVector<LobbyStatsRequest> ls;
	ls.addElement(LobbyStatsRequest());
	ls.addElement(LobbyStatsRequest(L"AAA"));
	ls.addElement(LobbyStatsRequest(L"BBB"));
	ls.addElement(LobbyStatsRequest(L"CCC", LobbyType::DEFAULT));
	ls.addElement(LobbyStatsRequest(L"AAA", LobbyType::SQL_LOBBY));
	mpLbc->opLobbyStats(ls);
	//	mpLbc->opLobbyStats();
}
Example #13
0
void classifier_hyperrect_list::initializeChromosome()
{
	int i,j,base;

	instance *ins=NULL;
	if(tGlobals->smartInit) {
		if(tGlobals->defaultClassPolicy!=DISABLED) {
			ins=is->getInstanceInit(tGlobals->defaultClass);
		} else {
			ins=is->getInstanceInit(ai.getNumClasses());
		}
	}

	JVector<int> selectedAtts;
	ruleSize=0;
	for(i=0;i<tGlobals->numAttributesMC;i++) {
		if(!rnd>=tReal->probIrr) {
			selectedAtts.addElement(i);
			ruleSize+=tReal->attributeSize[i];
		}
	}

	numAtt=selectedAtts.size();
	whichAtt = new int[numAtt];
	offsetPredicates = new int[numAtt];
	predicates = new float[ruleSize];

	for(i=0,base=0;i<numAtt;i++) {
		offsetPredicates[i]=base;
		int att=selectedAtts[i];
		whichAtt[i]=att;

		if (ai.getTypeOfAttribute(att) == REAL) {
			float max,min;
			float sizeD=ai.getSizeDomain(att);
			float minD=ai.getMinDomain(att);
			float maxD=ai.getMaxDomain(att);
			float size=(!rnd * tReal->rangeIntervalSizeInit + tReal->minIntervalSizeInit)*sizeD;

			if(ins) {
				float val=ins->realValues[att];
				min=val-size/2.0;
				max=val+size/2.0;
				if(min<minD) {
					max+=(minD-min);
					min=minD;
				}
				if(max>maxD) {
					min-=(max-maxD);
					max=maxD;
				}
			} else {
				min=!rnd*(sizeD-size)+minD;
				max=min+size;
			}
	
			predicates[base]=min;
			predicates[base+1]=max;
		} else {
			int value;
			if(ins) value=(unsigned char)ins->realValues[att];
			else value=-1;
			for(j=0;j<tReal->attributeSize[att];j++) {
				if(j!=value) {
					if(!rnd<tGlobals->probOne) {
						predicates[base+j]=1;
					} else {
						predicates[base+j]=0;
					}
				} else {
					predicates[base+j]=1;
				}
			}
		}

		base+=tReal->attributeSize[att];
	}

	if(ins) {
		classValue=ins->getClass();
	} else {
		do {
			classValue=rnd(0,ai.getNumClasses()-1);
		} while(tGlobals->defaultClassPolicy!=DISABLED && classValue==tGlobals->defaultClass);
	}
}
JBoolean
JX3DWidget::HandleRotationKeyPress
	(
	const int				key,
	const JXKeyModifiers&	modifiers
	)
{
	if (modifiers.meta() && key == kJUpArrow)
		{
		return ZoomForWheel(kJXButton4, modifiers);
		}
	else if (modifiers.meta() && key == kJDownArrow)
		{
		return ZoomForWheel(kJXButton5, modifiers);
		}

	const JVector& o = itsCamera->GetAttentionPt();
	JVector v        = itsCamera->GetPosition() - o;
	const JFloat r   = v.GetLength();
	JFloat lat       = asin(v.GetElement(3) / r);
	JFloat lon       = atan2(v.GetElement(2), v.GetElement(1));

	const JFloat delta =
		(modifiers.shift()   ? kSmallDeltaAngle :
		(modifiers.control() ? kBigDeltaAngle   :
		kDeltaAngle));

	JBoolean moved = kJFalse;

	if (key == kJUpArrow)
		{
		lat  += delta;
		moved = kJTrue;
		}
	else if (key == kJDownArrow)
		{
		lat  -= delta;
		moved = kJTrue;
		}

	else if (key == kJLeftArrow)
		{
		lon  += delta;
		moved = kJTrue;
		}
	else if (key == kJRightArrow)
		{
		lon  -= delta;
		moved = kJTrue;
		}

	if (moved)
		{
		itsCamera->SetPosition(JVector(3,
			r * cos(lat) * cos(lon),
			r * cos(lat) * sin(lon),
			r * sin(lat)));

		Redraw();	// key repeats can delay Refresh()
		return kJTrue;
		}
	else
		{
		return kJFalse;
		}
}