snip
some fucker on Google suggested casting a pointer to an array to your desired datatype and I fell for it, needless to say that's what the problem was
[QUOTE=Number-41;44650097]snip
some fucker on Google suggested casting a pointer to an array to your desired datatype and I fell for it, needless to say that's what the problem was[/QUOTE]
Well, technically you can do that depending on the circumstances (if the array contains pointers I think).
Works in C# too, since arrays are covariant there. You can also make array unions if you create it as the array of the smaller struct type (since they length-check), but that's not really recommended :v:
[editline]26th April 2014[/editline]
Unless you mean casting to a non-pointer value in C++, then it's clear what the issue is...
So I got a job working for a mobile app agency and they want to put me on an iOS project so I can learn native iOS dev and Objective-C. Any tips?
I'm not really that experienced as a coder but I've used a bit of Java (desktop and a bit of Android) and a bit of C# with Unity3D and some VB .NET back in uni. I'm fairly comfortable with OO concepts but there are still some basic concepts that throw me sometimes and I was honest about this at the interview but they seemed to think I had potential (after looking at some of my previous code) and were willing to allow time for me to get up to speed. I figure I'm gonna have to put some time in outside of working hours initially to get things moving.
How do I do real time rendering of screens? For instance drawing the mini map from Dota in real time?
I'm using a leap motion device to recognise gestures and carry out an action. In order to diferentiate between gestures I attempted to add a system timer, the interval is set correctly but the timer won't start after trying both timer.enabled = true and timer.start().
The code below is the method using the timer, the timer is declared elsewhere (Timer timer = new Timer()).
[code]
public override void OnFrame(Controller controller)
{
Frame frame = controller.Frame();
icon.Popup(timer.Interval.ToString());
if (!frame.Fingers.IsEmpty && timer.Interval <= 100)
{
foreach (Gesture gest in frame.Gestures())
{
if (!gest.IsValid)
continue;
switch (gest.Type)
{
case Gesture.GestureType.TYPESWIPE:
SwipeGesture swipeGesture = new SwipeGesture(gest);
if (swipeGesture.Direction.x > 0)
iTunesObj.nextTrack();
else if (swipeGesture.Direction.x < 0)
iTunesObj.prevTrack();
break;
}
timer.Interval = 2000;
timer.Start();
}
}
}
[/code]
snip- it fixed itself
Whenever i instantiate this class i get a stack overflow. I must be doing something stupid but i can't figure it out.
[code]
// header
#pragma once
#include "Pixel.h"
class Image
{
public:
static const int H = 900;
static const int W = 1600;
static const int LENGTH = H * W;
Image();
void setID(int id);
void setName(char* path);
void setPixel(int y, int x, Pixel pix, bool idx);
Pixel getPixel(int y, int x);
char* getName();
int getID();
void swapPixels(int y1, int x1, int y2, int x2);
private:
int id;
char* name;
Pixel pixels[H][W];
};
// cpp
#include "Image.h"
Image::Image()
{
/*for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
pixels[i][j] = Pixel();
}
}*/
}
void Image::setName(char* path)
{
name = path;
}
void Image::setID(int id)
{
id = id;
}
void Image::setPixel(int y, int x, Pixel pix, bool idx)
{
pixels[y][x].copy(pix, idx);
}
void Image::swapPixels(int y, int x, int y2, int x2)
{
Pixel temp;
temp.copy(pixels[y][x], false);
pixels[y][x].copy(pixels[y2][x2], false);
pixels[y2][x2].copy(temp, false);
}
Pixel Image::getPixel(int y, int x)
{
return pixels[y][x];
}
char* Image::getName()
{
return name;
}
int Image::getID()
{
return id;
}[/code]
the pixel class works fine, i can instantiate them without a problem.
[QUOTE=twoski;44660323]Whenever i instantiate this class i get a stack overflow. I must be doing something stupid but i can't figure it out.
...
the pixel class works fine, i can instantiate them without a problem.[/QUOTE]
Assuming sizeof(Pixel) == 4, one instance of Image would be ~5.5MiB. I guess you are just pumping the stack with too much data. Instantiate the Pixel array on the heap instead.
I'm playing around with an RGB LED using Arduino, and my goal is to get a smooth rainbow effect with it. So far I got this going on it.
[code]
if(digitalRead(button) == LOW){
analogWrite(red, 255*((sin(i/30)+1)/2)); // 30 time division is to create a smooth transition.
delay(DT);
analogWrite(green, 255*((sin((i+40*pi)/30)+1)/2));
delay(DT);
analogWrite(blue, 255*((sin((i+80*pi)/30)+1)/2));
delay(DT);
i++;
}
[/code]
graph :
[t]http://i.imgur.com/EZM6jFt.png[/t]
it works quite well, but I'd like the primary colours (RGB) to be stronger than they are now when either of them is at their maximum, as they get mixed in with the other two still.
In what way would I have to adjust the formula/program?
[QUOTE=scratch (nl);44661018]I'm playing around with an RGB LED using Arduino, and my goal is to get a smooth rainbow effect with it. So far I got this going on it.
[code]
if(digitalRead(button) == LOW){
analogWrite(red, 255*((sin(i/30)+1)/2)); // 30 time division is to create a smooth transition.
delay(DT);
analogWrite(green, 255*((sin((i+40*pi)/30)+1)/2));
delay(DT);
analogWrite(blue, 255*((sin((i+80*pi)/30)+1)/2));
delay(DT);
i++;
}
[/code]
graph :
[t]http://i.imgur.com/EZM6jFt.png[/t]
it works quite well, but I'd like the primary colours (RGB) to be stronger than they are now when either of them is at their maximum, as they get mixed in with the other two still.
In what way would I have to adjust the formula/program?[/QUOTE]
Use HSB instead of RGB, it's a lot easier to work with in this case.
Is there any free small sound recording software? Really just need to record and crop is all.
[QUOTE=Jitterz;44661253]Is there any free small sound recording software? Really just need to record and crop is all.[/QUOTE]
Audacity
[QUOTE=robmaister12;44661204]Use HSB instead of RGB, it's a lot easier to work with in this case.[/QUOTE]
Thank you! after a little bit of searching I found [URL="http://www.kasperkamperman.com/blog/arduino/arduino-programming-hsb-to-rgb/"]this article[/URL] and cut out all the stuff I didn't need (as I only care about the hue atm, and some stuff didn't seem to affect a whole lot). Now I got my fancy rainbow :D
[QUOTE=scratch (nl);44661795]Thank you! after a little bit of searching I found [URL="http://www.kasperkamperman.com/blog/arduino/arduino-programming-hsb-to-rgb/"]this article[/URL] and cut out all the stuff I didn't need (as I only care about the hue atm, and some stuff didn't seem to affect a whole lot). Now I got my fancy rainbow :D[/QUOTE]
I also only care about HUE
[sp]sorry[/sp]
Someone knows a good Speech-Recognition Library for .NET?
The built in isn't that good...If you speak a word clearly, it will not recognize it. If you speak it totaly fucked up and with wrong pronunciation, it will recognize it :v:
Anybody mind helping me understand how to implement the LZW algorithm to create an encoder? I need to do it in Java for a project, and it takes a file and outputs the encoded one.
[url]http://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch[/url] Link to the algorithm
Not really sure how to start it
[QUOTE=johnnyaka;44667444]Someone knows a good Speech-Recognition Library for .NET?
The built in isn't that good...If you speak a word clearly, it will not recognize it. If you speak it totaly fucked up and with wrong pronunciation, it will recognize it :v:[/QUOTE]
If the build in .NET one is the Windows one, then it's gonna be shit :v: I don't know if Google does an API for theirs, and the only other voice API I know of is Dragon but I think theirs costs
How come some code I have runs significantly slower in browser than in Node.js? over 10 times slower, taking ~74 seconds compared to nodes ~6 seconds
I have an assignment due next week and I'm way fucking behind and I need some help. The assignment is as follows:
[quote]The steps you must follow are:
1. Write a smooth shaded polygon drawing routine that you can pass the coordinate values of
the vertices and the color at each vertex.
2. Render the 3D polygon, do clipping and draw the result to the screen.
[B]3. Perform visible surface detection (backface culling and z-buffering). [/B]
[B]4. Apply 3D transformation to animate each object, i.e. 3D translation, 3D rotation, 3D
scaling. [/B]
[B]5. Apply a projection transformation to project each object to the correct location on the 2D
screen. [/B]
6. Make sure the polygon creation and destruction code is handled correctly without memory
leak.
7. The program should give the user feedback after some interaction. It could be visual
changes, or playing a sound.
To get the marks below, your functions should be implemented in C++, NO OpenGL
method should be used in this assignment.
The marking scheme will be as follows:
Polygon rendering function 15 marks
Polygon clipping 15 marks
[B]3D Polygon animation 15 marks
3D projection transform 15 marks
Visible surface detection 15 marks [/B]
Game interaction and feedback 10 marks
Documentation 15 marks[/quote]
I've bolded the parts I need help with. We were learning all these things from weekly labs but they only gave you the theory behind it all and I don't understand the implementation in C++. For starters I have to set up transformation matrices, I've done the identity matrix and I don't understand what I put for the rest of them. I know the theory behind them and what the matrices look like but I don't understand how to program them.
For example, here is my identity matrix and the empty translation matrix which I don't know how to do:
[code]Mat4::Mat4()
{
//fill the Mat4.data with an identity matrix
float data[] = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
}
Mat4 Mat4::translate(float x, float y, float z)
{
Mat4 tmp;
// ???
return tmp;
}[/code]
I don't want some one to do it for me, I just need some information to get me going.
Translation matrices are fairly easy, but projection matrices are annoying. Look up "perspective projection" and you'll get some info. Personally I just use the GLM functions so I never looked into it very much.
You'll need to figure out the matrices before you do backface culling and z-buffering, because both of those techniques require screen coords.
Backface culling in OpenGL is done by vertex winding for each triangle. Basically for each triangle, you provide the vertices in counter-clockwise order. Then, when they are moved to screen coords by the appropriate matrices, if they are still CCW, the GPU renders them. If not, it throws them out because the only way for something to be clockwise is if it is backwards relative to the camera.
Depth buffering is incredibly simple. As part of your transformation to screen coords, you store the depth, which is the "z" part of screen coords. For each pixel, in addition to the the color, you store the depth component. Then, if anything has a lower depth, you toss the old info and put in the new pixel because anything with a lower depth is closer to the camera.
Also, 3D polygon animation could be done just by making your cube or whatever rotate, which is easily done with a matrix.
Thanks could you provide some information for transformation matrices? I figured it would all be pretty easy because it all makes sense in my head, I just don't know how to make it work in the program.
for translation would this work?
[code]Mat4 Mat4::translate(float x, float y, float z)
{
Mat4 tmp;
tmp.data[0] += x;
tmp.data[1] += x;
tmp.data[2] += x;
tmp.data[3] += x;
tmp.data[4] += y;
// etc...
tmp.data[8] += z;
// etc...
return tmp;
}[/code]
[QUOTE=djjkxbox360;44670549]If the build in .NET one is the Windows one, then it's gonna be shit :v: I don't know if Google does an API for theirs, and the only other voice API I know of is Dragon but I think theirs costs[/QUOTE]
Yep, thats the one built into .NET :/
Yea i've heard of Dragon Natural Speaking, but it's kinda expensive for my project :P
[QUOTE=Pat.Lithium;44674982]Thanks could you provide some information for transformation matrices? I figured it would all be pretty easy because it all makes sense in my head, I just don't know how to make it work in the program.
for translation would this work?
[code]Mat4 Mat4::translate(float x, float y, float z)
{
Mat4 tmp;
tmp.data[0] += x;
tmp.data[1] += x;
tmp.data[2] += x;
tmp.data[3] += x;
tmp.data[4] += y;
// etc...
tmp.data[8] += z;
// etc...
return tmp;
}[/code][/QUOTE]
This should help you for sure:
[URL="http://blog.db-in.com/cameras-on-opengl-es-2-x/"]http://blog.db-in.com/cameras-on-opengl-es-2-x/[/URL]
To make it short:
index 3 = x
index 7 = y
index 11 = z
or
index 12 = x
index 13 = y
index 14 = z
Depends on how you store your array for the matrix, row-major or column-major order...
[QUOTE=Pappschachtel;44675794]This should help you for sure:
[URL="http://blog.db-in.com/cameras-on-opengl-es-2-x/"]http://blog.db-in.com/cameras-on-opengl-es-2-x/[/URL]
To make it short:
index 3 = x
index 7 = y
index 11 = z
or
index 12 = x
index 13 = y
index 14 = z
Depends on how you store your array for the matrix, row-major or column-major order...[/QUOTE]
I had a feeling it was like that, thanks.
[QUOTE=Pat.Lithium;44676320]I had a feeling it was like that, thanks.[/QUOTE]
additionally... do not forget the 1s of the identity matrix in your translation matrix!
[QUOTE=Pappschachtel;44676344]additionally... do not forget the 1s of the identity matrix in your translation matrix![/QUOTE]
The Mat4 class is defined with it's data array set to an identity matrix. A new instance is created and returned in the functions. Do these look correct?
[code]Mat4::Mat4()
{
//fill the Mat4.data with an identity matrix
float data[] = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
}
Mat4 Mat4::translate(float x, float y, float z)
{
Mat4 tmp;
tmp.data[3] = x;
tmp.data[7] = y;
tmp.data[11] = z;
return tmp;
}
Mat4 Mat4::rotateX(float degrees)
{
Mat4 tmp;
float rad = degrees * _pi180;
tmp.data[5] = cos(rad);
tmp.data[6] = sin(rad);
tmp.data[9] = -tmp.data[6];
tmp.data[10] = tmp.data[5];
return tmp;
}
Mat4 Mat4::rotateY(float degrees)
{
Mat4 tmp;
float rad = degrees * _pi180;
tmp.data[0] = cos(rad);
tmp.data[2] = -sin(rad);
tmp.data[8] = -tmp.data[2];
tmp.data[10] = tmp.data[0];
return tmp;
}
Mat4 Mat4::rotateZ(float degrees)
{
Mat4 tmp;
float rad = degrees * _pi180;
tmp.data[0] = cos(rad);
tmp.data[1] = -sin(rad);
tmp.data[4] = -tmp.data[1];
tmp.data[5] = tmp.data[0];
return tmp;
}
Mat4 Mat4::scale(float x, float y, float z)
{
Mat4 tmp;
tmp.data[0] = x;
tmp.data[5] = y;
tmp.data[10] = z;
return tmp;
}[/code]
To my understanding I need a function to add 2 matrices together and one to multiply them as well.
[QUOTE=johnnyaka;44667444]Someone knows a good Speech-Recognition Library for .NET?
The built in isn't that good...If you speak a word clearly, it will not recognize it. If you speak it totaly fucked up and with wrong pronunciation, it will recognize it :v:[/QUOTE]
A quick google brought up [url]https://github.com/gillesdemey/google-speech-v2[/url]
[CODE]#Encounter Outcome Program #Python
import random #imports the random function, allows randomisation of given values
def CharAttr():
CharName1 = input("What is your first character's name?\n")
CharStr1 = int(input("How powerful is your character, on a scale of 1-100?\n"))
if CharStr1 > 100:
print("Invalid Input.")
CharAttr()
elif CharStr1 < 1:
print("Invalid Input.")
CharAttr()
CharSkl1 = int(input("How skillful is your character, on a scale of 1-100?\n"))
if CharSkl1 > 100:
print("Invalid Input.")
CharAttr()
elif CharSkl1 < 1:
print("Invalid Input.")
CharAttr()
CharName2 = input("What is your second character's name?\n")
CharStr2 = int(input("How powerful is your character, on a scale of 1-100?\n"))
if CharStr2 > 100:
print("Invalid Input.")
CharAttr()
elif CharStr2 < 1:
print("Invalid Input.")
CharAttr()
CharSkl2 = int(input("How skillful is your character, on a scale of 1-100?\n"))
if CharSkl2 > 100:
print("Invalid Input.")
CharAttr()
elif CharSkl2 < 1:
print("Invalid Input.")
CharAttr()
StrengthMod = abs(CharStr1 - CharStr2)//5
SkillMod = abs(CharSkl1 - CharSkl2)//5
CharDice1 = random.randint(1, 6) #dice
CharDice2 = random.randint(1, 6) #rolls
if CharDice1 > CharDice2: #first character wins
CharStr1 = CharStr1 + StrengthMod
CharSkl1 = CharSkl1 + SkillMod
CharStr2 = CharStr2 - StrengthMod
CharSkl2 = CharSkl2 - SkillMod
elif CharDice1 < CharDice2: #second character wins
CharStr1 = CharStr1 - StrengthMod
CharSkl1 = CharSkl1 - SkillMod
CharStr2 = CharStr2 + StrengthMod
CharSkl2 = CharSkl2 + SkillMod
else:
print("The Characters were too evenly matched, therefore no encounter occurred!")
exit(0) #exits if draw occurs
if CharSkl1 < 1:
CharSkl1 = 0
elif CharSkl2 < 1:
CharSkl2 = 0
if CharStr1 < 1:
print(CharName1, "is now dead")
elif CharStr2 < 1:
print(CharName2, "is now dead")
if CharStr1 and CharStr2 and CharSkl1 and CharSkl2 > 0:
print(CharName1, "ended the fight with a Strength of", CharStr1, "and a Skill of", CharSkl1)
print(CharName2, "ended the fight with a Strength of", CharStr2, "and a Skill of", CharSkl2)
if CharStr1 and CharSkl1 > CharStr2 and CharSkl2:
print(CharName1, "won!\n")
print("The program has now finished")
exit(0)
elif CharStr2 and CharSkl2 > CharStr1 and CharSkl1:
print(CharName2, "won!\n")
print("The program has now finished")
exit(0)
else:
print("The program has now finished")
exit(0)[/CODE]
any idea why I'm getting this traceback error?
[THUMB]http://i.imgur.com/TyPr3IN.png[/THUMB]
I imagine it's a scope issue, I think you need to initialise CharStr1 in the top of the file, something like
[code]
CharStr1 = 0
def CharAttr():
CharName1 = input("What is your first character's name?\n")
CharStr1 = int(input("How powerful is your character, on a scale of 1-100?\n"))
[/code]
[QUOTE=Pat.Lithium;44676497]The Mat4 class is defined with it's data array set to an identity matrix. A new instance is created and returned in the functions. Do these look correct?
[code]Mat4::Mat4()
{
//fill the Mat4.data with an identity matrix
float data[] = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
}
Mat4 Mat4::translate(float x, float y, float z)
{
Mat4 tmp;
tmp.data[3] = x;
tmp.data[7] = y;
tmp.data[11] = z;
return tmp;
}
Mat4 Mat4::rotateX(float degrees)
{
Mat4 tmp;
float rad = degrees * _pi180;
tmp.data[5] = cos(rad);
tmp.data[6] = sin(rad);
tmp.data[9] = -tmp.data[6];
tmp.data[10] = tmp.data[5];
return tmp;
}
Mat4 Mat4::rotateY(float degrees)
{
Mat4 tmp;
float rad = degrees * _pi180;
tmp.data[0] = cos(rad);
tmp.data[2] = -sin(rad);
tmp.data[8] = -tmp.data[2];
tmp.data[10] = tmp.data[0];
return tmp;
}
Mat4 Mat4::rotateZ(float degrees)
{
Mat4 tmp;
float rad = degrees * _pi180;
tmp.data[0] = cos(rad);
tmp.data[1] = -sin(rad);
tmp.data[4] = -tmp.data[1];
tmp.data[5] = tmp.data[0];
return tmp;
}
Mat4 Mat4::scale(float x, float y, float z)
{
Mat4 tmp;
tmp.data[0] = x;
tmp.data[5] = y;
tmp.data[10] = z;
return tmp;
}[/code]
To my understanding I need a function to add 2 matrices together and one to multiply them as well.[/QUOTE]
seems ok i think, i didn't checked it all :)
the difference between row-major and column-major order is just transposing the matrix.
addition is not that important, but multiplication is.
Sorry, you need to Log In to post a reply to this thread.