lundi 30 mars 2015

OpenGl viewport zooming


I'm a bit new in opengl so please bear with me. I have a viewport window like this


http://ift.tt/1GFZsoQ


I have implemented a zoom in and zoom out using the arrow keys now the problem is it zooms in and out with the whole image. Can anyone put me in the right direction as to how i can make the gui on the sides stay in place while making my viewport the white background zoom in and out.


Any tips or suggestions on how i would accomplish this would be greatly appreciated!




Creating a NTP client with no prior network programming experience. Where do I start?


I have a task to implement a NTP client in C/C++. I have not done much programming in the networking area before and i'm not really sure where to start. Eventually this NTP client needs to be implemented in an embedded system, but I figured it would be wise to start out easy and implement it in a pc program first and then continue from there.


I've read through this: http://ift.tt/1GFYnxp, but I didn't get much wiser as to where to start. Any help to get me started would be greatly appreciated




Find the number of steps required to reach at the top of ladder


I have one question, where i have to climb a ladder of N steps. I have to follow this rule to reach at the top of ladder 1. Take one step 2. Skip one 3. Take another step 4. Skip two steps.


and so on..till i reaches at top.


Algorithm to find the required number of steps i have to take to reach at the top of ladder.


Thanks




Voronoi diagram of point clusters?


Is there a way to compute the voronoi diagram of groups of points?


I.e. all points with the same label/value should be entirely contained by one voronoi segment. Computing the centroid of each group and using that for a regular voronoi diagram will not guarantee that points of the same group are contained within the same segment.


Calculating the convex hull of each group is also not satisfactory as it does not guarantee that either all segments are joined, or that segments do not overlap.


I am trying to derive approximate postal-code boundaries based on lat/long information for individual addresses.


The data itself is in postgis, but any language is suitable (extra points for solutions using sql, python or C++)...




Passing reference of packed struct member to template. gcc bug?


I encountered a problem, passing struct member to a template function. The function's goal is to take the address and size of the member. Here is simple example:


This is the struct. It has packed attribute.



struct TestStruct {
unsigned char elem1;
unsigned char elem2;
uint64_t elem3;
char buf[10000];
int elem4;
unsigned char elem5;
}
__attribute__ ((packed));


this is the template function, which should get a member's address



template<typename T>
void addData(const T &val)
{
printf ("address inside func: %p \n",&val);
}

int main(int argc, char *argv[])
{
TestStruct testdata;
testdata.elem4 = 0;
printf ("struct address is: %p \n",&testdata);
printf ("elem4 address is: %p \n",&testdata.elem4);
addData(testdata.elem4);
return 0;
}


The problem: When attribute ((packed)); is set (like in the example) the template function receives wrong address of the member:


Output:



struct address is: 0x7fff735bb4e0
elem4 address is: 0x7fff735bdbfa
address inside func: 0x7fff735bb4dc


If I remove the "packed" attribute, everything is OK. There is no error and no warning (even with -Wall -Wextra), but not the right address is passed to the function.


I read this:


http://ift.tt/1xO5ke8


and found that there is an issue, getting references to packed-struct members. Interesting enough, replacing const T& with T& in my template function, produces the error message:



error: cannot bind packed field ‘testdata.TestStruct::elem4’ to ‘int&’


So, I have 2 questions:




  1. Why cannot packed-struct members be passed as const references, when their address can be passed as pointer




  2. What happens in the const T& case? There is no error, no warning, but the incorrect address is passed to the function. As we know, the address of reference is the address of the variable, the reference points to.






C++ template function specialization as an argument of template function


Consider a c++ template function specialization :



namespace test {

template < const int L, typename InputIt >
typename std::iterator_traits<InputIt>::value_type
Sum_L( InputIt beg, InputIt end)
{
typedef typename std::iterator_traits<InputIt>::value_type real_t;

for( int i=0 ; i<L; ++i)
call_rearrange_sum( beg, end);

real_t sum( 0 );
for( ; beg != end; ++beg)
sum += *beg;

return sum;
}

template < const int L, typename Real >
Real
Sum_L( const std::size_t len, Real * x)
{
for( int i=0 ; i<L; ++i)
call_rearrange_sum( x, x+len);

Real sum( 0 );
for( std::size_t i=0; i< len; ++i)
sum += x[i];

return sum;
}

template < typename Real, typename Func >
Real
special_sum( std::size_t len, const Real * const x, const Real * y, Func f)
{
std::vector<Real> res( 2*len );

for( std::size_t i=0; i<len; ++i) {
Real tmp;
res.push_back( call_operator( x[i], y[i], &tmp);
res.push_back( tmp );
}

return f( res.begin(), res.end(), f);
}
}


Now I want to use the above functions as :



double my_test( const std::size_t len, double * x, double * y)
{
return test::special_sum( len, x,y,
test::Sum_L< 4, typename std::vector<double>::iterator> );
}


The gcc 4.9.2 it is not able to find the correct template specialization function. The error is "no matching function for call to 'special_sum(std::size_t&, const double*&, const double*&, < unresolved overloaded function type > )'.


Ι know that it is difficult to resolve by the compiler. From whatever I tried, it is one of the two template function 'Sum_L' to get an extra dummy-template argument. Is there any other way?


Thanks.




How to allocate memory for object of the derived class by pointer of the base class using malloc?


For example there is a chain



class A
{
int a;
int b;
public:
A();
};

class B: public A
{
int c;
char b;
public:
B()
};


In ordinary way to to create an object of the derived class we can use this form



A* ptr = new B()


How to do the same using malloc ?