Beispiel #1
0
//--Implementations
void render()
{
    int counter;
    //clear the screen
    glClearColor(1.0, 1.0, 1.0, 1.0); 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //enable the shader program
    glUseProgram(program);

    glUniform1f(loc_lightType, lightTypeVal);
    glUniform1f(loc_lightType2, lightTypeVal2);


    for(counter = 0; counter < globalObjCount; counter++)
    {
        //matrix MVP for planet    
        mvp = projection * view * objectsDataList.getModelMatrix(counter);

        // load each objects mvp
        renderObject( mvp, counter );
    }

    score();                      
  
    //Render Text
    string playerOneStr = "Player One Score:" + numToStr(scoreOne);
    string elapsedTime = "Elapsed Time:" + numToStr(elapsedDT());

    glColor3d(0.0, 0.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    //glPushMatrix();
    glLoadIdentity();
    gluOrtho2D(0, w, 0, h);
    glScalef(1, -1, 1);
    glTranslatef(0, -h, 0);
    //glMatrixMode(GL_MODELVIEW);
    //glLoadIdentity();
    renderBitmapString(30,40,(void *)GLUT_BITMAP_HELVETICA_18,playerOneStr);
    glColor3d(0.0, 0.0, 0.0);
    renderBitmapString(30,60,(void *)GLUT_BITMAP_HELVETICA_18,elapsedTime);
    glPushMatrix();
    //glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
       

    //clean up
    glDisableVertexAttribArray(loc_position);
    glDisableVertexAttribArray(loc_uv);
    glDisableVertexAttribArray(loc_normal);

    //enable depth testing
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    //swap the buffers
    glutSwapBuffers();
}
Beispiel #2
0
/*
函数名:		void searchFriend( GtkWidget *widget,GtkWidget *entry );
参数:		widget : 用户查找的控件 ,  entry : 用户查找的IP 文本输入框
函数描述:    查找好友的回调函数
返回值:          空
*/
void searchFriend( GtkWidget *widget,GtkWidget *search)
{
	gchar *userip;
	//gtk_editable_delete_text(GTK_EDITABLE(entry),0,3);
    int result;
    gchar buf[128];
    //g_print("search OK,entry is:%x\n",entry);
	userip = gtk_entry_get_text (GTK_ENTRY (entry));
    g_print("user ip is:%s\n",userip);
    struct sockaddr_in addr;
    bzero(&addr,sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_port = htons(LINPOP_DEFAULT_PORT);
    result = inet_aton(userip,&addr.sin_addr);
    if(!result){
        g_print("Not find\n");
    }else{
        //result = appendBroadcastList(userip);
	g_print("result is:%d\n",result);
	g_print("result is:%d\n",result);
        LinpopSend(&addr,LINPOP_BR_EXIT,LinpopGetNickWithAbsence());
        LinpopSend(&addr,LINPOP_BR_ENTRY,LinpopGetNickWithAbsence());
        //LinpopSendBroadcast(LINPOP_BR_EXIT,"NEU_MSG");
        //LinpopSendBroadcast(LINPOP_BR_ENTRY,"NEU_MSG");
    }
	numToStr(buf,getUserNumber());
	strcat(buf," friends online");
	gtk_entry_set_text (GTK_ENTRY (entry), buf);
}
Beispiel #3
0
	JSONParser( const std::string& jsonStr ) : std::map< std::string, std::string >() {
		m_jsonStr = jsonStr;
		pos = 1;
		skipSpaces();

		long keyCount = 0;
		std::string key;
		while ( pos < m_jsonStr.length() ) {
			if ( ( m_jsonStr[ 0 ] == '[' ) || keyCount ) {
				key = numToStr( keyCount++ );
			}
			else {
				key = findKey();
			}
			if ( pos >= m_jsonStr.length() ) {
				return;
			}
			std::string value = findValue( keyCount != 0 );
			insert( std::pair< std::string, std::string >( key, value ) );
			if ( keyCount && ( m_jsonStr[ pos ] == ',' || m_jsonStr[ pos ] == ']' ) ) {
				++pos;
				skipSpaces();
			}
			else {
				moveToEndChar();
            }
		}
	}
Beispiel #4
0
// temperature conversion
// tempchar = the string containing the temperature value
// unit = the unit for temperature
// return value = the converted temperature with degree sign and unit; if fails, return N/A
void GetTemp(TCHAR *tempchar, TCHAR *unit, TCHAR* str) 
{
	// unit can be C, F
	double temp;
	TCHAR tstr[20];

	TrimString(tempchar);
	if (tempchar[0] == '-' && tempchar[1] == ' ')
		memmove(&tempchar[1], &tempchar[2], sizeof(TCHAR)*(_tcslen(&tempchar[2])+1));

	// quit if the value obtained is N/A or not a number
	if ( !_tcscmp(tempchar, NODATA) || !_tcscmp(tempchar, _T("N/A"))) {
		_tcscpy(str, tempchar);
		return;
	}
	if ( !is_number(tempchar)) {
		_tcscpy(str, NODATA);
		return;
	}

	// convert the string to an integer
	temp = _ttof(tempchar);

	// convert all to F first
	if ( !_tcsicmp(unit, _T("C")))		temp = (temp*9/5)+32;
	else if ( !_tcsicmp(unit, _T("K")))	temp = ((temp-273.15)*9/5)+32;

	// convert to apporiate unit
	switch (opt.tUnit) {
	case 1:
		// rounding
		numToStr((temp-32)/9*5, tstr, SIZEOF(tstr));
		if (opt.DoNotAppendUnit)
			mir_sntprintf(str, MAX_DATA_LEN, _T("%s"), tstr);
		else
			mir_sntprintf(str, MAX_DATA_LEN, _T("%s%sC"), tstr, opt.DegreeSign);
		break;

	case 2:
		numToStr(temp, tstr, SIZEOF(tstr));
		if (opt.DoNotAppendUnit)
			mir_sntprintf(str, MAX_DATA_LEN, _T("%s"), tstr);
		else
			mir_sntprintf(str, MAX_DATA_LEN, _T("%s%sF"), tstr, opt.DegreeSign);
		break;
	}
}
Beispiel #5
0
// speed conversion
// tempchar = the string containing the speed value
// unit = the unit for speed
// return value = the converted speed with unit; if fail, return _T(""
void GetSpeed(TCHAR *tempchar, TCHAR *unit, TCHAR *str) 
{
	// unit can be km/h, mph, m/s, knots
	double tempunit;
	TCHAR tstr[20];

	str[0] = 0;

	// convert the string into an integer (always positive)
	// if the result is 0, then the string is not a number, return _T(""
	tempunit = _ttof(tempchar);
	if (tempunit == 0 && tempchar[0] != '0')
		return;

	// convert all to m/s first
	if ( !_tcsicmp(unit, _T("KM/H")))
		tempunit /= 3.6;
//	else if ( !_tcsicmp(unit, _T("M/S"))
//		tempunit = tempunit;
	else if ( !_tcsicmp(unit, _T("MPH")))
		tempunit *= 0.44704;
	else if ( !_tcsicmp(unit, _T("KNOTS")))
		tempunit *= 0.514444;

	// convert to apporiate unit
	switch (opt.wUnit) {
	case 1:
		numToStr(tempunit * 3.6, tstr, SIZEOF(tstr));
		mir_sntprintf(str, MAX_DATA_LEN, _T("%s %s"), tstr, opt.DoNotAppendUnit ? _T("") : TranslateT("km/h"));
		break;
	case 2:
		numToStr(tempunit, tstr, SIZEOF(tstr));
		mir_sntprintf(str, MAX_DATA_LEN, _T("%s %s"), tstr, opt.DoNotAppendUnit ? _T("") : TranslateT("m/s"));
		break;
	case 3:
		numToStr(tempunit / 0.44704, tstr, SIZEOF(tstr));
		mir_sntprintf(str, MAX_DATA_LEN, _T("%s %s"), tstr, opt.DoNotAppendUnit ? _T("") : TranslateT("mph"));
		break;
	case 4:
		numToStr(tempunit / 0.514444, tstr, SIZEOF(tstr));
		mir_sntprintf(str, MAX_DATA_LEN, _T("%s %s"), tstr, opt.DoNotAppendUnit ? _T("") : TranslateT("knots"));
		break;
	}
}
Beispiel #6
0
/**
 * @brief	供调试使用,打印msg各成员。
 * @param	msg 解码信息结构体指针
 * @return	None
 */
void GPS_ShowPosition(NMEA_msg *msg)
{
	char buf[32];

	GPS_DEBUG("\r\nLocation: ");
	ftoa(buf, msg->longitude, 6);
	GPS_DEBUG(buf);

	GPS_DEBUG(",");

	ftoa(buf, msg->latitude, 6);
	GPS_DEBUG(buf);

	GPS_DEBUG("\r\nUTC:");
	GPS_DEBUG(numToStr(buf, msg->utc));

	GPS_DEBUG("\r\nStatus:");
	GPS_DEBUG(numToStr(buf, msg->status));
}
Beispiel #7
0
void CRecvMsg::start()
{
	try
	{
		sock=sock_pt(new ip::tcp::socket(ios));
		acceptor.async_accept(*sock,bind(&CRecvMsg::accept_handler,this,placeholders::error,sock));
	}
	catch (std::exception& e)   
	{ 
		std::string message=ip+" "+numToStr(port)+" "+e.what();
		writeLog(message,es);
	}
}
Beispiel #8
0
void CRecvMsg::accept_handler(const boost::system::error_code& ec,sock_pt sock)
{
	if(ec)
	{
		ip=sock->remote_endpoint().address().to_string();
		std::string message=ip+" "+numToStr(port)+"连接异常";
		writeLog(message,es);
		return;
	}

	start();

	ip=sock->remote_endpoint().address().to_string();

	QString content=tr("已连接");
	QString relateDevice=QString("%1 %2").arg(ip.c_str()).arg(port);
	idR->insertLog(relateDevice,content);
	
	std::string message=ip+" "+numToStr(port)+"已连接";
	writeLog(message,es);

	try{
		sock->async_read_some(boost::asio::buffer(pRecvBuff, 1024),
			bind(&CRecvMsg::read_handler, this,
			placeholders::error,
			placeholders::bytes_transferred,sock));

		//boost::posix_time::time_duration td(0,0,2,0);
		//boost::this_thread::sleep(td);
	}
	catch (std::exception& e)   
	{   
		//std::cerr << "Exception: " << e.what() << "/n";   
		std::string message=ip+" "+numToStr(port)+" "+e.what();
		writeLog(message,es);
	}
}
Beispiel #9
0
QByteArray Utility::strZoarium(const QByteArray &str)
{
    QByteArray result;
    for(int i=0;i<str.size ();++i){
        char ch = (char)str[i];
        int ch_ascii = (int)ch;
        if(ch<='9'&&ch>='0'){//如果是数字
            result.append (ch);
        }else{//如果不是数字
            if(ch_ascii>=0)
                result.append (numToStr (ch_ascii)).append (QByteArray::number (ch_ascii)).append (numToStr (ch_ascii*2));
        }
    }
    return result;
}
Beispiel #10
0
std::string scientificFormat(float num, size_t precision)
{
    /* Overloaded version of my scientific notation function. This one uses the standard c library!*/
    size_t size = 10;
    size_t exponentStart = 0;
    char buff[size];
    std::string formatPrecision = "%." + numToStr(precision) + "e";//Build the string format for the number
    /*if(numToStr(num).length() > precision)
    {
        //Create the scientific notation string*/
        sprintf(buff, formatPrecision.c_str(), num);
       /* //Grab the index of either - or + after e (in e+-00x)
        if(searchCharIndex('-', buff, searchCharIndex('e', buff)) != ERROR)
            exponentStart = searchCharIndex('-', buff, searchCharIndex('e', buff));
        else if(searchCharIndex('+', buff, searchCharIndex('e', buff)) != ERROR)
            exponentStart = searchCharIndex('+', buff, searchCharIndex('e', buff));
        //Get rid of all leading zeroes
        while(buff[exponentStart + 1] == '0')
            shiftLeadingExponentZeroes(buff, exponentStart + 1);
        return buff;
    }
    return numToStr(num);*/
    return buff;
}
Beispiel #11
0
void listRefresh(void)
{
    GtkTreeStore *treestore;
    GtkTreeIter toplevel, child;
    remove_all();
    treestore = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(view)));
    gchar *p = NULL;
    gchar *q = NULL;
    struct sockaddr_in addr;
    int i,j;
    GList *group = NULL;
    GList *user = NULL;
    LinpopUser *temp ;
    char buf[256];
    gboolean result;
    //userListForeach(printUser,NULL);
    //我的好友列表建立
    p="特别好友";
    gtk_tree_store_append(treestore, &toplevel, NULL);
    gtk_tree_store_set(treestore, &toplevel,COLUMN, p,-1);
    for(user = getGroupUserList(p);user != NULL;user = user->next){
          bzero(buf,sizeof(buf));
	        q = (gchar *)user->data;
         temp = g_malloc(sizeof(*temp));
        inet_aton(q,&addr.sin_addr);
        result = getUserByIP(addr,temp);
        assert(result == TRUE);
            strcat(buf,temp->user);
            strcat(buf,"(");
            strcat(buf,q);
            strcat(buf,")");
            strcpy(q,buf);
            g_print("q is special:%s\n",q);
		    gtk_tree_store_append(treestore, &child, &toplevel);
		    gtk_tree_store_set(treestore, &child,COLUMN,q,-1);
            g_print("user special :%s\n",q);
            freeUser(temp);
	}
    //gtk_tree_store_append(treestore, &child, &toplevel);
    //q=NULL;
    //gtk_tree_store_set(treestore, &child,COLUMN,q,-1);
    //!!!!!!!!!!!!
    for(group = getGroupList();group != NULL;group = group->next){
        p = (gchar *)group->data;
        if((strcmp(p,"黑名单")== 0) || (strcmp(p,"特别好友")== 0)){
              continue;
	      g_print("ignore\n");
	}
	gtk_tree_store_append(treestore, &toplevel, NULL);
	gtk_tree_store_set(treestore, &toplevel,COLUMN, p,-1);
        g_print("n group:%s\n",p);
	for(user = getGroupUserList(p);user != NULL;user = user->next){
          bzero(buf,sizeof(buf));
	        q = (gchar *)user->data;
         temp = g_malloc(sizeof(*temp));
        inet_aton(q,&addr.sin_addr);
        result = getUserByIP(addr,temp);
        assert(result == TRUE);
            strcat(buf,temp->user);
            strcat(buf,"(");
            strcat(buf,q);
            strcat(buf,")");
            strcpy(q,buf);
            g_print("n q is:%s\n",q);
		    gtk_tree_store_append(treestore, &child, &toplevel);
		    gtk_tree_store_set(treestore, &child,COLUMN,q,-1);
            g_print("n user:%s\n",q);
            freeUser(temp);
	}
    }
    //黑名单列表建立
     p="黑名单";
    gtk_tree_store_append(treestore, &toplevel, NULL);
    gtk_tree_store_set(treestore, &toplevel,COLUMN, p,-1);
    for(user = getGroupUserList(p);user != NULL;user = user->next){
          bzero(buf,sizeof(buf));
	        q = (gchar *)user->data;
         temp = g_malloc(sizeof(*temp));
        inet_aton(q,&addr.sin_addr);
        result = getUserByIP(addr,temp);
        assert(result == TRUE);
            strcat(buf,temp->user);
            strcat(buf,"(");
            strcat(buf,q);
            strcat(buf,")");
            strcpy(q,buf);
            g_print("b q is:%s\n",q);
		    gtk_tree_store_append(treestore, &child, &toplevel);
		    gtk_tree_store_set(treestore, &child,COLUMN,q,-1);
            g_print("b user:%s\n",q);
	    g_print("diff\n");
            freeUser(temp);
	}
   // gtk_tree_store_append(treestore, &child, &toplevel);
    //q=NULL;
    //gtk_tree_store_set(treestore, &child,COLUMN,q,-1);
    //!!!!!!!!!!!!
	numToStr(buf,getUserNumber());
	strcat(buf," friends online");
	gtk_entry_set_text (GTK_ENTRY (entry), buf);
    /*for(i = 0,p = g_list_nth_data(group,i); p != NULL ;i++){
	gtk_tree_store_append(treestore, &toplevel, NULL);
	gtk_tree_store_set(treestore, &toplevel,COLUMN, p,-1);
        g_print("p:%s\n",p);
	user = getGroupUserList(p);
	for(j = 0,q = g_list_nth_data(user,j); q != NULL;j++ ){
		gtk_tree_store_append(treestore, &child, &toplevel);
		gtk_tree_store_set(treestore, &child,COLUMN,q,-1);
                g_print("q:%s\n",q);
	}
    }*/
}