Been coding for too long need a fresh pair of eyes. Any idea why this joint is flat out not getting created?
[cpp]
b2WeldJointDef joint;
std::cout << "A: " << bodyA << " B: " << bodyB << "\n";
joint.Initialize(bodyA, bodyB, bodyA->GetPosition());
mWorld->CreateJoint(&joint);
std::cout << mWorld->GetJointCount() << "\n";
[/cpp]
mWorld is valid. Both bodies are valid. I don't get it! GetJointCount returns 0 after the code is run.
Never mind! Was trying to create a joint in a collision callback, apparently it locks the CreateJoint function in there.
[QUOTE=Richy19;36411576]Im trying to make an MD3 viewer but this is what it has drawn:
<img snip>
The model im using is: [url]http://dl.dropbox.com/u/18453712/car.md3[/url]
the shaders im using are:
Vertex:
<code snip>
and the MD3 class hpp
<code snip>
And the MD3 cpp
<code snip>[/QUOTE]
Well, first off, here's the output of my loader on that same model:
[img]http://i.imgur.com/XUgGk.png[/img]
Now, two things I see immediately suspicious in your code:
1.) You haven't told the compiler to pack your structs as tightly as possible, meaning somethings may get aligned to 8 byte boundaries or whatever. This can cause errors when reading bytes directly into the struct from a file.
2.) You have used glm::vec3 as your typedef for VEC3. If glm::vec3 is not defined as essentially 'struct vec3 { float x, y, z; }' then it will probably be the wrong size and/or alignment and will not read in correctly from the file.
[QUOTE=Nikita;36409038]So I've had this problem with C++0x in gcc:
It had let me assign an initialization list to an array, like so
[code]
double[5] vals;
vals = {-10, 0, 5, 10};[/code]
I had come to rely on this way of assigning values to an array because it's neat to write and I can do it at any time (not just during declaration/initialization).
But now I've updated gcc it's telling me that it's illegal. I.e.
[code]
error: assigning to an array from an initializer list.
[/code]
I has sads now. What should I do?[/QUOTE]
Well first of all its double vals[5]. Second the only way to do that would probably to create a new array and memcpy it over. However I see no real reason to do what you're doing. If its just right after initialization you do it then you should be doing it the proper way anyway. Otherwise you'll be wanting to use pointers instead of plain arrays.
[QUOTE=Chris220;36411705]Well, first off, here's the output of my loader on that same model:
[img]http://i.imgur.com/XUgGk.png[/img]
Now, two things I see immediately suspicious in your code:
1.) You haven't told the compiler to pack your structs as tightly as possible, meaning somethings may get aligned to 8 byte boundaries or whatever. This can cause errors when reading bytes directly into the struct from a file.
2.) You have used glm::vec3 as your typedef for VEC3. If glm::vec3 is not defined as essentially 'struct vec3 { float x, y, z; }' then it will probably be the wrong size and/or alignment and will not read in correctly from the file.[/QUOTE]
I checked that sizeof(glm::vec3), sizeof(float[3]) and sizeof(float x,y,z) are all the same.
How do I pack the structs?
[QUOTE=Richy19;36412187]I checked that sizeof(glm::vec3), sizeof(float[3]) and sizeof(float x,y,z) are all the same.
How do I pack the structs?[/QUOTE]
Depends entirely on the compiler. In MSVC, you want to use:
[cpp]#pragma pack(push, 1)
/* struct definitions go here */
#pragma pack(pop)[/cpp]
You'll have to check your compiler's documentation to see how it's done.
[QUOTE=Chris220;36412242]Depends entirely on the compiler. In MSVC, you want to use:
[cpp]#pragma pack(push, 1)
/* struct definitions go here */
#pragma pack(pop)[/cpp]
You'll have to check your compiler's documentation to see how it's done.[/QUOTE]
Seems to be the same in GCC, I also removed the static float in MD3Vertex but the same is stilll drawn
[QUOTE=Richy19;36412276]Seems to be the same in GCC, I also removed the static float in MD3Vertex but the same is stilll drawn[/QUOTE]
I can't see anything obviously wrong, but here's my code so you can compare and see what's going on:
model.h: [url]http://pastie.org/4120865[/url]
model.cpp: [url]http://pastie.org/4120863[/url]
[editline]20th June 2012[/editline]
And yes, the drawing code is very inefficient; I just whipped it up quickly to make sure it was loading correctly. Rendering is not the idea of this loader class! :P
In my program which just renders a triangle for now I get this error when I try to call glDrawArrays:
Unhandled exception at 0x6928ace0 in SIMPLE PHONG RENDER.exe: 0xC0000005: Access violation reading location 0x00000000.
I have called other GL functions in the program without trouble but this one is strange. Here is the calling code:
[cpp]
do {
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if((laster = glGetError()) != GL_NO_ERROR)
{
return 0xfacedead;
}
glDrawArrays(GL_TRIANGLES, 0, 9);
if((laster = glGetError()) != GL_NO_ERROR)
{
return 0xfacedead;
}
SwapBuffers(wndDC);
}while(msg.message != WM_QUIT);
[/cpp]
I piled as many glGetErrors on as I could so I could attempt to track down the error but they all turn up with no error.
EDITED:
RESOLVED. Don't forget your glVertexAttribPointers kids.
[QUOTE=flayne;36412141]Well first of all its double vals[5]. Second the only way to do that would probably to create a new array and memcpy it over. However I see no real reason to do what you're doing. If its just right after initialization you do it then you should be doing it the proper way anyway. Otherwise you'll be wanting to use pointers instead of plain arrays.[/QUOTE]
But that's the problem, it's not right after initialization.
[cpp]
double vals[5];
vals = {1,2,3,4,5};
doStuff(vals);
vals[3] = 0;
doStuff(vals);
vals = {5,4,3,2,1};
doStuff(vals);
[/cpp]
I don't want to use a vector because it messes up some pointer stuff I'm doing elsewhere.
[QUOTE=Overv;36410269]What you've been doing must have been some unofficial extension then, because even the C++0x standard only allows this with std::vector.
[cpp]std::vector<int> array = { 1, 3, 34, 5, 6 };
array = { 34, 2, 4, 5, 6 };[/cpp][/QUOTE]
I'd really like such an extension to exist. From what I've read it only worked because of a bug in some version of gcc.
How would you do
[cpp]
double *vals = mything->vals; // this is in a distant object, vals is not in scope of this function
vals[3]=vals[2]-vals[1]; // modifying an array element inside a distant object without writing too much
[/cpp]
with vectors?
[QUOTE=Chris220;36412419]I can't see anything obviously wrong, but here's my code so you can compare and see what's going on:
model.h: [url]http://pastie.org/4120865[/url]
model.cpp: [url]http://pastie.org/4120863[/url]
[editline]20th June 2012[/editline]
And yes, the drawing code is very inefficient; I just whipped it up quickly to make sure it was loading correctly. Rendering is not the idea of this loader class! :P[/QUOTE]
My vertex list lists the correct amount for (total triangles * 3), so maybe its just the way im sorting them?
[editline]20th June 2012[/editline]
Nvermind I re-wrote the code for adding the vertex's to the list and it works fine now :D
[QUOTE=Nikita;36416383]But that's the problem, it's not right after initialization.
[cpp]
double vals[5];
vals = {1,2,3,4,5};
doStuff(vals);
vals[3] = 0;
doStuff(vals);
vals = {5,4,3,2,1};
doStuff(vals);
[/cpp]
I don't want to use a vector because it messes up some pointer stuff I'm doing elsewhere.
I'd really like such an extension to exist. From what I've read it only worked because of a bug in some version of gcc.
How would you do
[cpp]
double *vals = mything->vals; // this is in a distant object, vals is not in scope of this function
vals[3]=vals[2]-vals[1]; // modifying an array element inside a distant object without writing too much
[/cpp]
with vectors?[/QUOTE]
You could use pointers. As in make those seperate arrays then have a pointer pointing to the one you want to use. Alternativly you could take my suggestion and memcpy the array over like so:
[cpp]
double vals[2] = { 1, 1}
{ //This indicates the array will be destroyed once it reaches } it is optional.
double newvals[2] = {2, 2};
memcpy(sizeof(newvals), vals, newvals); //Sorry if i put those parameters in the wrong order.
}
[/cpp]
Also you would do this:
vals.at(3) = vals.at(2) - vals.at(1)
considering at() returns a reference not the value.
[quote] NR1.TXT and NR2.TXT both contain natural numbers on a line, separated by spaces. Each file has at most 100 values and the values are strictly ascending. Write a program, without using vectors, that outputs, in ascending order, numbers divisible by 5 that are only present in one of the file.
For example: NR1.TXT contains "1 2 3 4 7 20 60", and NR2.TXT "3 5 7 8 9 10 12 20 24". The program must output 5 10 and 60.[/quote]
What I came up with so far:
[code]#include <iostream>
#include <fstream>
using namespace std;
ifstream f("nr1.txt" );
ifstream g("nr2.txt" );
int main()
{
long a,b;
do{
f>>a;
if(a%5==0)
{
do{
g>>b;
if(b%5==0 && b!=a && b<a)
cout << b << " ";
}while (!g.eof() && a!=b && b<a);
if(a!=b) cout << a << " ";
}
}while (!f.eof());
}[/code]
It works for the example in the exercise but if I put some other values in the text files it either outputs the ones the are in both files or does strange things (for example, for "3 5 9 35 46 55 67 69 71 75" and "5 9 10 13 15 25 45 55 67 70" it outputs 10 15 25 35 70 75). 45 should be there but isn't)
I have a somewhat curious problem.
I have the following code:
[b]main.cpp[/b]
[cpp]
#include <iostream>
#include "App.hpp"
int main(int argc, char **argv) {
std::cout << "hello world!" << std::endl;
return 0;
}
[/cpp]
[b]App.hpp[/b]
[cpp]
#ifndef APP_HPP
#define APP_HPP
#include <vector>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
class App {
public:
App();
~App();
bool OnInit();
bool OnProcessEvents( sf::Event *event );
void OnEvent( sf::Event *event );
void OnLoop();
void OnRender();
void OnCleanup();
bool isRunning();
sf::RenderWindow *getWindow();
void setWindow( sf::RenderWindow *window );
private:
bool Running;
std::vector<sf::RenderWindow*> *windows;
};
#endif /* APP_HPP */
[/cpp]
The program starts, then returns 0 without printing anything. What?
[QUOTE=T3hGamerDK;36422719]I have a somewhat curious problem.
I have the following code:
[b]main.cpp[/b]
[cpp]
#include <iostream>
#include "App.hpp"
int main(int argc, char **argv) {
std::cout << "hello world!" << std::endl;
return 0;
}
[/cpp]
[b]App.hpp[/b]
[cpp]
#ifndef APP_HPP
#define APP_HPP
#include <vector>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
class App {
public:
App();
~App();
bool OnInit();
bool OnProcessEvents( sf::Event *event );
void OnEvent( sf::Event *event );
void OnLoop();
void OnRender();
void OnCleanup();
bool isRunning();
sf::RenderWindow *getWindow();
void setWindow( sf::RenderWindow *window );
private:
bool Running;
std::vector<sf::RenderWindow*> *windows;
};
#endif /* APP_HPP */
[/cpp]
The program starts, then returns 0 without printing anything. What?[/QUOTE]
Try adding std::cin.get() before return 0;
[editline]21st June 2012[/editline]
It might be that it does print, but the program closes directly after. std::cin.get() waits for user input, then continues.
So did anyone ever work with shaders on DirectX? It would be nice if someone could get in touch with me I have serval questions and could require a little help :)
Basically I want to add lighting to my 2D Game/Engine thingy whatsoever but got no actual experience with shaders and reading all up the stuff is unconventional for me as I like examples
In games you often see Borderless Windowed fake fullscreen, and true fullscreen. I can create a fake fullscreen window but how would I create a true fullscreen window?
P.S. Using OpenGL not directX.
This is all you need [url]http://msdn.microsoft.com/en-us/library/windows/desktop/dd183411%28v=vs.85%29.aspx[/url]
[QUOTE=Armandur;36423825]
It might be that it does print, but the program closes directly after. std::cin.get() waits for user input, then continues.[/QUOTE]
That's not possible as std::endl flushes the buffer, but that's the only reason I can think of as well.
[editline]adsf[/editline]
Try adding std::cout << std::flush; ?
[QUOTE=Naelstrom;36426315]That's not possible as std::endl flushes the buffer, but that's the only reason I can think of as well.
[editline]adsf[/editline]
Try adding std::cout << std::flush; ?[/QUOTE]
What about just std::cin.ignore(); std::cin.get(); ?
[QUOTE=Armandur;36431411]What about just std::cin.ignore(); std::cin.get(); ?[/QUOTE]
He's using Linux; he doesn't have to pause the application to see its output.
For my program I need to load from appdata, how do I do this so that it will load from appdata for any user that is using the program?
e.g C:\Users\MyName\AppData\Roaming\Program will only work for someone with the username MyName, so how do i make it work for other users?
(I am attempting to load a html file into the webbrowser in vb.net)
[QUOTE=geoface;36436927]For my program I need to load from appdata, how do I do this so that it will load from appdata for any user that is using the program?
e.g C:\Users\MyName\AppData\Roaming\Program will only work for someone with the username MyName, so how do i make it work for other users?
(I am attempting to load a html file into the webbrowser in vb.net)[/QUOTE]
-SNIP- Sorry that won't work as it will return SYSTEM if it is the default created admin account. Try messing around with environment variables, you may be able to just use "%appdata%/..." as your path though I'm not sure this will work.
*vb.net... :cringe:*
[QUOTE=flayne;36437959]-SNIP- Sorry that won't work as it will return SYSTEM if it is the default created admin account. Try messing around with environment variables, you may be able to just use "%appdata%/..." as your path though I'm not sure this will work.
*vb.net... :cringe:*[/QUOTE]
yeah I know vb.net, but I had to find something that I knew exactly how to load a html, because java was bein a pain in the ass
the whole applet to application conversion just was not going well, so I went for the simplest, easiest solution.
Just curious about this In case I need to use NS.Data Available at some stage.
Say I had a StreamReader attached to a NetworkStream.
NetworkStream.DataAvailable doesn't seem to ever give me a true value despite it having data available.
[csharp]
while (NwStream.DataAvailable == false)
{
//waiting
}
StreamReader.ReadLine();
[/csharp]
I wouldn't actually use a while loop for waiting but you get what I mean?
[QUOTE=Naelstrom;36426315]That's not possible as std::endl flushes the buffer, but that's the only reason I can think of as well.
[editline]adsf[/editline]
Try adding std::cout << std::flush; ?[/QUOTE]
Thanks, I tried that. It works, and now it turned out to be some code in the App.h file with some pretty dumb pointer mishandling, where I passed the wrong type of pointer which caused the program to crash. I wasn't debugging it, so the "return 0" nagged me a bit.
Thanks again!
[QUOTE=geoface;36436927]For my program I need to load from appdata, how do I do this so that it will load from appdata for any user that is using the program?
e.g C:\Users\MyName\AppData\Roaming\Program will only work for someone with the username MyName, so how do i make it work for other users?
(I am attempting to load a html file into the webbrowser in vb.net)[/QUOTE]
Use My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData
So I'm trying to wrap cmd.exe so I can create my own pretty transparent terminal window just like in Linux. Right now I'm trying to figure out how to display its output properly. I have two synchronised TextReaders (StreamReaders) ShellOutput and ShellError. I'm currently doing output simply like this:
[cpp] private static void OutputPrinter()
{
char printedChar;
while (!Shell.HasExited)
{
printedChar = (char)ShellOutput.Read();
if(printedChar != 65535) //Makes sure garbage doesn't get printed just after the process ends.
Console.Write(printedChar);
}
}[/cpp]
The problem is I need to also output the ShellError stream. I can't use things like ReadToEnd() because that deadlocks until cmd exits or ReadLine() because that deadlocks until it finds a '\n'. Even Read() deadlocks until it finds one more character. I was thinking of using a Timer or something like that to time out Read() and assume that it finished reading all current output and then read the error stream and time it out the same way, then loop back to reading ShellOutput but that seems very hacky. Any suggestions?
[QUOTE=DeadKiller987;36440842]So I'm trying to wrap cmd.exe so I can create my own pretty transparent terminal window just like in Linux. Right now I'm trying to figure out how to display its output properly. I have two synchronised TextReaders (StreamReaders) ShellOutput and ShellError. I'm currently doing output simply like this:
[cpp] private static void OutputPrinter()
{
char printedChar;
while (!Shell.HasExited)
{
printedChar = (char)ShellOutput.Read();
if(printedChar != 65535) //Makes sure garbage doesn't get printed just after the process ends.
Console.Write(printedChar);
}
}[/cpp]
The problem is I need to also output the ShellError stream. I can't use things like ReadToEnd() because that deadlocks until cmd exits or ReadLine() because that deadlocks until it finds a '\n'. Even Read() deadlocks until it finds one more character. I was thinking of using a Timer or something like that to time out Read() and assume that it finished reading all current output and then read the error stream and time it out the same way, then loop back to reading ShellOutput but that seems very hacky. Any suggestions?[/QUOTE]
Yes I'm pretty sure that's what you have to do. I used WaitForSingleObject to wait for input, and then interpreted the input manually. WaitForSingleObject returns if you even start typing in the console so if I didn't interpret the input manually: the thread would hang till the user pressed enter.
For ShellError, WaitForSingleObject is probably all you need.
You can look how I did it here:
[url]https://github.com/naelstrof/Astrostruct/blob/master/src/NConsole.cpp[/url]
It's quite the spaghetti code, but it does mostly what you explained. Feel free to ask me questions on steam.
Has anyone here used Mini-XML? I'm trying to load a pretty simple XML file and then set attributes to a class from it but I keep getting memory errors and I am not sure what's going on:
[cpp]
#include "XMLParser.h"
FILE* XMLParser::mFile;
mxml_node_t* XMLParser::mTree;
ModelData XMLParser::CurrentModel;
void XMLParser::LoadFile(const char* path)
{
mFile = std::fopen(path, "r");
mTree = mxmlLoadFile(NULL, mFile, LoadCallBack);
fclose(mFile);
mxml_node_t* next_node = mTree;
while (next_node != NULL)
{
std::string type(mxmlGetElement(next_node));
std::cout << type << "\n";
next_node = mxmlWalkNext(next_node, mTree, MXML_DESCEND);
}
std::cout << "Finished Loading Model:" << "\n";
std::cout << "Texture Path: " << CurrentModel.mTexturePath << "\n";
std::cout << "Density: " << CurrentModel.mDensity << "\n";
std::cout << "Vertex Count: " << CurrentModel.mVertexCount << "\n";
}
mxml_type_t XMLParser::LoadCallBack(mxml_node_t *node)
{
std::string type(mxmlGetElement(node));
//Troll Code
//std::cout << ":" << type << ":\n";
if (type == "texture")
{
return MXML_TEXT;
}
else if (type == "density")
{
return MXML_REAL;
}
else if (type == "vertex")
{
return MXML_TEXT;
}
return MXML_TEXT;
}
/*
<model>
<physics_hull>
<texture>images/crate</texture>
<density>4</density>
<vertex_count>4</vertex_count>
<vertices>
<vertex>50 50</vertex>
<vertex>-50 50</vertex>
<vertex>-50 -50</vertex>
<vertex>50 -50</vertex>
</vertices>
</physics_hull>
</model>
[/cpp]
At the bottom is the XML file I am trying to parse. The program crashes when trying to access mxmlGetElement(node) I'm not really sure how to use this library to be honest the documentation is pretty sparse.
Sorry, you need to Log In to post a reply to this thread.