Has anyone here seen an issue such as this whilst trying to implement a skybox/cubemap ?
[URL="https://www.dropbox.com/s/ct5dm641xld8923/2014-02-05%2022-16-49-71.avi"]https://www.dropbox.com/s/ct5dm641xld8923/2014-02-05%2022-16-49-71.avi[/URL]
I think my calculations of the matrices are off when I'm moving the camera, but cant be sure as I'm quite the noob with this stuff :/
Hey im having problems re-directing stdin/stdout, running Ubuntu 12
my command prompt
[code]
william@MiNi-BuLl3t:~/r/A2$ ./vcftool -sort < test | ./vcftool -info < test //THIS WORKS!!!
9 cards (not sorted)
8 with photos
9 with URLs
9 with geographic locations
9 in canonical form
william@MiNi-BuLl3t:~/r/A2$ ./vcftool -sort < test | ./vcftool -info //THIS DOESN'T WORK :(
0 cards (not sorted)
0 with photos
0 with URLs
0 with geographic locations
0 in canonical form
[/code]
my main:
[code]int main(int argc, char*argv[]){
VcFile filep;
VcStatus currentStatus;
currentStatus.code=OK;
if(strcmp(argv[1],"-info")==0){
currentStatus=readVcFile(stdin,&filep);//read the file, populate the struct
currentStatus.code=vcfInfo(stdout,&filep);//output info about the struct
}else if(strcmp(argv[1],"-canon")==0){
}else if(strcmp(argv[1],"-select")==0){
}else if(strcmp(argv[1],"-sort")==0){
currentStatus=readVcFile(stdin,&filep); //read the file, populate struct
currentStatus.code=vcfSort(&filep); //sort it
writeVcFile(stdout,&filep); //write it to stdout
}
return 0;
}[/code]
-snip-
Operator overloading has been killing me in my Comp. Sci. class recently. We're just now leaving it but our exam still covers the content and I am in no way prepared for that. Here's some code I just finished writing for one of my HW's to give you guys an idea of where we are at:
[code]// -snip-
// -snip-
// Lab 07
#include <lab07.h>
Rational Rational::operator+(const Rational& addend) const
{
int lcm = Rational::lcm(this->getDenominator(), addend.getDenominator());
Rational sum;
sum.setNumerator(lcm * this->getNumerator() / this->getDenominator()+
lcm * addend.getNumerator() / addend.getDenominator());
sum.setDenominator(lcm);
sum.reduce();
return sum;
}
Rational Rational::operator-() const
{
return Rational(-getNumerator(), getDenominator());
}
Rational Rational::operator-(const Rational& subtrahend) const
{
//return this->add(subtrahend.additiveInverse());
return *this + -subtrahend;
}
bool Rational::operator==(const Rational& rhs) const
{
return (*this - rhs).getNumerator() == 0;
}
bool Rational::operator!=(const Rational& rhs) const
{
return !(*this == rhs);
}
Rational& Rational::operator=(const Rational& rhs)
{
if (this != &rhs)
{
this->setNumerator(rhs.getNumerator());
this->setDenominator(rhs.getDenominator());
} else { }
}
bool Rational::operator<(const Rational& rhs) const
{
return (*this - rhs).getNumerator() < 0 && *this != rhs;
}
bool Rational::operator<=(const Rational& rhs) const
{
return !(*this > rhs);
}
bool Rational::operator>(const Rational& rhs) const
{
return rhs < *this;
}
bool Rational::operator>=(const Rational& rhs) const
{
return !(*this < rhs);
}
Rational Rational::operator*(const Rational& multiplicand) const
{
Rational rat;
rat.setNumerator(getNumerator() * multiplicand.getNumerator());
rat.setDenominator(getDenominator() * multiplicand.getDenominator());
rat.reduce();
return rat;
}
Rational Rational::operator/(const Rational& divisor) const
{
// return this->multiply(divisor.multiplicativeInverse());
Rational rat;
rat.setDenominator(getDenominator() * divisor.getNumerator());
rat.setNumerator(getNumerator() * divisor.getDenominator());
rat.reduce();
return rat;
}
istream& operator>>(istream& is, Rational& rat)
{
int numerator, denominator;
is >> numerator;
is >> denominator;
rat.setNumerator(numerator);
rat.setDenominator(denominator);
return is;
}
ostream& operator<<(ostream& out, const Rational& rat)
{
out << rat.getNumerator() << "/" << rat.getDenominator();
return out;
}
[/code]
Anyway, this stuff is blowing my mind. The precursor to this class was a breeze, but this one's difficulty escalated significantly. Was wondering if you guys could give some more indepth explanations on "friend" operators vs. member operators, and some general explanation on operator overloading (this is [b]C++[/b]).
And ignore the "this->"s, I was using them to help me visualize what I was doing.
I hate to ask for so much help but F# is hard to find help for.
I'm still pretty bad at F# and functional design so this is fairly imperative, It's basically a json parser but for strings only.
[code]
namespace SimpleRon
open System;
open System.Collections;
type internal valtype =
| value = 1
| name = 2
[<Sealed>]
type Ron() =
static let list = new ArrayList()
static let mutable value = ""
static let mutable name = ""
static let mutable state = valtype.name
static let start =
value <- ""
name <- ""
state <- valtype.name
static let writeChar (c:char) =
match state with
| valtype.name -> name <- name + c.ToString()
| valtype.value -> value <- value + c.ToString()
| _ -> ()
static let writeValue =
Console.WriteLine(name+":"+value)
let tup =
(name, value)
match tup with
|(a,b) -> Console.WriteLine(a+":"+b)
list.Add(tup) |> ignore
()
static let parse (str:string) =
str
|> Seq.filter (fun x -> Char.IsWhiteSpace(x) <> true) |> ignore
for c in str do
match c with
|'{' -> start
|'}' -> writeValue
|':' -> state <- valtype.value
|',' -> ()
|'[' -> ()
|']' -> ()
|_ -> writeChar c
list
static member Parse (s:string) =
parse s
[/code]
Test
[code]
module Testfs
open SimpleRon
open System.Collections;
open System;
[<EntryPoint>]
let main args =
let str = "{name:value}"
let al = Ron.Parse str
Console.WriteLine( (al.[0].ToString()) )
Console.Read() |> ignore
0
[/code]
writeValue is being called before the pattern match in parse even starts. I have no idea why? It's probably something obvious.
[QUOTE=WitheredGryphon;43819820]Operator overloading has been killing me in my Comp. Sci. class recently. We're just now leaving it but our exam still covers the content and I am in no way prepared for that.
[...]
Anyway, this stuff is blowing my mind. The precursor to this class was a breeze, but this one's difficulty escalated significantly. Was wondering if you guys could give some more indepth explanations on "friend" operators vs. member operators, and some general explanation on operator overloading (this is [b]C++[/b]).
And ignore the "this->"s, I was using them to help me visualize what I was doing.[/QUOTE]
You overload operators to provide custom behaviour for a user-defined type when applying said operators to instances of it.
For a class Foo with instances foo1 and foo2, this:[cpp]foo1 + foo2[/cpp]is just syntactic sugar for this:[cpp]foo1.operator+(foo2)[/cpp]Both work equally, but the former is far more readable. So what happens is the method operator+() is called on the left-hand operand and the right-hand operand is passed as an argument.
You need to define an operator as a non-member function if you don't have access to the lhs type's implementation:[cpp]ostream& operator<<(std::ostream& lhs, const Rational& rhs); // You don't have access to std::ostream but want to call std::cout << rat
Rational operator+(int lhs, const Rational& rhs); // You cannot overload operators for int, but you want to call 3 + rat;[/cpp]Those global operators should only be "friend" if they need access to private members.
Operators return either a new value or a reference to the operand to allow chaining:[cpp]std::cout << a << b << c;[/cpp]Is the same as[cpp]std::cout.operator<<(a).operator<<(b).operator<<(c);[/cpp]
[QUOTE=reevezy67;43820137]I hate to ask for so much help but F# is hard to find help for.[/QUOTE]
There seem to be almost no tutorials and so on, even the official language reference relies on previous .NET knowledge.
[QUOTE]I'm still pretty bad at F# and functional design so this is fairly imperative, It's basically a json parser but for strings only.
[code]
writeValue is being called before the pattern match in parse even starts. I have no idea why? It's probably something obvious.[/QUOTE]
writeValue isn't a function because it doesn't have a pattern match. Add [I]()[/I] to its definition and the call site.
Why are you ignoring so many things? The [I]Seq.filter[/I] at the start of [I]parse[/I] is effectively a [I]nop[/I] because of that. If you just want to remove it, you can comment/uncomment the current or selected line(s) with ctrl+k,c/ctrl+k,u, respectively.
Don't use [I]ArrayList[/I]. It's a pretty much deprecated, non-generic .NET collection that is a holdover from when [I]List<_>[/I] didn't exist.
[I]List<_>.Add[/I] also returns [I]void[/I]/a [I]unit[/I], so you don't need to ignore anything.
Another quick-replace option would be to use F# [I]list[/I]s in a mutable field. Appending values to them is slow, but you can quickly prepend things quickly like this:
[code]let mutable someList = []
someList <- item :: someList[/code]
You should rename your list, as it's currently hiding the type shortcut [I]'a list[/I].
You could try changing your parser into a [I]Seq<_>[/I]/[I]IEnumerable<_>[/I] method, using a [I]seq { ... }[/I] sequence expression.
It behaves exactly like C# iterators, so you can just return values with [I]yield[/I].
You should turn the static let bindings into instance members, currently you're basically using mutable globals.
If you want to make a quick functional parser, you may actually want to have a look at [url=https://github.com/sprache/Sprache]Sprache[/url].
It has the right patterns if you want to copy it, but I'm fairly sure it's also fully compatible with query expressions (which are F#'s equivalent of LINQ comprehension syntax).
Wow thanks, To be honest I'm just learning it by using and looking up references on msdn it so I missed a lot of stuff. If it had better documentation I would have read those instead of jumping right in to it.
[editline]8th February 2014[/editline]
Also the static let bindings aren't global because they are inside the type definition. I want it to be a static class. Hence why it is sealed.
Fixed version if anyone cares/googles. [url]http://pastebin.com/x7yc1fBM[/url]
[QUOTE=reevezy67;43822760]Also the static let bindings aren't global because they are inside the type definition. I want it to be a static class. Hence why it is sealed.
Fixed version if anyone cares/googles. [url]http://pastebin.com/x7yc1fBM[/url][/QUOTE]
No, but they behave like that since they stay around even after your method returns.
You really should put them as variables into the [I]parse[/I] function so they are discarded afterwards and no persistent mutable state exists.
Since your other let bindings are all very small and only used once in [I]parse[/I], it might actually not hurt to just move them into the pattern match cases with a comment.
If you want to keep them, it would be cleaner to use mutable/reference parameters (with the type shortcut [I]'a byref[/I], non-partial application shouldn't touch the heap).
You can then pass your variables with [I]&[/I] prefix like in C++.
Good point, I'll do that.
[QUOTE=reevezy67;43823383]Good point, I'll do that.[/QUOTE]
Another thing I forgot to add before: You can consolidate multiple pattern matches with |, so instead of
[code]
|',' -> ()
|'[' -> ()
|']' -> ()
|'"' -> ()
|''' -> ()
[/code] you can write [code]
|',' |'[' |']' |'"' |''' -> ()
[/code]
(Also, the default match looks less indented than the rest.)
Ok so I got docked points because this:
[CODE]return !(*this > rhs);[/CODE]
should've been this:
[CODE]return *this < rhs || *this == rhs;[/CODE]
I could have sworn those two were the exact same statements but maybe I'm missing something?
[QUOTE=WitheredGryphon;43824373]Ok so I got docked points because this:
[CODE]return !(*this > rhs);[/CODE]
should've been this:
[CODE]return *this < rhs || *this == rhs;[/CODE]
I could have sworn those two were the exact same statements but maybe I'm missing something?[/QUOTE]
Assuming correct implementation of the comparisons, yes.
The first option seems better too, as it might avoid branching (depending on whether negation is a CPU instruction, which I don't know).
[editline]7th February 2014[/editline]
There is one, but it's the same as bitwise not.
It's definitely fine as long as no-one tries to do boolean logic with arithmetic operators though.
[QUOTE=Tamschi;43826103]Assuming correct implementation of the comparisons, yes.
The first option seems better too, as it might avoid branching (depending on whether negation is a CPU instruction, which I don't know).
[editline]7th February 2014[/editline]
There is one, but it's the same as bitwise not.
It's definitely fine as long as no-one tries to do boolean logic with arithmetic operators though.[/QUOTE]
Apparently we had to assume we never made the previous functions in our class (in that particular assignment) and were only allowed to make our operators using "<" and "==". Frustrating because I also agree that my solutions looked a lot better than the second one (which I thought I wouldn't use just because I could do the first solution).
Whatever though.
[QUOTE=WitheredGryphon;43824373]Ok so I got docked points because this:
[CODE]return !(*this > rhs);[/CODE]
should've been this:
[CODE]return *this < rhs || *this == rhs;[/CODE]
I could have sworn those two were the exact same statements but maybe I'm missing something?[/QUOTE]
I've actually run into a similar situation in a C-like language where they weren't equivalent.
I was doing something like
[code]float a, b;
...
if (a == b || a > b)
...
else
...[/code]
I had trapped the code so it'd catch floating-point errors like NaN comparisons. However the NaNs still kept passing through. Turns out the == was doing a bitwise comparison, forgoing all floating-point checks, and shortcutting the if-clause when a or b were NaN.
Not exactly relevant, but I just thought I'd share.
[QUOTE=ThePuska;43828290]I've actually run into a similar situation in a C-like language where they weren't equivalent.
I was doing something like
[code]float a, b;
...
if (a == b || a > b)
...
else
...[/code]
I had trapped the code so it'd catch floating-point errors like NaN comparisons. However the NaNs still kept passing through. Turns out the == was doing a bitwise comparison, forgoing all floating-point checks, and shortcutting the if-clause when a or b were NaN.
Not exactly relevant, but I just thought I'd share.[/QUOTE]
Huh I don't think I've come across that type of situation before. I tried both of the comparison types and they worked equally as well but I'm sure some weird backdoor stuff happened in your case.
Haven't really messed with floats too much yet this semester, we've been mainly sticking to ints and objects.
How do I use spritesheets in LOVE?
I have this image:
[img]https://dl.dropboxusercontent.com/u/14273442/set_0.gif[/img]
I need to extract 3 particular 16x16 tiles. Can I do it without cutting the image?
[QUOTE=MuffinZerg;43836267]How do I use spritesheets in LOVE?
I have this image:
[img]https://dl.dropboxusercontent.com/u/14273442/set_0.gif[/img]
I need to extract 3 particular 16x16 tiles. Can I do it without cutting the image?[/QUOTE]
[url]https://love2d.org/wiki/Quad[/url]
-snip-
I am messing around with OpenGL on Android using GLES1 and I can get around 1000 sprites on the screen at around 27 to 29 frames per second. This is on the Genymotion emulator at 720x1280 resolution.
Is there anyway I can speed this up? I have a feeling 1000 sprites at that frame rate(without input) is extremely slow.
So, a simple maths-y question.
Long story short, I have two spheres of radius r1 and r2, r2 > r1, with the same origin, existing in an XYZ plane.
I want to generate points in this XYZ plane that are between these two spheres. I know a simple way to do it is subtractively - generate points between 0 and r2, toss out those whose distance to the origin is less than r1 - but I anticipate scenarios are (r2 - r1) << r1, EG the shell width will be a lot less than the smaller sphere, ergo a subtractive method like that would become very inefficient.
Here is a cross-section of what I mean, centered at the origin:
[t]http://a.pomf.se/ddspnu.png[/t]
Does anyone know of an algorithm to generate those points without the use of subtractive geometry? I can determine one quadrant easily with something like
[code]x = r1 + random(r2 - r1) // random(n) generates a value between 0 and n.
y = r1 + random(r2 - r1)
z = r1 + random(r2 - r1)[/code]
But that doesn't account for the other three quadrants.
You could generate points between two points (upper and lower sphere on Y axis) and then generate a random angle and use trigonometry to transform the points.
[QUOTE=Gmod4ever;43852564]snip[/QUOTE]
Multiply each axis with either 1 or -1.
[QUOTE=Gmod4ever;43852564]
But that doesn't account for the [b]other three quadrants[/b].[/QUOTE]
There should be 8 octants, if it's a 3-dimensional object.
Therefore, two angles and a radius. Let r still just be randomly chosen between r1 and r2, and theta (also randomly) between -Pi/2 and +Pi/2 and phi (again randomly) between 0 and 2Pi, then use
[IMG]https://upload.wikimedia.org/math/0/6/e/06e9dca47ef906d175c87552d3bbc8d4.png[/IMG]
[IMG]https://upload.wikimedia.org/math/0/2/c/02ce35b6057a7958a407068d1f4dce48.png[/IMG]
[IMG]https://upload.wikimedia.org/math/8/4/7/847a8baa62532b7141a3e8c430b14b60.png[/IMG]
[URL="https://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates"]Source[/URL]
[QUOTE=Number-41;43853187]Therefore, two angles and a radius. Let r still just be randomly chosen between r1 and r2, and theta (also randomly) between -Pi/2 and +Pi/2 and phi (again randomly) between 0 and 2Pi, then use
[IMG]https://upload.wikimedia.org/math/0/6/e/06e9dca47ef906d175c87552d3bbc8d4.png[/IMG]
[IMG]https://upload.wikimedia.org/math/0/2/c/02ce35b6057a7958a407068d1f4dce48.png[/IMG]
[IMG]https://upload.wikimedia.org/math/8/4/7/847a8baa62532b7141a3e8c430b14b60.png[/IMG]
[URL="https://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates"]Source[/URL][/QUOTE]
This way sounds the simplest and most feasibly implemented way. Thanks, guys; you're all awesome!
[QUOTE=Gmod4ever;43853367]This way sounds the simplest and most feasibly implemented way. Thanks, guys; you're all awesome![/QUOTE]
Do you need it to be uniformly distributed in XYZ-space?
If you choose the radius from a uniform distribution, it will have a higher density with lower radii. You would have to use some other distribution for sampling the radius.
I need help with these two chaps here.
[img]http://gyazo.com/964fc1ad1dd7e651f42bb9044a24e112.png[/img]
These guys are real cool and I want to make them collide. I detect collisions just fine, but I can't wrap my head around how to make them repell.
Whenever animate walks into a static he should get pushed back to the point where he is not colliding with it anymore.
The vars of these chaps we can use:
- dx, dy (they are always 0 for static though)
- x, y of centers
- radiuses
- the amount of how much one overlaps another
I tried to do it this way:
[code] local distance = math.sqrt((self.values.x - invoker.values.x)*(self.values.x - invoker.values.x) + (self.values.y - invoker.values.y)*(self.values.y - invoker.values.y));
local overlap = math.abs(distance - self.values.radius - invoker.values.radius);
print(overlap)
local absx = invoker.values.dx/math.abs(invoker.values.dx); -- if < 0 then returns -1, if > 0 returns 1. If == 0 fucks everything up with nans
local absy = invoker.values.dy/math.abs(invoker.values.dy);
invoker.values.dx = absx * overlap/STAGE.TILESIZE;
invoker.values.dy = absy * overlap/STAGE.TILESIZE;[/code]
This produces weird results. Tried some variations of it but nothing worked better. How do I do it?
Using Unity here!
I've followed up a tutorial about doors, but after making two animations for the door "Open" and "Close", but I get two errors when I interact with the door (When the open/close animation should show:
First I get
[code]The AnimationClip 'Open' used by the Animation component 'door' must be marked as Legacy.
UnityEngine.Animation:CrossFade(String)
DoorBehaviour:changeDoorState() (at Assets/DoorBehaviour.cs:56)
DoorBehaviour:Update() (at Assets/DoorBehaviour.cs:15)
[/code]
and then I get
[code]The animation state Open could not be played because it couldn't be found!
Please attach an animation clip with the name 'Open' or call this function only for existing animations.
UnityEngine.Animation:CrossFade(String)
DoorBehaviour:changeDoorState() (at Assets/DoorBehaviour.cs:56)
DoorBehaviour:Update() (at Assets/DoorBehaviour.cs:15)
[/code]
Using Love2D to make simple side scroller,
How can I check/add new ground if the player goes to the left or right
I am currently moving the whole ground/trees if the player goes in certain range of borders.
What i have:
[IMG]http://i.imgur.com/Ds8q2yR.gif[/IMG]
I'm totally blanking for some reason. In C++ with constructors, do you need to initialize every variable?
Example:
[cpp]//Default Constructor
Employee();
//Constructor
Employee(string, int, int, int, char, string, float, string);[/cpp]
For the actual Constructor do I need to initialize the string/char to null and the int/float to 0, or is that unnecessary? Any time I'd call it I'd be assigning values to all of it anyway, so I'm not sure if that's necessary.
[editline]10th February 2014[/editline]
and if so is there a fast way to do it because i'm lazy and that's a lot of initialization
Sorry, you need to Log In to post a reply to this thread.