[QUOTE=Richy19;38580874]It works fine if the reference is a const, so:
[cpp]WaterCube(const glm::vec3 &pos = glm::vec3(0.0f));[/cpp]
works fine.
Also are these coordinates/indecies correct for a cube? I think so but all its drawing is 1 triangle
[cpp]/*
* 8/---/5
* / /|
* 1/---/4|
* | | /6
* | |/
* 2\---/3
*/
glm::vec3 vec[8];
vec[0] = glm::vec3(-0.5f, 0.5f, 0.5f);
vec[1] = glm::vec3(-0.5f, -0.5f, 0.5f);
vec[2] = glm::vec3(0.5f, -0.5f, 0.5f);
vec[3] = glm::vec3(0.5f, 0.5f, 0.5f);
vec[4] = glm::vec3(0.5f, 0.5f, -0.5f);
vec[5] = glm::vec3(0.5f, -0.5f, -0.5f);
vec[6] = glm::vec3(-0.5f, -0.5f, -0.5f);
vec[7] = glm::vec3(-0.5f, 0.5f, -0.5f);
GLuint index[36];
index[0] = 1;
index[1] = 2;
index[2] = 4;
index[3] = 4;
index[4] = 2;
index[5] = 3;
index[6] = 4;
index[7] = 3;
index[8] = 5;
index[9] = 5;
index[10] = 3;
index[11] = 6;
index[12] = 5;
index[13] = 6;
index[14] = 8;
index[15] = 8;
index[16] = 6;
index[17] = 7;
index[18] = 8;
index[19] = 7;
index[20] = 1;
index[21] = 1;
index[22] = 7;
index[23] = 2;
index[24] = 8;
index[25] = 1;
index[26] = 5;
index[27] = 5;
index[28] = 1;
index[29] = 4;
index[30] = 2;
index[31] = 7;
index[32] = 3;
index[33] = 3;
index[34] = 7;
index[35] = 6;[/cpp][/QUOTE]
On the last face, I think it should be 2, 3, 7, 7, 6, 3. Those faces are counter-clockwise but the rest of them are clockwise.
[QUOTE=robmaister12;38581205]On the last face, I think it should be 2, 3, 7, 7, 6, 3. Those faces are counter-clockwise but the rest of them are clockwise.[/QUOTE]
wait what, they should all be counter-clockwise
[QUOTE=Richy19;38581311]wait what, they should all be counter-clockwise[/QUOTE]
Oh wait, crap, got confused going around the back... make sure you're setting glFrontFace to GL_CCW, I went over it a few times and all the faces seem to be counter-clockwise...
[QUOTE=robmaister12;38581417]Oh wait, crap, got confused going around the back... make sure you're setting glFrontFace to GL_CCW, I went over it a few times and all the faces seem to be counter-clockwise...[/QUOTE]
Yea I tried that, but this is what shows up
[img]http://i.imgur.com/3mYan.png[/img]
Thoguth I would share the whole cube class incase:
[cpp]
WaterCube::WaterCube(const glm::vec3 &pos)
{
/*
* 8/---/5
* / /|
* 1/---/4|
* | | /6
* | |/
* 2\---/3
*/
glm::vec3 vec[8];
vec[0] = glm::vec3(-0.5f, 0.5f, 0.5f);
vec[1] = glm::vec3(-0.5f, -0.5f, 0.5f);
vec[2] = glm::vec3(0.5f, -0.5f, 0.5f);
vec[3] = glm::vec3(0.5f, 0.5f, 0.5f);
vec[4] = glm::vec3(0.5f, 0.5f, -0.5f);
vec[5] = glm::vec3(0.5f, -0.5f, -0.5f);
vec[6] = glm::vec3(-0.5f, -0.5f, -0.5f);
vec[7] = glm::vec3(-0.5f, 0.5f, -0.5f);
GLuint index[36];
index[0] = 1;
index[1] = 2;
index[2] = 4;
index[3] = 4;
index[4] = 2;
index[5] = 3;
index[6] = 4;
index[7] = 3;
index[8] = 5;
index[9] = 5;
index[10] = 3;
index[11] = 6;
index[12] = 5;
index[13] = 6;
index[14] = 8;
index[15] = 8;
index[16] = 6;
index[17] = 7;
index[18] = 8;
index[19] = 7;
index[20] = 1;
index[21] = 1;
index[22] = 7;
index[23] = 2;
index[24] = 8;
index[25] = 1;
index[26] = 5;
index[27] = 5;
index[28] = 1;
index[29] = 4;
index[30] = 2;
index[31] = 7;
index[32] = 3;
index[33] = 3;
index[34] = 7;
index[35] = 6;
indexVBO.AddData(index, 36, sizeof(GLuint ), GL_ELEMENT_ARRAY_BUFFER,GL_STATIC_DRAW);
std::string vertCode =
"#version 120\n" \
"uniform mat4 MVP;\n" \
"attribute vec3 Position;\n" \
"void main(){\n" \
"gl_Position = MVP * vec4(Position, 1.0f);\n" \
"}";
std::string fragCode =
"#version 120\n" \
"void main(){\n" \
"gl_FragColor = vec4(1.0f, 0.0f, 0.0f ,1.0f);\n" \
"}";
shader.LoadShaderCode(vertCode, fragCode);
shader.Bind();
positionVBO.SetAttributeIndex(shader.GetAttribute("Position"));
Shader::Unbind();
positionVBO.Bind (3);
positionVBO.AddData (vec, 8*3, sizeof(float));
positionVBO.Unbind ();
}
WaterCube::~WaterCube()
{
}
void WaterCube::Update()
{
mvp = *mvpoint * glm::mat4(1.0f);
}
void WaterCube::Draw()
{
shader.Bind ();
glUniformMatrix4fv(shader.GetUniform ("MVP"), 1, GL_FALSE, &mvp[0][0]);
positionVBO.Bind (3);
indexVBO.Bind(0);
// Draw the triangles !
glDrawElements(
GL_TRIANGLES, // mode
36, // count
GL_UNSIGNED_INT, // type
(void*)0 // element array buffer offset
);
positionVBO.Unbind ();
Shader::Unbind ();
}
void WaterCube::SetProjViewMatrix(glm::mat4 &mat)
{
mvpoint = &mat;
}
[/cpp]
[editline]25th November 2012[/editline]
changed it from using indexes, to using just the verticies and it works fine...
Does anyone have documentation for Jitter(C# library)? I found only quickstart, which well, tells almost nothing
Fixed my other error, the program runs fine... but the text doesn't render. Here's a [url=http://stackoverflow.com/q/13547150/1846280]link to my problem on stack overflow.[/url]
[QUOTE=HeatPipe;38582374]Does anyone have documentation for Jitter(C# library)? I found only quickstart, which well, tells almost nothing[/QUOTE]
Start by creating a Jitter.World. You'll notice that the constructor requires a Jitter.Collision.CollisionSystem, so create one of those too.
There are 3 implementations available: CollisionSystemBrute, CollisionSystemSAP, and CollisionSystemPersistentSAP. Brute is just checking every object against every other object in the world - O(n^2). SAP is Sweep And Prune, sweeping across one axis and removing non-colliding bodies before doing full checks. PersistentSAP is the same thing, but with 3 axes and the bodies stay sorted. I'm using CollisionSystemPersistentSAP, works pretty well.
You can change some of the world's settings here, i.e. World.Gravity = new JVector(0, 0, 0); for zero-g.
You add bodies to the world with (you guessed it) World.AddBody(body). The Jitter.Dynamics.RigidBody constructor requires a Jitter.Collision.Shapes.Shape. If you look at that namespace, you'll see a variety of shapes - BoxShape, CapsuleShape, ConeShape, etc. You can also define your own shape with a TriangleMeshShape.
From there I'm sure you can explore the library more and find all the cool stuff it lets you do.
[editline]24th November 2012[/editline]
I'd post some code showing all this, but it's pretty spread out in my engine...
[editline]24th November 2012[/editline]
oh, almost forgot. You have to call World.Step for anything to actually happen...
[url]http://jitter-physics.com/Tutorial.pdf[/url]
Found it :D
[editline]25th November 2012[/editline]
[QUOTE=robmaister12;38582867]Start by creating a Jitter.World. You'll notice that the constructor requires a Jitter.Collision.CollisionSystem, so create one of those too.
There are 3 implementations available: CollisionSystemBrute, CollisionSystemSAP, and CollisionSystemPersistentSAP. Brute is just checking every object against every other object in the world - O(n^2). SAP is Sweep And Prune, sweeping across one axis and removing non-colliding bodies before doing full checks. PersistentSAP is the same thing, but with 3 axes and the bodies stay sorted. I'm using CollisionSystemPersistentSAP, works pretty well.
You can change some of the world's settings here, i.e. World.Gravity = new JVector(0, 0, 0); for zero-g.
You add bodies to the world with (you guessed it) World.AddBody(body). The Jitter.Dynamics.RigidBody constructor requires a Jitter.Collision.Shapes.Shape. If you look at that namespace, you'll see a variety of shapes - BoxShape, CapsuleShape, ConeShape, etc. You can also define your own shape with a TriangleMeshShape.
From there I'm sure you can explore the library more and find all the cool stuff it lets you do.
[editline]24th November 2012[/editline]
I'd post some code showing all this, but it's pretty spread out in my engine...
[editline]24th November 2012[/editline]
oh, almost forgot. You have to call World.Step for anything to actually happen...[/QUOTE]
Also thanks! Yeah, I saw that in QuickStart :D.
Here's my fixed code, but the text still doesn't render. I've ran the program through a debugger, and none of the variables are wonky in the slightest. I'm doing as much error checking as I can.
Text.cpp: [url]http://pastebin.com/QeE0jkgK[/url]
Main.cpp: [url]http://pastebin.com/qYXxJCNj[/url]
I'm using this example: [url]http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Text_Rendering_01[/url]
Could someone help me out I got a C# assignment to make a program that converts 4 different temperatures but the trick is I am only allowed to touch a class that has been implemented from an interface.
So my problem is that I have a bunch of methods to convert the temperatures after one of them has been entered and I used the methods like this:
[code]
public decimal Celsius
{
get { return celsius; }
set {
celsius = value;
CtoF();
FtoR();
CtoK();
}
}
public decimal Fahrenheit
{
get { return fahrenheit; }
set
{
fahrenheit = value;
FtoC();
FtoR();
CtoK();
}
}
//and so on for the other two classes
[/code]
But doing it this way gives me a stack overflow error because the methods are referencing eachother back and fourth, any advice on how to use the methods while only being able to edit code in this one class?
[QUOTE=Tovip;38595954]Could someone help me out I got a C# assignment to make a program that converts 4 different temperatures but the trick is I am only allowed to touch a class that has been implemented from an interface.
So my problem is that I have a bunch of methods to convert the temperatures after one of them has been entered and I used the methods like this:
[code]
public decimal Celsius
{
get { return celsius; }
set {
celsius = value;
CtoF();
FtoR();
CtoK();
}
}
public decimal Fahrenheit
{
get { return fahrenheit; }
set
{
fahrenheit = value;
FtoC();
FtoR();
CtoK();
}
}
//and so on for the other two classes
[/code]
But doing it this way gives me a stack overflow error because the methods are referencing eachother back and fourth, any advice on how to use the methods while only being able to edit code in this one class?[/QUOTE]
I don't know if it's possible to change the method definition of FtoC(), FtoR(), CtoK() etc, but you could have them return decimals and call them like this:
[csharp]
public decimal Fahrenheit
{
get { return fahrenheit; }
set
{
fahrenheit = value;
celsius = FtoC();
rakine = FtoR();
kelvin = CtoK();
}
}
[/csharp]
That way you avoid the property setters.
[QUOTE=robmaister12;38596432]I don't know if it's possible to change the method definition of FtoC(), FtoR(), CtoK() etc, but you could have them return decimals and call them like this:
[csharp]
public decimal Fahrenheit
{
get { return fahrenheit; }
set
{
fahrenheit = value;
celsius = FtoC();
rakine = FtoR();
kelvin = CtoK();
}
}
[/csharp]
That way you avoid the property setters.[/QUOTE]
Thanks man that works perfectly, now I just have a lot of rewriting to do.
[code]
/*Setters*/
public void setAll(String[] sa)
{
setNumber(Integer.parseInt(sa[0]));
setPass(sa[1]);
setCash(Integer.parseInt(sa[2]));
}
[/code]
So the setAll takes an array and assigns its elements are used as parameters in some other methods.
Does anyone know a way to make this look neater instead of the hardcoding I'm doing?
Like looping over the methods...
I have been trying to read tilemap data from XML files in XNA. So far, i have figured out how to read the XML files but not actually load the map data from them. The one and only thing im thinking about right now, is how to check if the Xml nodes (whatsoever, the things inside the other things) are in the correct place? Such as:
[CODE]
<Map>
<MapData>
<Tile asd="qwerty"/>
</MapData>
<EntityData>
</EntityData>
</Map>
[/CODE]
would be valid but
[CODE]
<Map>
<MapData>
<Tile asd="qwerty"/>
</MapData>
</Map>
<EntityData>
</EntityData>
[/CODE]
would would not be since the EntityData is in the wrong place. How do i check for correct places for them?
[code]
XmlDocument doc = new XmlDocument();
doc.Load(filepath);
XmlNodeList mapdata = doc.SelectNodes("map");
foreach(XmlNode map in mapdata)
{
if(map.SelectSingleNode("EntityData") == null)
throw new Exception("missing EntityData node in Map");
}
[/code]
or something
-snip-
i'm making tests with Android Development Kit, and i started to mess around with openGL functions, but i am not able of rendering a damn quad.
setting opengl in '2D mode'
[code]
gl.glClearColor(0.5f, 0.5f, 0.5f, 1);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
gl.glShadeModel(GL10.GL_FLAT);
gl.glDisable(GL10.GL_DEPTH_TEST);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glEnable(GL10.GL_TEXTURE_2D);[/code]
then defining four points and their indices
[code]
float vertices[] ={ -0.25f, 0.25f,
-0.25f,-0.25f,
0.25f,-0.25f,
0.25f, 0.25f};
byte indices[] ={1, 2, 0,3};
(.....)
ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4 );
vbb.order(ByteOrder.nativeOrder());
vertexBuffer = vbb.asFloatBuffer();
vertexBuffer.put(vertices);
vertexBuffer.position(0);
ByteBuffer indexBuffer = ByteBuffer.allocateDirect(indices.length);
indexBuffer.order(ByteOrder.nativeOrder());
indexBuffer.put(indices);
indexBuffer.position(0);[/code]
and finally drawing the frames
[code]
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
gl.glColor4f(1.0f,1.0f,1.0f,1f);
gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 1, GL10.GL_UNSIGNED_BYTE, indexBuffer);
[/code]
anyone have an idea about how is this failing?
later i got a gray screen, now i've been changing the code for a while and get a black screen, then the application silently closes due to an error in [code]gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, 1, GL10.GL_UNSIGNED_BYTE, indexBuffer);[/code]
full source here, for interest/help
·Renderer: [url]http://pastebin.com/bCcgsXyW[/url]
·Main Class: [url]http://pastebin.com/W9nLBcRz[/url]
thanks in advice
I would like to learn OpenGL and only use CodeBlocks if possible.
I used this guide to get freeGLUT with CodeBlocks: [url]http://wiki.codeblocks.org/index.php?title=Using_FreeGlut_with_Code::Blocks[/url]
I look everywhere and it's all different and I have no idea where to start.
[url]http://open.gl[/url]
I need help in Java guys.
How would I merge two photo together using dimensional arrays.?
[QUOTE=pyschomc;38608748]I need help in Java guys.
How would I merge two photo together using dimensional arrays.?[/QUOTE]
An image can be represented as an array of color values, with columns and rows (X, Y).
[code]
Color4[][] image = new Color4[image.Width][image.Height];
[/code]
Merging two photos would simply require to create a new 2D array, with an increased size. (If you want to merge the photos on the sides, increase the width, on the bottom, increase the Height). Then fill this array with the first image first, then fill it with the second image offsetting by the first image's width/height.
However, this doesn't take into account the fact that your two images might be of different size and that you might have missing data
[QUOTE=Armandur;38611473]Picked up my SFML2 C++ port of a Viking board-game. It's coming along nicely, and I'm well on my way of implementing the rules for the different types of boards it can be played on.
Kind of wondering if anyone would be so kind as making some art for this, it would be much appreciated :)
[url]https://github.com/Armandur/Hnefatafl[/url]
[IMG]https://dl.dropbox.com/u/5342745/hnefatafl/hnefataflv0-5.png[/IMG][/QUOTE]
[I]cross-post from WAYWO[/I]
I was wondering if anyone would mind taking a look at the code, and informing me if I'm doing something stupid and how I could improve :)
[QUOTE=Armandur;38611485][I]cross-post from WAYWO[/I]
I was wondering if anyone would mind taking a look at the code, and informing me if I'm doing something stupid and how I could improve :)[/QUOTE]
I'm not a pro myself but it looks like there's a lot of code reuse e.g.,
[cpp]
sf::Texture Tile::texture = sf::Texture();
bool Tile::initiated = false;
Tile::Tile(TileType type) // = Empty
{
try
{
if(!init("img/tiles.png"))
{
throw "Could not load img/tiles.png";
}
sprite.setTexture(texture);
this->setType(type);
}
catch(std::exception &e)
{
std::cerr << e.what() << std::endl;
}
}
Tile::~Tile(void)
{
}
void Tile::setType(TileType type)
{
this->type = type;
sf::Vector2<int> pos, size;
//snipped
sprite.setTextureRect(sf::IntRect(pos, size));
}
[/cpp]
[cpp]
sf::Texture Piece::texture = sf::Texture();
bool Piece::initiated = false;
Piece::Piece(PieceType type, sf::Vector2<int> boardPosition) // = Black, (0,0)
{
this->boardPosition = boardPosition;
try
{
if(!init("img/pieces.png"))
{
throw "Could not img/board.png";
}
sprite.setTexture(texture);
this->setType(type);
} catch(std::exception &e)
{
std::cerr << e.what() << std::endl;
}
}
Piece::~Piece(void)
{
}
void Piece::setType(PieceType type)
{
// etc.
[/cpp]
[cpp]
sf::Texture Selector::texture = sf::Texture();
bool Selector::initiated = false;
Selector::Selector(void)
{
try
{
if(!init("img/selectors.png"))
{
throw "Could not load img/selectors.png";
}
sprite.setTexture(texture);
} catch(std::exception &e)
{
std::cerr << e.what() << std::endl;
}
}
Selector::~Selector(void)
{
[/cpp]
I think you can merge it in a class or something
[quote]A picture is represented by a two dimensional array. The elements in the array indicate the amount of gray at each pixel. The value can vary from 0 to 255. The class Picture has been provided for you as well as a PictureViewer so you can see the application visually. There is some advanced code in these classes that you do not need to worry about.
Your job is to write a class Pictures that has a static merge method which PictureViewer will use to merge the two images. There is a MergeTester class provided to help you test the method.
The signature for the merge method is:
public static int[][] merge(int[][] a, int[][] b)
The parameter arrays a and b may be different sizes. Look in your text to find out how to calculate the size of each dimension in a 2D array. The number of rows in the results array will be the larger of the number of rows in arraya andb. The number of columns in the results array will be the larger of the number of columns in arraysa and b
The value of an element at a given position in the results array is calculated as follows:
If the position exists in both arrays, the value in the results array is the average of the values in array a and b.
if the position exists only in array a, the value in the results array is the value in arraya
if the position exists only in array b, the value in the results array is value in array b
if the position is in neither array assign a value of 127 at that position in the results array.
Here are the images that are used in PictureViewer. You will need to copy them into the folder that holds your Bluej project along with PictureViewer.java and Picture.java in order to run PictureViewer and see your method in action.[/quote]
Here is my Prompt o_o
[img]http://horstmann.com/sjsu/fall2012/cs46a/hw12/merged.png[/img]
[img]http://horstmann.com/sjsu/fall2012/cs46a/hw12/blimp.jpg[/img] [img]http://horstmann.com/sjsu/fall2012/cs46a/hw12/tower.jpg[/img]
Any suggestions you guys can help me besides creating a new 2D Array
[QUOTE=pyschomc;38617766]Here is my Prompt o_o
[img]http://horstmann.com/sjsu/fall2012/cs46a/hw12/merged.png[/img]
[img]http://horstmann.com/sjsu/fall2012/cs46a/hw12/blimp.jpg[/img] [img]http://horstmann.com/sjsu/fall2012/cs46a/hw12/tower.jpg[/img]
Any suggestions you guys can help me besides creating a new 2D Array[/QUOTE]
It's basically all laid out for you at the end there. It's really just a matter of following instructions and converting his pseudocode into actual code.
What's holding you up right now?
i'm learning about C++ stacks, how do i create a member function that tests a stack to see if it's full and return a true or false value?
[QUOTE=meppers;38618383]i'm learning about C++ stacks, how do i create a member function that tests a stack to see if it's full and return a true or false value?[/QUOTE]
If you are using arrays in your implementation, just check if the last element is used or free. If you are using linked nodes, you can increment a counter whenever you add an element to the stack, and decrease it when you remove the top, then just compare your counter with the limit to see if your stack is full.
[QUOTE=robmaister12;38618373]It's basically all laid out for you at the end there. It's really just a matter of following instructions and converting his pseudocode into actual code.
What's holding you up right now?[/QUOTE]
He just gave us a Tester code
Haha.
But Yeah It's simple enough to create it from scratch
I'm just kind of confused at some stuff. haha.
In C, can someone please give an example, or link me to a resource / tutorial over reading a file and storing the items into a linked list? I literally can find nothing conclusive on it when I google it, It's all people with some botched code asking for help. Please someone help me D:
I finished everything perfect
I didn't realize the dimensional array was easier than I expected!
Sorry, you need to Log In to post a reply to this thread.