Jump to content

  • Log In with Google      Sign In   
  • Create Account

Brother Bob

Member Since 26 Nov 2001
Online Last Active Today, 07:46 AM

#5198734 constructor for class that contains another class and constructor C++

Posted by Brother Bob on 17 December 2014 - 03:16 AM

As BitMaster said, the base class is responsible for initializing itself. You don't initialize the base class from derived classes, but instead you delegate the work to it from the derived class' constructor.

template <class _cType> class  t4dpoint : public t3dpoint<_cType> {
public:
    _cType w;
 
    // the t3dpoint base class is automatically default initialized if not specified, and then initialize our own member
    t4dpoint<_cType>() : w(1.0)
    { }
 
    // initialize the t3dpoint base class and then initialize our own member
    t4dpoint<_cType>(_cType x, _cType y, _cType z, _cType w) : t3dpoint(x,y,z), w(w)
    { }
};



#5198611 declare custom types of ints?

Posted by Brother Bob on 16 December 2014 - 03:13 PM

 

Use enums, or wrap the integers in different classes.


If we are talking about C++ it should be enum class instead of the standard enum as the latter one is basically just an int with a fancy name.

Note that enum class was introduced in C++11 so it might not be available for your compiler.

 

Depends on what you want to do with the enum, what extra protection you want, and what possibilities you are willing to drop. The OP asked for a way to prevent passing one kind of value to a parameter or a different kind (passing an animation as a model, or vice versa) and you don't need the new strong enums for that.




#5198597 declare custom types of ints?

Posted by Brother Bob on 16 December 2014 - 02:35 PM

Use enums, or wrap the integers in different classes.




#5196219 My "Hello World" OpenGL application doesn't display anything

Posted by Brother Bob on 04 December 2014 - 04:17 AM

Your perspective matrix has a znear of 1. Your modelview is identity. Your points are at z=0. They are outside of your view area. Try placing your points at z>=1.

The symptom is correct, but it has to be z <= -1, because the Z-axis is pointing out from the screen towards you. It may be confusing, but the clip plane values are the distances along the negative Z-axis, which mean that a near clip plane value of 1 places the near clip plane value at Z = -1.




#5195970 Help finding error in base 62 converter

Posted by Brother Bob on 02 December 2014 - 05:22 PM

 

I've been working on an encryption system for a program, and as a means of getting size of the encrypted String down, I decided to allow the system to put numbers into any base - 62 being the max (values going 0-9,A-Z,a-z). I wrote this out fairly quickly, and it works for the most part, but *almost* every output value is off on the last character (even worse if not using base 62).
 
Some example cases:
  • 30400066288418849 becomes 2FEQDJkH9F instead of 2FEQDJkH9E (a difference of 1)
  • 21392905688514741 becomes 1Zyk6HmZO9 instead of 1Zyk6HmZO8 (a difference of 1)
  • 22236810928128038 becomes 1dqNWdRcwg instead of 1dqNWdRcwi  (a difference of -2)
  • 1407619700686911 becomes 6Rhvv3b0J, which oddly is right?

[...]

 

I'm sure it's just a small error somewhere, or a tiny oversight, but I've been looking at it on and off for 5 days and still can't see it. System.out.println()-ing each step hasn't been too informative either, as the math seems about right. The digit conversions are all correct too (6=6, 35=Z, 44=i, 61=z, etc).I've been using this site and this one as a means to test my results. Both have the same results, so I think I'm the wrong one here.
 
Any help is greatly appreciated! Cheers! smile.png

 

I've checked all four of them with Matlab and all input numbers convert to what you say your code produce and not what you expect. You can easily see that your expectation for the first two are incorrect: 9 and 1 from the inputs are odd, but E and 8 from your expectations are even, and thus your expectations cannot be correct. However, F and 9 from the values your code produce are indeed odd values.

 

I tried the converter code in your last link and 30400066288418848, 30400066288418849 and 30400066288418850 all convert to 2FEQDJkH9E, while 30400066288418851 converts to 2FEQDJkH9I. Without looking at that code, I suspect that they are doing the calculations with 64-bit floating point values. Since they only have 53 bits of precision and 30400066288418849 in on the order of 54 bits, there simply isn't enough precision to do precise integer calculations at those magnitudes.

 

