|
Hello sorry I wasn't very clear, basically at the moment I have a camera that following the player in the 4 direction i.e moving forward, backwards and strafing right and left, I was aiming to be able to rotate the camera around the player in order to me able to see the rest of the world around him.
yet when I tried adjusting the glrotate i got the camera to kinda rotate but the longer to hold either left or right the further away from the player the camera becomes.
//Bind Camera to Player
gluLookAtf(player.position.getX() + player.xrot ,player.position.getY() + 15, player.position.getZ() + 20,
player.position.getX() ,player.position.getY(),player.position.getZ() ,
0.0, 1.0, 0.0);
glPushMatrix();
glRotatef(xrot, 0.0, 0.1, 0.0);
glTranslatef(pos.getX(), pos.getY(), pos.getZ());
|
|
|
|
|
In a robotics context, at this point I'd ensure I was using a work (player) co-ordinate system rather than a global (the game area) coordinate system or a tool (camera) coordinate system. Is your coordinate system based on the player at this point to make rotation easier? or if not can you switch to one that is?
Also are you using a polar coordinate system, to rotate around the player?
|
|
|
|
|
|
Sounds like you need to apply two transformations then, one for the player to rotate them and one to rotate the camera position around the same point. That's about the limit of my gl recall I'm afraid.
|
|
|
|
|
Here is the description:
Consider lists of numbers from real-life data
sources, for example, a list containing the number of students enrolled in different
course sections, the number of comments posted for different Facebook status
updates, the number of books in different library holdings, the number of votes per
precinct, etc. It might seem like the leading digit of each number in the list should
be 1–9 with an equally likely probability. However, Benford’s Law states that the
leading digit is 1 about 30% of the time and drops with larger digits. The leading
digit is 9 only about 5% of the time. Write a program that tests Benford’s Law. Collect a list of at least one hundred numbers from some real-life data source and enter them into a text file.
Your program should loop through the list of numbers and count how many times 1 is the
first digit, 2 is the first digit, etc. For each digit, output the percentage it appears
as the first digit. If you read a number into the string variable named strNum then you can access
the first digit as a char by using strNum[0] .
And Here is how I got so far:
Programming Language C++ (I just take this class this F2013)
#include
#include
#include
#include
#include
#include
int main(int argc, char** [0])
{
std::string strNum
//this just a random # I put in here, I want digit 1-9 NOT ZERO
("15157,83049,1193049090,1289727392,9075,54984,5419981,231540,1498056");
std::map digit_frequency;
for(int i = 0; i < strNum.size(); ++i)
{
std::stringstream ss;
ss << strNum[i];
std::string str = ss.str();
if(isdigit(str[0]))
{
++digit_frequency[str[0]];
}
else if(isdigit(str[1]))
{
++digit_frequency[str[1]];
}
}
std::map::iterator it;
for(it = digit_frequency.begin(); it != digit_frequency.end(); it++)
{
std::cout << "Leading Digit " << it->first << ": repeated " << it->second << " time(s).\n";
}
return 0;
}
output:
click the link to see the output.
http://www.facebook.com/#!/photo.php?fbid=10200531325265379&set=a.1645092726942.2077529.1225598765&type=1&theater
KingLord
|
|
|
|
|
Very interesting; now do you have a question?
Use the best guess
|
|
|
|
|
Hi,
I suppose that you didn't expect the result you've got.
Your program doesn't check the frequency of the first digit of the number but all the digits in the stream.
You have to split your data set into numbers first and then take only the first digit of that number.
Now there are several ways to split a number but the easiest is probably to use the getline function of a stream. The get line default uses the endline to seperate the lines but you can provide your own delimiter.
std::string sNumber;
std::stringstream numberStream = std::stringstream(strNum);
while (std::getline(numberStream , sNumber, ','))
{
++digit_frequency[sNumber[0]];
}
This reduces the complexity of your program, which is good in industrial code but isn't when someone still needs to learn coding algorithms.
I think your aim should be to write your own string split function/algorithm.
regards
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
Create a "number box" that has 10 compartments, one for each digit 0-9.
For each number in your list
Check the first digit.
If it is a 0, increment the "0" compartment in the above-mentioned box.
If it is a 1, increment the "1" compartment in the above-mentioned box.
If it is a 2, increment the "2" compartment in the above-mentioned box.
...
Next
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I'm updating an existing MFC project from VC6 into VC2010, and adding dockable window functionality. In doing so, I've recreated some CDialog-based windows as CPaneDialogs. In general, this works well, but there's a visual anomaly with CTabCtrls: the unpopulated portion of the tab bar is a different colour from the CPaneDialog background.
This can be seen be tweaking the SetPaneSize example in the 2008 Feature Pack to add a CTabCtrl to the IDD_DLG_BAR dialog. Derive from CPaneDialog and then add something like:
BEGIN_MESSAGE_MAP(CMyPaneDialog, CPaneDialog)
ON_MESSAGE(WM_INITDIALOG, HandleInitDialog)
END_MESSAGE_MAP()
LRESULT CMyPaneDialog::HandleInitDialog(WPARAM wParam, LPARAM lParam)
{
VERIFY(m_tabCtrl.SubclassDlgItem(IDC_TAB1, this));
TC_ITEM tci;
tci.mask = TCIF_TEXT;
tci.pszText = _T("A");
m_tabCtrl.InsertItem(0, &tci);
tci.pszText = _T("B");
m_tabCtrl.InsertItem(1, &tci);
m_tabCtrl.SetCurSel(0);
return CPaneDialog::HandleInitDialog(wParam, lParam);
}
Searching for solutions to this issue comes up with a lot of suggestions about the CTabCtrl background as a whole, but nothing seems to work. I've tried overriding OnCtlColor, OnEraseBkgnd, etc, but the header steadfastly refuses to change colour. I don't see owner drawing as an option, since theme support would be difficult to replicate.
Even more annoyingly, if I place the same CTabCtrl in SetPaneSize's CFormView, it renders perfectly!
Does anyone have any suggestions I could try? My one thought is that perhaps I'm looking at the problem from the wrong perspective: is the CTabCtrl correct, but the CPaneDialog ignoring theme instructions?
|
|
|
|
|
|
I created at run time window using below styles and left =0
WS_CHILD|WS_VISIBLE|WS_BORDER|WS_THICKFRAME
when I am trying to get windows position
pSrcWnd->GetWindowRect(&rtOriginal);
pSrcWnd->ScreenToClient(&rtOriginal);
I am getting left = -7 but It should be 0.
I investigate the problem I found it because of
WS_THICKFRAME proerty.
How can I get exact position?
|
|
|
|
|
Your conversion makes no sense. You are taking the screen coordinates of your window and converting it to client coordinates relative to itself.
Use the best guess
|
|
|
|
|
what I need to do to get position of window?
|
|
|
|
|
You had the position with pSrcWnd->GetWindowRect(&rtOriginal); , as described in the documentation[^]
Use the best guess
|
|
|
|
|
Relative to what? Child window positions in WinAPI are expressed in the client coordinates of its parent while GetWindowPos always returns screen coordinates. For this reason after getting the screen coordinates of the child control you probably want to transform them into the client coordinate space of the parent control.
pChild->GetWindowRect(&rt);
pParent->ScreenToClient(&rt);
In contrast to this MoveWindow() and SetWindowPos() expect coordinates that are in the client coordinates of the parent window (that is the screen for top level windows). Always read the docs about the expression of coordinates. For example in case of mouse messages you always receive mouse pos in client coordinates of the control that receives the message but there is one exception: WM_MOUSEWHEEL returns screen coordinates. So: Read docs!!!
modified 19-Aug-13 12:20pm.
|
|
|
|
|
pasztorpisti wrote: So: Read docs!! What, when you can post a question at CodeProject?
Use the best guess
|
|
|
|
|
I should have asked it from someone else (maybe on codeproject) before answering this question!
|
|
|
|
|
Do you know what is a client area/coordinate and have you read the documentation of GetWindowRect and ScreenToClient? Calling these functions in this order is not very useful...
|
|
|
|
|
I wrote a mfc interface to draw graph and show calculated result. The calculated result is right.It can be showed on the interface everytime. But the graph can not show normally.Under the same condition, sometimes the graph is showed and sometimes it not. I have no idear why it happens. The code about drawing is as follows:
CDC* pDC;
CRect rectPic;
void f_curve();
void CAISIDlg::OnBnClickedButton1()
{
BeginWaitCursor();
UpdateData(TRUE);
width=m_width;
... UpdateData(FALSE);
if( Read_data(FolderPath,dhPath)!=0 )
{
m_picDraw.GetClientRect(&rectPic);
pDC = m_picDraw.GetDC();
f_curve();
m_transmisivity = ((long int)(transmisivity*1e5))/1e5; m_BSE = BSE; UpdateData(FALSE);
}
EndWaitCursor();
}
the f_curve() function is called to draw graph,key code as follow:
void f_curve()
{
...
pDC->SelectObject(PenRed);
pDC->MoveTo( (int)( (db_jinyan[0][0]-minX)*itlX ),
(int)( (db_jinyan[1][0]-minY)*itlY )
);
for(int i=0;i<Len;i++)
pDC->LineTo(
(int)( (db_jinyan[0][i]-minX)*itlX ),
(int)( (db_jinyan[1][i]-minY)*itlY )
);
...
}
why the grapy can not be draw out everytime while the calculated result could?
|
|
|
|
|
You are doing the drawing in the wrong place. Drawing should only be done in response to a WM_PAINT message. In MFC that is in the OnPaint() [^] member function.
Use the best guess
|
|
|
|
|
I wonder why was your answer down-voted.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
Thanks for the counter vote. As to why: who knows, there are strange people around in all walks of life.
Use the best guess
|
|
|
|
|
IMHO the OP wanted to know why his code does not work, and you did not help in that aspect, just suggested a different approach.
My vote of 2
Now you should have better idea why. Or not.
One of the strange people here.
|
|
|
|
|
Vaclav_Sal wrote: the OP wanted to know why his code does not work, and you did not help in that aspect, just suggested a different approach. No, I explained exactly why his code does not work, because he is painting to the screen in the wrong place. Spending more time reading the available documentation would have also helped.
Use the best guess
|
|
|
|
|
Hi,
I am getting an exception on a WaitForSingleObject
Below is the code the Security events parameter of the CreateEvent is NULL I am Wondering if that might be the issue
Event_Handle = ::CreateEvent(NULL, FALSE, FALSE, NULL);
int i;
UINT start_port;
for (i = 0, start_port = 11007; i < 4; start_port++, i++)
{
threadptr[i] = NULL;
threadptr[i] = new SockCLeintThread(start_port);
threadptr[i]->m_pActiveWnd = m_pMainWnd;
threadptr[i]->m_pMainWnd = m_pMainWnd;
if (threadptr[i] == NULL)
m_pMainWnd->MessageBox((LPCTSTR)"SockClientThreadFail",NULL,MB_ICONERROR);
threadptr[i]->CreateThread(CREATE_SUSPENDED,0,NULL);
threadptr[i]->flags.is_connected = 0;
threadptr[i]->ipaddr = (LPCTSTR)"192.168.1.4";
threadptr[i]->flags.busy = 0;
SetThreadName(threadptr[i]->m_nThreadID,thread[i]);
threadptr[i]->ResumeThread();
DWORD return_value = ::WaitForSingleObject(Event_Handle,INFINITE);
|
|
|
|
|