I would like to store the following values in a Vector but I'm not sure how, please help.
Thanks again
Joseph Maddison
Ranch Hand
Joined: Nov 04, 2004
Posts: 53
posted
0
Take your double and create a wrapped Double around it.
when accessing the value of a Double, use the doubleValue() method of the wrapper class.
Hope this helps, jdmaddison
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
posted
0
If you plan on doing calculations like those above, this is probably not the way to go. The standard Vector class is very clunky when it comes to mathematical operations on primitive types. Also, it is easy to confuse the Vector class with the concept of a vector in physics or mathematics. They are NOT really the same thing. Since it looks like you are trying to do a cross product here, you may want to make your own Vector class that behaves more like the mathematical vector that you are trying to imitate. I've done this before myself specifically for 3D graphics, so I call it Vector3D to avoid confusion with java.util.Vector from the Java API.
does Double x return a boolean value or an Object value?
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
posted
0
I'm not sure that I understand your question. The code
Doesn't return anything since there is no function call here. This just declares a variable x that refers to an object of type Double.
However, I don't think this is the answer you are looking for. Can you please clarify your question?
Thanks,
Layne
Fran Montanez
Greenhorn
Joined: Jan 14, 2005
Posts: 14
posted
0
I'm trying to add a value to Double x which I thought would be of type double. And then I wanted to try to put the Double x value into the Vector.
However, when I conpiled it I got back an error that said incompatible types. So I'm cofused as to which type it would take.
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
posted
0
Can you please post your code and the exact error message? Also indicate what line causes the error.
As a side note, remember that Java is case sensitive, so "Double x" means that x is of type Double, not type double.
Layne
Fran Montanez
Greenhorn
Joined: Jan 14, 2005
Posts: 14
posted
0
This is the double for loop in which normalCrossX is defined in an init method.
I had wanted to pass the information stored in normalCrossX, normalCrossY, normalCrossZ into this method which takes floats and is in a method called display.
thanks for any help
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
posted
0
So what is the compiler error and what line of code causes it?
Also, why are you using glNormal3[f() when the values you have are doubles? I'm pretty sure that OpenGL provides a glNormal3d() method that takes doubles as parameters. OpenGL commonly uses suffixes on method names to specify the types of parameters. This is an unfortunate side-effect of its roots in C where there is no function (or method) overloading.
F:\Potionbottle\BottleRotation5.java:106: inconvertible types found : boolean required: float gl.glNormal3f((float)nrm.add( x ), (float)nrm.add( y ), (float)nrm.add( z ));
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
posted
0
First of all, you should really, really learn to navigate the Java API documentation. Use this link to find the docs for the version of Java that you are using. (I will give some links in the following discussion to the pages in the docs for JDK 1.4.2, as I believe it is fairly common. However, if you have an older version, you should double check.)
Secondly, I think this is a really bad way to go. Using the Vector class in this way makes the code much harder to write, imo. You should strongly consider writing your own Vector3D class that acts like a mathematical vector, which is much closer to the concepts in OpenGL than that of the standard Vector class.
However, if you insist on going this direction, you can look at the API docs for Vector and see that Vector.add() attempts to add an element to the Vector and returns true to indicate that the Vector was changed as a result of the call. As you can see, this return value doesn't make any sense in the context of the line of code that is giving you problems. Rather, you need to retrieve an Object that was (hopefully) previously added to the Vector.
To do this, you should call Vector.get(). You also need to look closely at the API docs. It says that Vector.get() returns an Object. In order to reference the Object as a Double, you need to use a cast such as this:
Then to get the double primitive in this Double object, you need to call Double.doubleValue() (again, you can find this method by navigating the API docs):
Hopefully, this will get you on your way. However, I would like to emphasize that I think this is a difficult way of accomplishing this task. You should reconsider even using the Vector class here. In my opinion, it is not appropriate.
Still, I wish you luck in your project. Keep working at it.
Layne
Fran Montanez
Greenhorn
Joined: Jan 14, 2005
Posts: 14
posted
0
Thank you for all your help
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
posted
0
No problem! Come back with more questions.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.