Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Creste

#1
Support / Re: Problem with controlling a box
June 22, 2014, 12:44:55 PM
Okay, I am such an idiot. Did some things, everyone does when he has no idea what went wrong - change a few parameters and hope it works. It shure did :D

For everyone having similar problems; the code must be like public void strafeLeft() {
moving.add(new SimpleVector(xangle.x * (-1), 0, xangle.z));
}

public void strafeRight() {
moving.add(new SimpleVector(xangle.x, 0, xangle.z * (-1)));
}

public void forward() {
moving.add(new SimpleVector(zangle.x * (-1), 0, zangle.z));
}

public void backward() {
moving.add(new SimpleVector(zangle.x, 0, zangle.z * (-1)));
}
Only one parameter needs to be reverted.

Thanks for helping me so much :)
#2
Support / Re: Problem with controlling a box
June 22, 2014, 12:23:44 PM
Thanks fpr your reply.

I've been a bad explainer like my whole life ^^
I want to move an object in the world depending on the rotation if the camera.

I have this code right now: public class FirstPersonControler {
private Camera c;

SimpleVector moving = new SimpleVector(0f, 0f, 0f);

private SimpleVector xangle = new SimpleVector(0f, 0f, 0f);
private SimpleVector zangle = new SimpleVector(0f,0f,0f);

public FirstPersonControler(Camera c) {
this.c = c;
lasttick = GameTicks.getSystemTick();
}

public void update() {
double nowtick = GameTicks.getSystemTick();

moving = new SimpleVector(0f, 0f, 0f);

/* Code for turning the camera with the mouse */

xangle = c.getXAxis();
zangle = c.getZAxis();

tickcount = nowtick - lasttick;

lasttick = nowtick;
}

public void strafeLeft() {
moving.add(new SimpleVector(xangle.x * (-1), 0, xangle.z * (-1)));
}

public void strafeRight() {
moving.add(new SimpleVector(xangle.x, 0, xangle.z));
}

public void forward() {
moving.add(new SimpleVector(zangle.x * (-1), 0, zangle.z * (-1)));
}

public void backward() {
moving.add(new SimpleVector(zangle.x, 0, zangle.z));
}

public void jump() {
gravity = 1.2f;
}

public void forceMove(SimpleVector sv) {
this.forcedmoves.add(sv);
}

public SimpleVector getMoveVector() {
SimpleVector ret = new SimpleVector(moving.x, moving.y, moving.z);
if(ret.length() > 0) ret.scalarMul((1f/ret.length())*(float)(tickcount/2f));
return ret;
}
}
Every tick (~5ms) I check for the pressed key
w = FirstPersonControler.forward()
a = FirstPersonControler.strafeLeft()
s = FirstPersonControler.backward()
d = FirstPersonControler.strafeRight()
Then I move an object with the Vector FirstPersonControler.getMoveVector() and put the camera right on top of it.

Using the code above make the camera move weird; when pressing "a", it doesn't move to how it should.
I want to calculate the vector I need to translate, if I want to move the camera to the left (with calculating its rotation)
#3
Support / Re: Problem with controlling a box
June 20, 2014, 06:43:08 AM
Okay, I'd like to explain me problem again ^^

We are moving in a 3d space, so we need only 3 coordinates to find out, how camera is facing (like in screenshot below).

With cam.getXAxis(), cam.getYAxis() and cam.getZAxis() we can read 3 coordinates each - what are these 9 coordinated for? What are they showing?

[attachment deleted by admin]
#4
Support / Re: Problem with controlling a box
June 20, 2014, 12:01:35 AM
That was a pretty fast answer, thanks ^^

I am confused; why do they return 3 coordinates?
Saying I want to know the degrees to the vector 0|0|1, so I know the degrees the camera is turned. Which vector do I need to use?

Sorry, if that question sounds stupid, but I got used to the checkCameraCollision and never thought of leaving that one.
#5
Support / Problem with controlling a box
June 19, 2014, 10:13:12 PM
Hey there,

I have kind of a weird problem. I have no idea, how to first person control a box...

I have a class structured like this: class FirstPersonControler {
SimpleVector moving = new SimpleVector(0f, 0f, 0f);
SimpleVector facingangle = new SimpleVector(0f,0f,0f);

public void update() {
double nowtick = GameTicks.getSystemTick();

/* Unimportant logic having todo with fps view */

facingangle = c.getDirection();
}

public void strafeLeft() {
moving.add(new SimpleVector(-2f, 0f, 1-Math.abs(facingangle.z)));
}

public void strafeRight() {
moving.add(new SimpleVector(2f, 0f, (facingangle.x*2f)/facingangle.z));
}

public void forward() {
moving.add(new SimpleVector(facingangle.x, 0, facingangle.z));
}

public void backward() {
moving.add(new SimpleVector(-facingangle.x, 0, -facingangle.z));
}

public SimpleVector getMoveVector() {
return moving;
}
}
It controls the way, the box is moving, woth looking how the camera is turned. Then you should be able to control the box with "WASD" and turn around with the mouse, but that doesn't work well   :(
I need to find out, how to strafe left - if I try with that solution, it acts weird, going to front, back, side and any way that looks nicer then left. Same with right. I tried every math trick I know, scalar product, simple addition, ...
Forward and backwards work well, just the left and right thing don't.

Would be quite cool, if someone could help me. I am getting depressed by that...

Hope I don't left any information...