• What are you working on? v15
    5,001 replies, posted
[QUOTE=Xeon06;27176487]What am I doing wrong?[/QUOTE] Not providing enough info.
[QUOTE=Xeon06;27176487] -snip snap- [/QUOTE] 'scuse me if im wrong but surely (centerx-leftx)*2*ratio is what you want to use to get the width? the same goes for height Though i once managed to work out that 1-1=2, so you might not want to trust me on this
Okay well, maybe I shall ask it another way. Suppose you want to write a method for a polygon class that takes a float and resizes it by that amount. You have access to a list/array of points called Points and the center of the polygon, called Center. What I was doing in the previous code I posted was taking the difference from the center of the polygon to each point, multiplying that difference by the ratio, and then adjusting the point accordingly.
-snip-
[cpp]public void Resize(float ratio) { for(int i = 0; i < Points.Count; i++) { float yDist=Points[i].Y-Center.Y; float xDist=Points[i].X-Center.X; float angle=Math.atan2(yDist, xDist); float distance=Math.sqrt(xDist*xDist+yDist*yDist); Points[i].X=Math.cos(angle)*distance*ratio+Center.X; Points[i].Y=Math.sin(angle)*distance*ratio+Center.Y; } }[/cpp] This should work. [b]Edit:[/b] Use Jallen's code, it's much faster.
[QUOTE=MakeR;27176682]Please explain.[/QUOTE] I don't know, there's no challenge in it anymore. I want to learn more.
[QUOTE=ZenX2;27178956]I don't know, [b]there's no challenge in it anymore.[/b] I want to learn more.[/QUOTE] Isn't that a good thing?
How can I make a transparent circle through a grid based game. So like if the character enters a secret area, the circle will follow him and let you see. I just don't know how I can make a transparent object appear. If I just make a transparent circle, you won't be able to see it. If I make it white, you won't be able to see the player. I also want the player to be able to see the background layer. Not a technical question, but more of a abstract question.
[QUOTE=Robber;27178935][cpp]public void Resize(float ratio) { for(int i = 0; i < Points.Count; i++) { float yDist=Points[i].Y-Center.Y; float xDist=Points[i].X-Center.X; float angle=Math.atan2(yDist, xDist); float distance=Math.sqrt(xDist*xDist+yDist*yDist); Points[i].X=Math.cos(angle)*distance*ratio+Center.X; Points[i].Y=Math.sin(angle)*distance*ratio+Center.Y; } }[/cpp] This should work.[/QUOTE] Couldn't you just do this? [code]public void Resize(float ratio) { for(int i = 0; i < Points.Count; i++) { float yDist = Points[i].Y - Center.Y; float xDist = Points[i].X - Center.X; Points[i].X = Center.X + (xDist * ratio); Points[i].Y = Center.Y + (yDist * ratio); } }[/code] Never done this before and this code is untested but I don't see why it wouldn't work. [editline]3rd January 2011[/editline] [QUOTE=WTF Nuke;27179382]How can I make a transparent circle through a grid based game. So like if the character enters a secret area, the circle will follow him and let you see. I just don't know how I can make a transparent object appear. If I just make a transparent circle, you won't be able to see it. If I make it white, you won't be able to see the player. I also want the player to be able to see the background layer. Not a technical question, but more of a abstract question.[/QUOTE] I think you're wanting a semi-transparent circle :downs:
[QUOTE=MakeR;27179099]Isn't that a good thing?[/QUOTE] I guess, I've just been bored lately.
[QUOTE=Jallen;27179515] I think you're wanting a semi-transparent circle :downs:[/QUOTE] No, that would look horrible. I want to completely remove the tiles while keeping the background intact. So like cutout a circle in the tiles.
Just finished my first menu system. It's probably horrible, but i'm proud of it :v: [img_thumb]http://img411.imageshack.us/img411/3010/topdowngame201101032312.png[/img_thumb] [img_thumb]http://img411.imageshack.us/img411/2087/topdowngame201101032312.jpg[/img_thumb]
Ok I'm going crazy over this. I made another project with only the basic code required to do this, and it still doesn't work. Robber's method acts the same as mine, whereas Jallen's does some crazy stuff (I know it was untested). [code] using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public class Form1 : Form { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } Polygon p; public Form1() { this.Click += new EventHandler(Form1_Click); this.Paint += new PaintEventHandler(Form1_Paint); p = new Polygon(); p.Points.Add(new PointF(100, 100)); p.Points.Add(new PointF(200, 100)); p.Points.Add(new PointF(200, 200)); p.Points.Add(new PointF(100, 200)); } void Form1_Paint(object sender, PaintEventArgs e) { e.Graphics.FillPolygon(Brushes.CornflowerBlue, p.Points.ToArray()); foreach (PointF point in p.Points) e.Graphics.DrawLine(Pens.Red, point, p.Center); } void Form1_Click(object sender, EventArgs e) { p.JallensResize(0.5f); this.Refresh(); } } public class Polygon { public List<PointF> Points; public Polygon() { Points = new List<PointF>(); } public PointF Center { get { PointF center = new PointF(); foreach (PointF PointF in Points) { center.X += PointF.X; center.Y += PointF.Y; } center.X /= Points.Count; center.Y /= Points.Count; return center; } } public void Resize(float ratio) { for (int i = 0; i < Points.Count; i++) { float width = (Points[i].X - Center.X) * ratio; float height = (Points[i].Y - Center.Y) * ratio; Points[i] = new PointF(Center.X + width, Center.Y + height); } } public void RobbersResize(float ratio) { for (int i = 0; i < Points.Count; i++) { float yDist = Points[i].Y - Center.Y; float xDist = Points[i].X - Center.X; float angle = (float)Math.Atan2(yDist, xDist); float distance = (float)Math.Sqrt(xDist * xDist + yDist * yDist); float x = (float)Math.Cos(angle) * distance * ratio + Center.X; float y = (float)Math.Sin(angle) * distance * ratio + Center.Y; Points[i] = new PointF(x, y); } } public void JallensResize(float ratio) { for (int i = 0; i < Points.Count; i++) { float yDist = Points[i].Y - Center.Y; float xDist = Points[i].X - Center.X; float x = Center.X + (Points[i].X * ratio); float y = Center.Y + (Points[i].Y * ratio); Points[i] = new PointF(x, y); } } } } [/code]
I just wrote a program that translates text to a brainfuck program that prints the text. [lua]function ToBrainF(te) local ta = string.Explode("", te) local t = {} for k, v in pairs(ta) do t[k] = tonumber(string.byte(v)) end local s = "" s = s..string.rep("+", 10) --prpare the multiplier s = s.."[" local tn, to = {}, {} for k, v in pairs(t) do tn[k] = (v/10 - (v/10)%1) * 10 --closest multiple of ten to[k] = v - tn[k] --the offset end for k, v in pairs(t) do s = s..">"..string.rep("+", tn[k] / 10) --get each thing to it's number end s = s..string.rep("<", #t).."-]" --decrement counter, close loop for k, v in pairs(to) do s = s..">"..string.rep("+", v).."." end print(s) end[/lua]
[QUOTE=ZenX2;27180346]I just wrote a program that translates text to a brainfuck program that prints the text. [lua]local ta = string.Explode("", te)[/lua][/QUOTE] string.Explode isn't available in pure Lua. [editline]3rd January 2011[/editline] Use this instead if you want it to work in pure Lua. [lua]local t = {} for v in te:gmatch(".") do table.insert(t, string.byte(v)) end[/lua]
Meh, I pretty much pulled it from my script running environment, which automatically loads extensions from a folder, alleviating me of the need to dofile whatever I need in any one script.
[QUOTE=Xeon06;27180298]Ok I'm going crazy over this. I made another project with only the basic code required to do this, and it still doesn't work. Robber's method acts the same as mine, whereas Jallen's does some crazy stuff (I know it was untested). [code] ...[/code][/QUOTE] I think that's supposed to be [code]float x = Center.X + (xDist * ratio);[/code] in Jallan's code
[QUOTE=Xeon06;27180298]Ok I'm going crazy over this. I made another project with only the basic code required to do this, and it still doesn't work. Robber's method acts the same as mine, whereas Jallen's does some crazy stuff (I know it was untested). [code] using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public class Form1 : Form { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } Polygon p; public Form1() { this.Click += new EventHandler(Form1_Click); this.Paint += new PaintEventHandler(Form1_Paint); p = new Polygon(); p.Points.Add(new PointF(100, 100)); p.Points.Add(new PointF(200, 100)); p.Points.Add(new PointF(200, 200)); p.Points.Add(new PointF(100, 200)); } void Form1_Paint(object sender, PaintEventArgs e) { e.Graphics.FillPolygon(Brushes.CornflowerBlue, p.Points.ToArray()); foreach (PointF point in p.Points) e.Graphics.DrawLine(Pens.Red, point, p.Center); } void Form1_Click(object sender, EventArgs e) { p.JallensResize(0.5f); this.Refresh(); } } public class Polygon { public List<PointF> Points; public Polygon() { Points = new List<PointF>(); } public PointF Center { get { PointF center = new PointF(); foreach (PointF PointF in Points) { center.X += PointF.X; center.Y += PointF.Y; } center.X /= Points.Count; center.Y /= Points.Count; return center; } } public void Resize(float ratio) { for (int i = 0; i < Points.Count; i++) { float width = (Points[i].X - Center.X) * ratio; float height = (Points[i].Y - Center.Y) * ratio; Points[i] = new PointF(Center.X + width, Center.Y + height); } } public void RobbersResize(float ratio) { for (int i = 0; i < Points.Count; i++) { float yDist = Points[i].Y - Center.Y; float xDist = Points[i].X - Center.X; float angle = (float)Math.Atan2(yDist, xDist); float distance = (float)Math.Sqrt(xDist * xDist + yDist * yDist); float x = (float)Math.Cos(angle) * distance * ratio + Center.X; float y = (float)Math.Sin(angle) * distance * ratio + Center.Y; Points[i] = new PointF(x, y); } } public void JallensResize(float ratio) { for (int i = 0; i < Points.Count; i++) { float yDist = Points[i].Y - Center.Y; float xDist = Points[i].X - Center.X; float x = Center.X + (Points[i].X * ratio); float y = Center.Y + (Points[i].Y * ratio); Points[i] = new PointF(x, y); } } } } [/code][/QUOTE] [cpp] public void Resize(float ratio) { float centx = Center.X; float centy = Center.Y; for (int i = 0; i < Points.Count; i++) { float width = (Points[i].X - centx) * ratio; float height = (Points[i].Y - centy) * ratio; Points[i] = new PointF(centx + width, centy + height); } }[/cpp] The Center was changing every time you moved a point. That is why it was being rotated.
[QUOTE=high;27180666][cpp] public void Resize(float ratio) { float centx = Center.X; float centy = Center.Y; for (int i = 0; i < Points.Count; i++) { float width = (Points[i].X - centx) * ratio; float height = (Points[i].Y - centy) * ratio; Points[i] = new PointF(centx + width, centy + height); } }[/cpp] The Center was changing every time you moved a point. That is why it was being rotated.[/QUOTE] I'm so dumb. Thanks loads.
Had an urge to work on an interpreted language I started just before I broke up for Christmas: [img]http://ahb.me/1mkc[/img] Going to add an array sort of thing then I'm probably going to get it to interface with SFML. I'll use it for scripting entities in Die to Win.
Anyone know why I can't seem to get posix in gcc? I really need fdopen...
[QUOTE=DevBug;27181443]Anyone know why I can't seem to get posix in gcc? I really need fdopen...[/QUOTE] -D_POSIX_SOURCE or whatever [editline]4th January 2011[/editline] eg. POSIX isn't c99 so you have to enable it separately [editline]4th January 2011[/editline] Yup, it's -D_POSIX_SOURCE
[QUOTE=esalaka;27181728]-D_POSIX_SOURCE or whatever [editline]4th January 2011[/editline] eg. POSIX isn't c99 so you have to enable it separately [editline]4th January 2011[/editline] Yup, it's -D_POSIX_SOURCE[/QUOTE] I've tried that before, I'll try it again. I think I defined the version manually... [editline]3rd January 2011[/editline] Nope, didn't work.
Hey, Yay, I fixed one padding issue ... and introduced another :v: ... :(
[QUOTE=limitofinf;27182720]Hey, Yay, I fixed one padding issue ... and introduced another :v: ... :([/QUOTE] Why do you always rate yourself optimistic?
[QUOTE=Robert64;27181167]Had an urge to work on an interpreted language I started just before I broke up for Christmas: [img_thumb]http://ahb.me/1mkc[/img_thumb] Going to add an array sort of thing then I'm probably going to get it to interface with SFML. I'll use it for scripting entities in Die to Win.[/QUOTE] Looks cool, but I'm a little concerned about the similarities between the table syntax and the function syntax. Also how are you going to declare parameters? (might I suggest syntax involving '->', I'm quite fond of that)
[QUOTE=DevBug;27182068]Nope, didn't work.[/QUOTE] Works for me: [cpp] #include <stdio.h> FILE *foo() { return fdopen(0, "r"); } [/cpp] [code]gcc -c -Wall -std=c99 -D_POSIX_SOURCE test.c[/code] No warnings or errors.
[QUOTE=Dj-J3;27182754]Why do you always rate yourself optimistic?[/QUOTE] Pride?
[QUOTE=Dj-J3;27182754]Why do you always rate yourself optimistic?[/QUOTE] Hey, I guess I'm just an optimistic guy :) (and I like Justin Bieber)
[QUOTE=Wyzard;27182873]Works for me: [cpp] #include <stdio.h> FILE *foo() { return fdopen(0, "r"); } [/cpp] [code]gcc -c -Wall -std=c99 -D_POSIX_SOURCE test.c[/code] No warnings or errors.[/QUOTE] Still getting it... warning: implicit declaration of function ‘fdopen’
Sorry, you need to Log In to post a reply to this thread.