Lost Password?

Go Back   CodeCall Programming Forum > Software Development > General Programming > Programming Theory

Programming Theory Discuss programming theory, algorithm efficiency, logic, and other any other category where math and computer science overlap.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-29-2008, 03:40 PM
Maurice_Z Maurice_Z is offline
Learning Programmer
 
Join Date: Nov 2007
Location: Poland
Posts: 35
Rep Power: 3
Maurice_Z is on a distinguished road
Send a message via ICQ to Maurice_Z Send a message via AIM to Maurice_Z Send a message via MSN to Maurice_Z Send a message via Yahoo to Maurice_Z
Default Find harmony in two relative things

At the very beginning I must warn you, that explaining the problem will be hard to me.
Now, that you've been warned I'll start with quick explanation:
When position is relative to angle and angle is relative to position, how can I find the "perfect point"?
Now to have an example. I have two points: A(Xa,Ya) and B(Xb,Yb), I also have angle between them which is stored in DIR.
Point A - Static, moves with mouse move
Point B - Relative to Angle between two points
DIR - Relative to position of point B
So in one step I want to calculate the perfect position of point B, so it won't have to reassign, without using loops with one, relatively short algorithm.
And now, because it might not be sufficent, I'll give you a real-life example:
I have a platformer I'm working on. There is a player, who is made out of 4 parts: Body with head, arm, and two legs. The last two are not important. What is important is the body. In this game you aim using mouse, and the arm with gun rotates accordingly. To add realism, I decided to make it so the body bends when looking down, and moves aside(? Bends up?) when looking up. But when the body rotates the point where arm connects with body moves also. Look at the picture:

See? When the angle between Point A and B changes (DIR), so does the poistion of point B, and furthermore because of that DIR changes again, and so on...
So how can I find the harmony between these points? How can I find the one and only right point? ^^
If you need, these are the formulas I use:
Code:
Point A - Static, its positions are Xa and Xb
DIR - It is atan2(Xa-Xb,Ya-Yb)
temp_atan=ATan2(-4,-5)  //It's just temporarty variable, to quicken the calculations)
Xb=x+5+Sin(temp_atan+dir/5)
Yb=y+8+Cos(temp_atan+dir/5)
X and Y are coordinates of the player object, temp_atan, is the angle between rotation axis/point of body and point where body and arm joins.
(These codes above might not be perfect, as I keep finding mistakes here and there, but in any case I think I'd be able to change the finishing algorithm)

I hope it is understandable. It was hellishly difficult for me to explain ^^;
Thanks in advance

Last edited by Maurice_Z; 02-29-2008 at 03:57 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 03-01-2008, 10:27 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,035
Last Blog:
NaNoWriMo Day 23 The...
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

Let me see if I understand:

You want the body to tilt when you aim up/down. This changes where the arm is, requiring a correction of the arm so you are still aiming at the desired location.

Thinking of this in terms of vectors, you want to have two vectors determine the position of the arm/body, rather than a single vector for the arm which will determine the appearance when aiming, correct? If so, I should be able to construct the equations you need to render the arm/body correctly.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 11:26 AM
Maurice_Z Maurice_Z is offline
Learning Programmer
 
Join Date: Nov 2007
Location: Poland
Posts: 35
Rep Power: 3
Maurice_Z is on a distinguished road
Send a message via ICQ to Maurice_Z Send a message via AIM to Maurice_Z Send a message via MSN to Maurice_Z Send a message via Yahoo to Maurice_Z
Default

Quote:
Originally Posted by WingedPanther View Post
Let me see if I understand:

You want the body to tilt when you aim up/down. This changes where the arm is, requiring a correction of the arm so you are still aiming at the desired location.
I'm not sure ^^;. The body tilt is dependant of the Angle between Arm and Mouse. When body Tilts, the position of arm changes. When position of Arm is change, the angle between Arm and Mouse changes. So the body has to tilt again. So the position of arm has to change again. So the Angle changes again.

Either way, I don't need it anymore, as I managed to write alternate algorithm which works fine. If you want to bother though, then I'll be grateful, as I enjoy gaining new experiences .
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-02-2008, 08:03 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,035
Last Blog:
NaNoWriMo Day 23 The...
Rep Power: 24
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

In the end, it will proably end up being a system of equations (with what I'm thinking). If you have a working solution, I'll probably consider it "mission accomplished"
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
What Sort Of Things Did You Make When You Started VB? Skel Visual Basic Programming 1 11-06-2007 01:47 PM
how to find derivative in java sania21 Java Help 1 05-15-2007 06:35 AM
Linking strategy - absolute vs relative Carrym Search Engine Optimization 10 05-09-2007 10:08 AM
A great find: Beginning Perl techni68 Perl 0 01-21-2007 05:39 AM
10 Things That Will Make Or Break Your Website xXHalfSliceXx Website Design 10 01-04-2007 05:38 AM


All times are GMT -5. The time now is 03:15 PM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
gaylo565 ........ 18.00000
WingedPanther ........ 15.00000
|pH| ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 65%

Ads