In short, your code produces the correct values (not saying there aren't other corner cases where it may be wrong, just that you examples are correct), and your links are not precise enough for your values.




#5195934 1 VBO and multiple blend modes

Posted by Brother Bob on 02 December 2014 - 02:06 PM

Hello everyone!
 
 
I was wondering ...
When i create one big vbo then can i have different blending modes in it?
 
for example i put house in vbo and the walls will be glBlendFunc(GL_ONE, GL_ONE), glBlendEquation(GL_FUNC_ADD); and the windows will be 
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glBlendEquation(GL_MIN);
just really random but well you get the idea.

 
You don't put blend modes into your buffer objects. They are completely different things and are unrelated to each other. If you need different blend modes when drawing different parts of the buffer objects, then simply change blend mode before drawing.
 

the one other question, am i right that if im having one vbo then vertices what are in it, i dont have to sort them near to far when using blend am i right?

Thanks!

If the blend mode you use requires back-to-front drawing order, or any other order, then you have to sort those vertices accordingly.




#5195549 Return value

Posted by Brother Bob on 30 November 2014 - 02:57 PM

I think Brother Bob may have misread the code, "it" is not directly an iterator object. A different name can help disambiguate, e.g. "entry", "element", etc.

Indeed I did. The name sure made me assume it was an iterator so I didn't even pay attention to the loop. Thanks for pointing that out.




#5195503 Return value

Posted by Brother Bob on 30 November 2014 - 10:58 AM

My question is what do I return as NULL?

 
You can't. Think of a reference as an alias for an existing object. If so, by definition, a reference can't indicate "non-existent object."

And what you do instead is to throw an exception if no object is found, or you go back to returning a pointer. You can return a pointer to the object in the vector so you don't have to change the vector to store pointers.


#5194640 find components distances from 2 points on a plane n

Posted by Brother Bob on 25 November 2014 - 11:58 AM

Brother Bob:
Project the vector between the two points onto the X and Y vectors. Just ensure that the X and Y vectors are normalized.
 
The projections are the component along the X and Y directions, respectively - ? you mean after projection i take the vector length? X len = veclength(Xvec* Projected(B-A))

 
The projection of a vector onto another vector is calculated using the dot product.

xlen = dot(B-A, x)
ylen = dot(B-A, y)

Buckeye
 
Oh indeed i can

What you are calculating is the angle between the vector cpos-pos and what appears to be the X-axis. You are therefore not calculating the angle between two points, but between two vectors, just what Buckeye stated. One vector is cpos-pos and the other vector is implicitly hardcoded as the X-axis.

 

Furthermore, use atan2 instead of manually correcting for the different quadrants.




#5194607 find components distances from 2 points on a plane n

Posted by Brother Bob on 25 November 2014 - 09:24 AM

Take a look on at the image on the right.I need to find y and x distances between two dots (points) that lie on this plane i know the y and x directions and the points poisition, surface normal is also known.

Project the vector between the two points onto the X and Y vectors. Just ensure that the X and Y vectors are normalized. The projections are the component along the X and Y directions, respectively.

 

I need this to find angle between these two points (and i need it to e between 0..360) maybe someone knows better formula to achieve this.

I will take a guess that you don't need the angle, but rather that you want the angle because you don't know a solution in linear algebra. You have a vector-based problem, and solutions rarely involve angles. Describe your problem instead and we'll propose a vector solution that isn't dependent on angles.




#5194097 Visual Studio C++ building from command line

Posted by Brother Bob on 22 November 2014 - 03:43 AM


Is there a way to specify a log file to output to with cl.exe?

Maybe there's an explicit option for it, but you can always just pipe the output to a file instead of to the console.

 

cl ... > log.txt



#5193135 member access into incomplete type

Posted by Brother Bob on 16 November 2014 - 03:09 PM

The definition of the getSomething function belongs to the object class, but you've defined it as a free function instead.




#5193129 member access into incomplete type

Posted by Brother Bob on 16 November 2014 - 02:42 PM

component.cpp has to include object.h to get the definition of the object class. You also need include guards to prevent multiple inclusions.




#5192919 Proper C++ header file?

Posted by Brother Bob on 14 November 2014 - 05:59 PM



class TileMap()

No parentheses at the class definition.




#5192649 VBO display nothing, but VAO yes

Posted by Brother Bob on 13 November 2014 - 08:21 AM

If my memory serves me right, vertex array objects are mandatory from version 3.3. It is an error to bind vertex buffer objects and set pointers and such without a bound vertex array object. However, nothing prevents you from binding a dummy-object at the beginning and then pretending you don't use vertex array objects.






PARTNERS