[csharp]
namespace _3DProjection
{
class Program
{
const int scrwidth = 120;
const int scrheight = 80;
private static void RenderPoint(Point point)
{
static Point Cam = new Point(0,0,0);
static Point CamRot = new Point(0,0,0);
static Point CamSurf = new Point(0,0,5);
Point wtf = new Point();
wtf.X = Math.Cos(CamRot.Y) * (Math.Sin(CamRot.Z) * (point.Y - Cam.Y) + Math.Cos(CamRot.Z) * (point.X - Cam.X)) - Math.Sin(CamRot.Y) * (point.Z - Cam.Z);
wtf.Y = Math.Sin(CamRot.X) * (Math.Cos(CamRot.Y) * (point.Z - Cam.Z) + Math.Sin(CamRot.Y) * (Math.Sin(CamRot.Z) * (point.Y - Cam.Y) + Math.Cos(CamRot.Z) * (point.X - Cam.X))) + Math.Cos(CamRot.X) * (Math.Cos(CamRot.Z) * (point.Y - Cam.Y) - Math.Sin(CamRot.Z) * (point.X - Cam.X));
wtf.Z = Math.Cos(CamRot.X) * (Math.Cos(CamRot.Y) * (point.Z - Cam.Z) + Math.Sin(CamRot.Y) * (Math.Sin(CamRot.Z) * (point.Y - Cam.Y) + Math.Cos(CamRot.Z) * (point.X - Cam.X))) - Math.Sin(CamRot.X) * (Math.Cos(CamRot.Z) * (point.Y - Cam.Y) - Math.Sin(CamRot.Z) * (point.X - Cam.X));
double theX = (wtf.X - CamSurf.X) * (CamSurf.Z / wtf.Z);
double theY = (wtf.Y - CamSurf.Y) * (CamSurf.Z / wtf.Z);
Console.Title = theX + "," + theY;
Graphics.DrawPoint((int)(Math.Round(theX - scrwidth / 2.0d)), (int)Math.Round(theY - scrheight/2.0d));
}
}
class Point
{
public Point()
{
}
public Point(double X, double Y, double Z)
{
this.X = X;
this.Y = Y;
this.Z = Z;
}
public double X, Y, Z;
}
}
[/csharp]
RenderPoint produces nothing but absolute bullshit. The point moves in a random-ass parabola when I CamRot.X+=0.1;
[editline]27th August 2011[/editline]
[url]http://en.wikipedia.org/wiki/3D_projection#Perspective_projection[/url]
Can't you break that down into smaller chunks and test those individually?
Add like a proper matrix/quaternion class for those rotations. It's likely you'll want to re-use that code elsewhere in your program.
Also, don't call the same trig function with the same arguments fifty-seven times in a row. Call it once and store the result in a variable.
[QUOTE=ROBO_DONUT;31965256]Can't you break that down into smaller chunks and test those individually?
Add like a proper matrix/quaternion class for those rotations. It's likely you'll want to re-use that code elsewhere in your program.
Also, don't call the same trig function with the same arguments fifty-seven times in a row. Call it once and store the result in a variable.[/QUOTE]
That's the problem. I don't know what I'm computing. That's just what the wiki article says to do.
[QUOTE=Map in a box;31963600]Clamp it :v: Math.max(updownRot,0)[/QUOTE]
That actually didn't work, and as it turns out, C# doesn't appear to actually have a clamp function at all, and my initial approach was correct, albeit a bit flawed.
[csharp]
private void ProcessInput(float amount)
{
MouseState currentMouseState = Mouse.GetState();
if (currentMouseState != originalMouseState)
{
float xDifference = currentMouseState.X - originalMouseState.X;
float yDifference = currentMouseState.Y - originalMouseState.Y;
leftrightRot -= rotationSpeed * xDifference * amount;
updownRot -= rotationSpeed * yDifference * amount;
Mouse.SetPosition(device.Viewport.Width / 2, device.Viewport.Height / 2);
if (updownRot < -1.3f)
{
updownRot = -1.3f;
}
if (updownRot > 1.5f)
{
updownRot = 1.5f;
}
UpdateViewMatrix();
}
[/csharp]
C# should have Math.max though :v:
Common sense:
[code]
float clamp(float val,float min,float max){
if(val<min)
return min;
if(val>max)
return max;
return val;
}
[/code]
W/e :P
I'm trying to do smooth camera movement, which works but it's jerky.
[lua]
cam.pos.x = lerp(0.9, cam.pos.x, ship:getX())
cam.pos.y = lerp(0.9, cam.pos.y, ship:getY())[/lua]
I assume it's because I'm not taking into account delta time, but I can't figure out how to work it in in the usual way, so that the camera moves at the same speed regardless of framerate.
[QUOTE=Map in a box;31966031]C# should have Math.max though :v:
Common sense:
[code]
float clamp(float val,float min,float max){
if(val<min)
return min;
if(val>max)
return max;
return val;
}
[/code]
W/e :P[/QUOTE]
[csharp]
public static T Clamp<T>(this T obj, T min, T max) where T : IComparable
{
if(obj.CompareTo(min) < 0) return min;
if(obj.CompareTo(max) > 0) return max;
return obj;
}
[/csharp]
If your camera had velocity it might be easier
[QUOTE=Ortzinator;31966093]I'm trying to do smooth camera movement, which works but it's jerky.
[lua]
cam.pos.x = lerp(0.9, cam.pos.x, ship:getX())
cam.pos.y = lerp(0.9, cam.pos.y, ship:getY())[/lua]
I assume it's because I'm not taking into account delta time, but I can't figure out how to work it in in the usual way, so that the camera moves at the same speed regardless of framerate.[/QUOTE]
[cpp]// Vector stuff to make the camera move at a constant speed regardless of direction
dx = ship:getX() - cam.pos.x;
dy = ship:getY() - cam.pos.y;
dist = sqrt(dx * dx + dy * dy);
speedx = cam.speed * dx / dist;
speedy = cam.speed * dy / dist;
// Interpolation
cam.pos.x += speedx * frametime;
cam.pos.y += speedy * frametime;
[/cpp]
[QUOTE=ROBO_DONUT;31959056]Don't bother. MinGW is just the Windows port of GCC and its related tools. It stands for "Minimalist GNU for Windows".
If you already have GCC installed, there's no sense in downloading MinGW.[/QUOTE]
[QUOTE=Z_guy;31960196]Code::Blocks lists all the compilers it supports and not just the ones you have installed. Also Code::Blocks comes with MinGW, so you don't need to install it separately.[/QUOTE]
Oh..... :v:
[QUOTE=Hypershadsy;31965418]That's the problem. I don't know what I'm computing. That's just what the wiki article says to do.[/QUOTE]
I'd pretty much do it the way it's done in GL/D3D. Create a matrix class with constructors for rotation, translation, and perspective projection matrices. Combine these into a single view-projection matrix by multiplying them in the appropriate order, multiply the vector coordinate by this final matrix, and do perspective division (divide the x-, y-, and z- components by the w-component).
Also, I'd avoid expressing rotations or orientations as Euler angles, ever. They're really terrible at just about everything. I generally express simple rotations as vectors (like in physics) or axis-angle (it's basically the exact same thing) and orientations as either matrices or quaternions.
[url]http://en.wikipedia.org/wiki/Matrix_multiplication[/url]
[url]http://en.wikipedia.org/wiki/Translation_(geometry)#Matrix_representation[/url]
[url]http://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle[/url]
[url]http://www.songho.ca/opengl/gl_projectionmatrix.html[/url]
After perspective division, you'll end up with coordinates in the range [-1, 1] (called normalized device coordinates in OpenGL) which need to be mapped to the screen.
[QUOTE=ThePuska;31966861][cpp]// Vector stuff to make the camera move at a constant speed regardless of direction
dx = ship:getX() - cam.pos.x;
dy = ship:getY() - cam.pos.y;
dist = sqrt(dx * dx + dy * dy);
speedx = cam.speed * dx / dist;
speedy = cam.speed * dy / dist;
// Interpolation
cam.pos.x += speedx * frametime;
cam.pos.y += speedy * frametime;
[/cpp][/QUOTE]
What is cam.speed?
[editline]27th August 2011[/editline]
Never mind, I got it. Unfortunately this isn't the behavior I was looking for. I don't want it to move at a constant speed because it has to keep up with the ship and slowly come to a stop when the ship does.
Quick question concerning C#. I'm new so bear with me.
I wanted to know how I could make the program look throughout a string for a certain keyword, but not the entire string as a whole.
I'll make an example for what I mean:
[csharp]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Are you a male or female?");
string userInput = Console.ReadLine();
switch (userInput)
{
case "male":
case "Male":
Console.WriteLine("You're a male.");
break;
case "female":
case "Female":
Console.WriteLine("You're a female.");
break;
default:
Console.WriteLine("Invalid gender!");
break;
}
Console.ReadLine();
}
}
}
[/csharp]
Simple enough, really. Now, I'd like to know how I could make it so that it will only look for the words "male" or "female" INSIDE the user's input, Instead of the user only typing that. So the user could say "I'm a male" and still get the same results. Of course I could include it in the switch statement but there's many ways people can portray their answer. Why I need this? I might make a cyoa game or something, and it would help me a bit more if I found out how to do this :v:.
Thanks in advance
[QUOTE=Armybrother;31974781]Quick question concerning C#. I'm new so bear with me.
I wanted to know how I could make the program look throughout a string for a certain keyword, but not the entire string as a whole.
I'll make an example for what I mean:
[csharp]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Are you a male or female?");
string userInput = Console.ReadLine();
switch (userInput)
{
case "male":
case "Male":
Console.WriteLine("You're a male.");
break;
case "female":
case "Female":
Console.WriteLine("You're a female.");
break;
default:
Console.WriteLine("Invalid gender!");
break;
}
Console.ReadLine();
}
}
}
[/csharp]
Simple enough, really. Now, I'd like to know how I could make it so that it will only look for the words "male" or "female" INSIDE the user's input, Instead of the user only typing that. So the user could say "I'm a male" and still get the same results. Of course I could include it in the switch statement but there's many ways people can portray their answer. Why I need this? I might make a cyoa game or something, and it would help me a bit more if I found out how to do this :v:.
Thanks in advance[/QUOTE]
Use the String.Contains(otherString) method.
And make it lowercase
[QUOTE=Map in a box;31975080]And make it lowercase[/QUOTE]
And check if it contains female first, so it doesn't say that you're male if you enter "Female" :v:
[QUOTE=Ortzinator;31971187]What is cam.speed?
[editline]27th August 2011[/editline]
Never mind, I got it. Unfortunately this isn't the behavior I was looking for. I don't want it to move at a constant speed because it has to keep up with the ship and slowly come to a stop when the ship does.[/QUOTE]
Maybe you're looking for a kind of an exponential decay of the distance.
[cpp]dx = ship:getX() - cam.pos.x;
dy = ship:getY() - cam.pos.y;
lambda = log(2) / halflife; // halflife means the time it takes for the distance to halve
mult = exp(-frametime * lambda);
dx *= mult;
dy *= mult;
// Interpolation
cam.pos.x = ship:getX() - dx;
cam.pos.y = ship:getY() - dy;[/cpp]
[QUOTE=ThePuska;31975468]Maybe you're looking for a kind of an exponential decay of the distance.
[cpp]dx = ship:getX() - cam.pos.x;
dy = ship:getY() - cam.pos.y;
lambda = log(2) / halflife; // halflife means the time it takes for the distance to halve
mult = exp(-frametime * lambda);
dx *= mult;
dy *= mult;
// Interpolation
cam.pos.x = ship:getX() - dx;
cam.pos.y = ship:getY() - dy;[/cpp][/QUOTE]
That works great, thanks!
Are there any tutorials out there for voxels in XNA, preferably using marching cubes?
[QUOTE=horsedrowner;31975097]And check if it contains female first, so it doesn't say that you're male if you enter "Female" :v:[/QUOTE]
On top of your avatar, my respect just shot through the roof for you. I would've never thought of that.
Anyone know how I can create a SFML window and another window in GTK# for all the options and buttons?
I need the SFML window to handle some minimum input and run at a constant fps (30 to 60), and the GTK window to be event based
[QUOTE=thf;31975000]Use the String.Contains(otherString) method.[/QUOTE]
Ah, okay. Thanks :smile:
I'm trying to test if I put in the glext.h and wglext.h from Overb's OpenGL guide properly, I put both of the files in this directory C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include . When I try to build the project, I get this error log:
[code]
1>------ Build started: Project: empty, Configuration: Debug Win32 ------
1>Open gl example.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function _WinMain@16
1>Open gl example.obj : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function _WinMain@16
1>Open gl example.obj : error LNK2019: unresolved external symbol __imp__wglDeleteContext@4 referenced in function _WinMain@16
1>Open gl example.obj : error LNK2019: unresolved external symbol __imp__wglGetProcAddress@4 referenced in function _WinMain@16
1>Open gl example.obj : error LNK2019: unresolved external symbol __imp__wglMakeCurrent@8 referenced in function _WinMain@16
1>Open gl example.obj : error LNK2019: unresolved external symbol __imp__wglCreateContext@4 referenced in function _WinMain@16
1>D:\Programming\Visual Studio 2010 C++\empty\Debug\empty.exe : fatal error LNK1120: 6 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
[/code]
Apparently SFML scaling seems to be broken in 1.6 somewhat. Does anyone know a fix or should i just migrate over to 2.0?
[QUOTE=Icedshot;31978663]Apparently SFML scaling seems to be broken in 1.6 somewhat. Does anyone know a fix or should i just migrate over to 2.0?[/QUOTE]
Afaik, migrate to 2.0. 1.6 is riddled with bugs
[QUOTE=Exosel;31978545]I'm trying to test if I put in the glext.h and wglext.h from Overb's OpenGL guide properly, I put both of the files in this directory C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include . When I try to build the project, I get this error log:
[code]
1>------ Build started: Project: empty, Configuration: Debug Win32 ------
1>Open gl example.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function _WinMain@16
1>Open gl example.obj : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function _WinMain@16
1>Open gl example.obj : error LNK2019: unresolved external symbol __imp__wglDeleteContext@4 referenced in function _WinMain@16
1>Open gl example.obj : error LNK2019: unresolved external symbol __imp__wglGetProcAddress@4 referenced in function _WinMain@16
1>Open gl example.obj : error LNK2019: unresolved external symbol __imp__wglMakeCurrent@8 referenced in function _WinMain@16
1>Open gl example.obj : error LNK2019: unresolved external symbol __imp__wglCreateContext@4 referenced in function _WinMain@16
1>D:\Programming\Visual Studio 2010 C++\empty\Debug\empty.exe : fatal error LNK1120: 6 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
[/code][/QUOTE]
Did you:
[code]#include <glext.h>
#include <wglext.h>[/code]
An easier way is to put the 2 .h files in the same directory as your .cpp. Go to solution explorer->Header files (right click)->add existing item. And then add glext.h and wglext.h. Then use:
[code]#include "glext.h"
#include "wglext.h"[/code]
You might have also forgotten to add the .lib. Make sure you have: [code]#pragma comment(lib,"opengl32.lib");[/code]
[QUOTE=wdth2;31979499]Did you:
[code]#include <glext.h>
#include <wglext.h>[/code]
An easier way is to put the 2 .h files in the same directory as your .cpp. Go to solution explorer->Header files (right click)->add existing item. And then add glext.h and wglext.h. Then use:
[code]#include "glext.h"
#include "wglext.h"[/code]
You might have also forgotten to add the .lib. Make sure you have: [code]#pragma comment(lib,"opengl32.lib");[/code][/QUOTE]
Thanks a lot, I got it fixed. I added headers to the project and added the .lib to fix it.
[QUOTE=Icedshot;31978663]Apparently SFML scaling seems to be broken in 1.6 somewhat. Does anyone know a fix or should i just migrate over to 2.0?[/QUOTE]
2.0 is just generally better than 1.6, so go for it :v:
Although I don't remember scaling being broken in 1.6, got any code that will reproduce the issue?
Does anyone know why my solution in Visual C++ 2008 thinks the code is up to date even though it isn't, when I try to build it just gives me "Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped" Even though I have changed something and saved it. It seems to rebuild only if I delete the debug folder in my solution, anyone know what might be causing this?
Sorry, you need to Log In to post a reply to this thread.